diff --git a/resource-manager/datafactory/2018-06-01/dataflowdebugsession/constants.go b/resource-manager/datafactory/2018-06-01/dataflowdebugsession/constants.go index f06b797dd08..0752acdebed 100644 --- a/resource-manager/datafactory/2018-06-01/dataflowdebugsession/constants.go +++ b/resource-manager/datafactory/2018-06-01/dataflowdebugsession/constants.go @@ -110,18 +110,18 @@ func parseParameterType(input string) (*ParameterType, error) { type Type string const ( - TypeLinkedServiceReference Type = "LinkedServiceReference" + TypeIntegrationRuntimeReference Type = "IntegrationRuntimeReference" ) func PossibleValuesForType() []string { return []string{ - string(TypeLinkedServiceReference), + string(TypeIntegrationRuntimeReference), } } func parseType(input string) (*Type, error) { vals := map[string]Type{ - "linkedservicereference": TypeLinkedServiceReference, + "integrationruntimereference": TypeIntegrationRuntimeReference, } if v, ok := vals[strings.ToLower(input)]; ok { return &v, nil diff --git a/resource-manager/media/2022-07-01/client.go b/resource-manager/media/2022-07-01/client.go new file mode 100644 index 00000000000..0455b336710 --- /dev/null +++ b/resource-manager/media/2022-07-01/client.go @@ -0,0 +1,28 @@ +package v2022_07_01 + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-07-01/encodings" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 Client struct { + Encodings *encodings.EncodingsClient +} + +func NewClientWithBaseURI(api environments.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + encodingsClient, err := encodings.NewEncodingsClientWithBaseURI(api) + if err != nil { + return nil, fmt.Errorf("building Encodings client: %+v", err) + } + configureFunc(encodingsClient.Client) + + return &Client{ + Encodings: encodingsClient, + }, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/README.md b/resource-manager/media/2022-07-01/encodings/README.md new file mode 100644 index 00000000000..f0ad1b61e8f --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/README.md @@ -0,0 +1,218 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-07-01/encodings` Documentation + +The `encodings` SDK allows for interaction with the Azure Resource Manager Service `media` (API Version `2022-07-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/media/2022-07-01/encodings" +``` + + +### Client Initialization + +```go +client := encodings.NewEncodingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EncodingsClient.JobsCancelJob` + +```go +ctx := context.TODO() +id := encodings.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue", "jobValue") + +read, err := client.JobsCancelJob(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncodingsClient.JobsCreate` + +```go +ctx := context.TODO() +id := encodings.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue", "jobValue") + +payload := encodings.Job{ + // ... +} + + +read, err := client.JobsCreate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncodingsClient.JobsDelete` + +```go +ctx := context.TODO() +id := encodings.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue", "jobValue") + +read, err := client.JobsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncodingsClient.JobsGet` + +```go +ctx := context.TODO() +id := encodings.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue", "jobValue") + +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 +} +``` + + +### Example Usage: `EncodingsClient.JobsList` + +```go +ctx := context.TODO() +id := encodings.NewTransformID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue") + +// alternatively `client.JobsList(ctx, id, encodings.DefaultJobsListOperationOptions())` can be used to do batched pagination +items, err := client.JobsListComplete(ctx, id, encodings.DefaultJobsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EncodingsClient.JobsUpdate` + +```go +ctx := context.TODO() +id := encodings.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue", "jobValue") + +payload := encodings.Job{ + // ... +} + + +read, err := client.JobsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncodingsClient.TransformsCreateOrUpdate` + +```go +ctx := context.TODO() +id := encodings.NewTransformID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue") + +payload := encodings.Transform{ + // ... +} + + +read, err := client.TransformsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncodingsClient.TransformsDelete` + +```go +ctx := context.TODO() +id := encodings.NewTransformID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue") + +read, err := client.TransformsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncodingsClient.TransformsGet` + +```go +ctx := context.TODO() +id := encodings.NewTransformID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue") + +read, err := client.TransformsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncodingsClient.TransformsList` + +```go +ctx := context.TODO() +id := encodings.NewMediaServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue") + +// alternatively `client.TransformsList(ctx, id, encodings.DefaultTransformsListOperationOptions())` can be used to do batched pagination +items, err := client.TransformsListComplete(ctx, id, encodings.DefaultTransformsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EncodingsClient.TransformsUpdate` + +```go +ctx := context.TODO() +id := encodings.NewTransformID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue") + +payload := encodings.Transform{ + // ... +} + + +read, err := client.TransformsUpdate(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/media/2022-07-01/encodings/client.go b/resource-manager/media/2022-07-01/encodings/client.go new file mode 100644 index 00000000000..e6efacb5e83 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/client.go @@ -0,0 +1,26 @@ +package encodings + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 EncodingsClient struct { + Client *resourcemanager.Client +} + +func NewEncodingsClientWithBaseURI(api environments.Api) (*EncodingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(api, "encodings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EncodingsClient: %+v", err) + } + + return &EncodingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/constants.go b/resource-manager/media/2022-07-01/encodings/constants.go new file mode 100644 index 00000000000..5c0929b8fdb --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/constants.go @@ -0,0 +1,1010 @@ +package encodings + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AacAudioProfile string + +const ( + AacAudioProfileAacLc AacAudioProfile = "AacLc" + AacAudioProfileHeAacVOne AacAudioProfile = "HeAacV1" + AacAudioProfileHeAacVTwo AacAudioProfile = "HeAacV2" +) + +func PossibleValuesForAacAudioProfile() []string { + return []string{ + string(AacAudioProfileAacLc), + string(AacAudioProfileHeAacVOne), + string(AacAudioProfileHeAacVTwo), + } +} + +func parseAacAudioProfile(input string) (*AacAudioProfile, error) { + vals := map[string]AacAudioProfile{ + "aaclc": AacAudioProfileAacLc, + "heaacv1": AacAudioProfileHeAacVOne, + "heaacv2": AacAudioProfileHeAacVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AacAudioProfile(input) + return &out, nil +} + +type AnalysisResolution string + +const ( + AnalysisResolutionSourceResolution AnalysisResolution = "SourceResolution" + AnalysisResolutionStandardDefinition AnalysisResolution = "StandardDefinition" +) + +func PossibleValuesForAnalysisResolution() []string { + return []string{ + string(AnalysisResolutionSourceResolution), + string(AnalysisResolutionStandardDefinition), + } +} + +func parseAnalysisResolution(input string) (*AnalysisResolution, error) { + vals := map[string]AnalysisResolution{ + "sourceresolution": AnalysisResolutionSourceResolution, + "standarddefinition": AnalysisResolutionStandardDefinition, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AnalysisResolution(input) + return &out, nil +} + +type AttributeFilter string + +const ( + AttributeFilterAll AttributeFilter = "All" + AttributeFilterBottom AttributeFilter = "Bottom" + AttributeFilterTop AttributeFilter = "Top" + AttributeFilterValueEquals AttributeFilter = "ValueEquals" +) + +func PossibleValuesForAttributeFilter() []string { + return []string{ + string(AttributeFilterAll), + string(AttributeFilterBottom), + string(AttributeFilterTop), + string(AttributeFilterValueEquals), + } +} + +func parseAttributeFilter(input string) (*AttributeFilter, error) { + vals := map[string]AttributeFilter{ + "all": AttributeFilterAll, + "bottom": AttributeFilterBottom, + "top": AttributeFilterTop, + "valueequals": AttributeFilterValueEquals, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttributeFilter(input) + return &out, nil +} + +type AudioAnalysisMode string + +const ( + AudioAnalysisModeBasic AudioAnalysisMode = "Basic" + AudioAnalysisModeStandard AudioAnalysisMode = "Standard" +) + +func PossibleValuesForAudioAnalysisMode() []string { + return []string{ + string(AudioAnalysisModeBasic), + string(AudioAnalysisModeStandard), + } +} + +func parseAudioAnalysisMode(input string) (*AudioAnalysisMode, error) { + vals := map[string]AudioAnalysisMode{ + "basic": AudioAnalysisModeBasic, + "standard": AudioAnalysisModeStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AudioAnalysisMode(input) + return &out, nil +} + +type BlurType string + +const ( + BlurTypeBlack BlurType = "Black" + BlurTypeBox BlurType = "Box" + BlurTypeHigh BlurType = "High" + BlurTypeLow BlurType = "Low" + BlurTypeMed BlurType = "Med" +) + +func PossibleValuesForBlurType() []string { + return []string{ + string(BlurTypeBlack), + string(BlurTypeBox), + string(BlurTypeHigh), + string(BlurTypeLow), + string(BlurTypeMed), + } +} + +func parseBlurType(input string) (*BlurType, error) { + vals := map[string]BlurType{ + "black": BlurTypeBlack, + "box": BlurTypeBox, + "high": BlurTypeHigh, + "low": BlurTypeLow, + "med": BlurTypeMed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BlurType(input) + return &out, nil +} + +type ChannelMapping string + +const ( + ChannelMappingBackLeft ChannelMapping = "BackLeft" + ChannelMappingBackRight ChannelMapping = "BackRight" + ChannelMappingCenter ChannelMapping = "Center" + ChannelMappingFrontLeft ChannelMapping = "FrontLeft" + ChannelMappingFrontRight ChannelMapping = "FrontRight" + ChannelMappingLowFrequencyEffects ChannelMapping = "LowFrequencyEffects" + ChannelMappingStereoLeft ChannelMapping = "StereoLeft" + ChannelMappingStereoRight ChannelMapping = "StereoRight" +) + +func PossibleValuesForChannelMapping() []string { + return []string{ + string(ChannelMappingBackLeft), + string(ChannelMappingBackRight), + string(ChannelMappingCenter), + string(ChannelMappingFrontLeft), + string(ChannelMappingFrontRight), + string(ChannelMappingLowFrequencyEffects), + string(ChannelMappingStereoLeft), + string(ChannelMappingStereoRight), + } +} + +func parseChannelMapping(input string) (*ChannelMapping, error) { + vals := map[string]ChannelMapping{ + "backleft": ChannelMappingBackLeft, + "backright": ChannelMappingBackRight, + "center": ChannelMappingCenter, + "frontleft": ChannelMappingFrontLeft, + "frontright": ChannelMappingFrontRight, + "lowfrequencyeffects": ChannelMappingLowFrequencyEffects, + "stereoleft": ChannelMappingStereoLeft, + "stereoright": ChannelMappingStereoRight, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ChannelMapping(input) + return &out, nil +} + +type Complexity string + +const ( + ComplexityBalanced Complexity = "Balanced" + ComplexityQuality Complexity = "Quality" + ComplexitySpeed Complexity = "Speed" +) + +func PossibleValuesForComplexity() []string { + return []string{ + string(ComplexityBalanced), + string(ComplexityQuality), + string(ComplexitySpeed), + } +} + +func parseComplexity(input string) (*Complexity, error) { + vals := map[string]Complexity{ + "balanced": ComplexityBalanced, + "quality": ComplexityQuality, + "speed": ComplexitySpeed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Complexity(input) + return &out, nil +} + +type DeinterlaceMode string + +const ( + DeinterlaceModeAutoPixelAdaptive DeinterlaceMode = "AutoPixelAdaptive" + DeinterlaceModeOff DeinterlaceMode = "Off" +) + +func PossibleValuesForDeinterlaceMode() []string { + return []string{ + string(DeinterlaceModeAutoPixelAdaptive), + string(DeinterlaceModeOff), + } +} + +func parseDeinterlaceMode(input string) (*DeinterlaceMode, error) { + vals := map[string]DeinterlaceMode{ + "autopixeladaptive": DeinterlaceModeAutoPixelAdaptive, + "off": DeinterlaceModeOff, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeinterlaceMode(input) + return &out, nil +} + +type DeinterlaceParity string + +const ( + DeinterlaceParityAuto DeinterlaceParity = "Auto" + DeinterlaceParityBottomFieldFirst DeinterlaceParity = "BottomFieldFirst" + DeinterlaceParityTopFieldFirst DeinterlaceParity = "TopFieldFirst" +) + +func PossibleValuesForDeinterlaceParity() []string { + return []string{ + string(DeinterlaceParityAuto), + string(DeinterlaceParityBottomFieldFirst), + string(DeinterlaceParityTopFieldFirst), + } +} + +func parseDeinterlaceParity(input string) (*DeinterlaceParity, error) { + vals := map[string]DeinterlaceParity{ + "auto": DeinterlaceParityAuto, + "bottomfieldfirst": DeinterlaceParityBottomFieldFirst, + "topfieldfirst": DeinterlaceParityTopFieldFirst, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeinterlaceParity(input) + return &out, nil +} + +type EncoderNamedPreset string + +const ( + EncoderNamedPresetAACGoodQualityAudio EncoderNamedPreset = "AACGoodQualityAudio" + EncoderNamedPresetAdaptiveStreaming EncoderNamedPreset = "AdaptiveStreaming" + EncoderNamedPresetContentAwareEncoding EncoderNamedPreset = "ContentAwareEncoding" + EncoderNamedPresetContentAwareEncodingExperimental EncoderNamedPreset = "ContentAwareEncodingExperimental" + EncoderNamedPresetCopyAllBitrateNonInterleaved EncoderNamedPreset = "CopyAllBitrateNonInterleaved" + EncoderNamedPresetDDGoodQualityAudio EncoderNamedPreset = "DDGoodQualityAudio" + EncoderNamedPresetHTwoSixFiveAdaptiveStreaming EncoderNamedPreset = "H265AdaptiveStreaming" + EncoderNamedPresetHTwoSixFiveContentAwareEncoding EncoderNamedPreset = "H265ContentAwareEncoding" + EncoderNamedPresetHTwoSixFiveSingleBitrateFourK EncoderNamedPreset = "H265SingleBitrate4K" + EncoderNamedPresetHTwoSixFiveSingleBitrateOneZeroEightZerop EncoderNamedPreset = "H265SingleBitrate1080p" + EncoderNamedPresetHTwoSixFiveSingleBitrateSevenTwoZerop EncoderNamedPreset = "H265SingleBitrate720p" + EncoderNamedPresetHTwoSixFourMultipleBitrateOneZeroEightZerop EncoderNamedPreset = "H264MultipleBitrate1080p" + EncoderNamedPresetHTwoSixFourMultipleBitrateSD EncoderNamedPreset = "H264MultipleBitrateSD" + EncoderNamedPresetHTwoSixFourMultipleBitrateSevenTwoZerop EncoderNamedPreset = "H264MultipleBitrate720p" + EncoderNamedPresetHTwoSixFourSingleBitrateOneZeroEightZerop EncoderNamedPreset = "H264SingleBitrate1080p" + EncoderNamedPresetHTwoSixFourSingleBitrateSD EncoderNamedPreset = "H264SingleBitrateSD" + EncoderNamedPresetHTwoSixFourSingleBitrateSevenTwoZerop EncoderNamedPreset = "H264SingleBitrate720p" +) + +func PossibleValuesForEncoderNamedPreset() []string { + return []string{ + string(EncoderNamedPresetAACGoodQualityAudio), + string(EncoderNamedPresetAdaptiveStreaming), + string(EncoderNamedPresetContentAwareEncoding), + string(EncoderNamedPresetContentAwareEncodingExperimental), + string(EncoderNamedPresetCopyAllBitrateNonInterleaved), + string(EncoderNamedPresetDDGoodQualityAudio), + string(EncoderNamedPresetHTwoSixFiveAdaptiveStreaming), + string(EncoderNamedPresetHTwoSixFiveContentAwareEncoding), + string(EncoderNamedPresetHTwoSixFiveSingleBitrateFourK), + string(EncoderNamedPresetHTwoSixFiveSingleBitrateOneZeroEightZerop), + string(EncoderNamedPresetHTwoSixFiveSingleBitrateSevenTwoZerop), + string(EncoderNamedPresetHTwoSixFourMultipleBitrateOneZeroEightZerop), + string(EncoderNamedPresetHTwoSixFourMultipleBitrateSD), + string(EncoderNamedPresetHTwoSixFourMultipleBitrateSevenTwoZerop), + string(EncoderNamedPresetHTwoSixFourSingleBitrateOneZeroEightZerop), + string(EncoderNamedPresetHTwoSixFourSingleBitrateSD), + string(EncoderNamedPresetHTwoSixFourSingleBitrateSevenTwoZerop), + } +} + +func parseEncoderNamedPreset(input string) (*EncoderNamedPreset, error) { + vals := map[string]EncoderNamedPreset{ + "aacgoodqualityaudio": EncoderNamedPresetAACGoodQualityAudio, + "adaptivestreaming": EncoderNamedPresetAdaptiveStreaming, + "contentawareencoding": EncoderNamedPresetContentAwareEncoding, + "contentawareencodingexperimental": EncoderNamedPresetContentAwareEncodingExperimental, + "copyallbitratenoninterleaved": EncoderNamedPresetCopyAllBitrateNonInterleaved, + "ddgoodqualityaudio": EncoderNamedPresetDDGoodQualityAudio, + "h265adaptivestreaming": EncoderNamedPresetHTwoSixFiveAdaptiveStreaming, + "h265contentawareencoding": EncoderNamedPresetHTwoSixFiveContentAwareEncoding, + "h265singlebitrate4k": EncoderNamedPresetHTwoSixFiveSingleBitrateFourK, + "h265singlebitrate1080p": EncoderNamedPresetHTwoSixFiveSingleBitrateOneZeroEightZerop, + "h265singlebitrate720p": EncoderNamedPresetHTwoSixFiveSingleBitrateSevenTwoZerop, + "h264multiplebitrate1080p": EncoderNamedPresetHTwoSixFourMultipleBitrateOneZeroEightZerop, + "h264multiplebitratesd": EncoderNamedPresetHTwoSixFourMultipleBitrateSD, + "h264multiplebitrate720p": EncoderNamedPresetHTwoSixFourMultipleBitrateSevenTwoZerop, + "h264singlebitrate1080p": EncoderNamedPresetHTwoSixFourSingleBitrateOneZeroEightZerop, + "h264singlebitratesd": EncoderNamedPresetHTwoSixFourSingleBitrateSD, + "h264singlebitrate720p": EncoderNamedPresetHTwoSixFourSingleBitrateSevenTwoZerop, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EncoderNamedPreset(input) + return &out, nil +} + +type EntropyMode string + +const ( + EntropyModeCabac EntropyMode = "Cabac" + EntropyModeCavlc EntropyMode = "Cavlc" +) + +func PossibleValuesForEntropyMode() []string { + return []string{ + string(EntropyModeCabac), + string(EntropyModeCavlc), + } +} + +func parseEntropyMode(input string) (*EntropyMode, error) { + vals := map[string]EntropyMode{ + "cabac": EntropyModeCabac, + "cavlc": EntropyModeCavlc, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EntropyMode(input) + return &out, nil +} + +type FaceRedactorMode string + +const ( + FaceRedactorModeAnalyze FaceRedactorMode = "Analyze" + FaceRedactorModeCombined FaceRedactorMode = "Combined" + FaceRedactorModeRedact FaceRedactorMode = "Redact" +) + +func PossibleValuesForFaceRedactorMode() []string { + return []string{ + string(FaceRedactorModeAnalyze), + string(FaceRedactorModeCombined), + string(FaceRedactorModeRedact), + } +} + +func parseFaceRedactorMode(input string) (*FaceRedactorMode, error) { + vals := map[string]FaceRedactorMode{ + "analyze": FaceRedactorModeAnalyze, + "combined": FaceRedactorModeCombined, + "redact": FaceRedactorModeRedact, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FaceRedactorMode(input) + return &out, nil +} + +type H264Complexity string + +const ( + H264ComplexityBalanced H264Complexity = "Balanced" + H264ComplexityQuality H264Complexity = "Quality" + H264ComplexitySpeed H264Complexity = "Speed" +) + +func PossibleValuesForH264Complexity() []string { + return []string{ + string(H264ComplexityBalanced), + string(H264ComplexityQuality), + string(H264ComplexitySpeed), + } +} + +func parseH264Complexity(input string) (*H264Complexity, error) { + vals := map[string]H264Complexity{ + "balanced": H264ComplexityBalanced, + "quality": H264ComplexityQuality, + "speed": H264ComplexitySpeed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := H264Complexity(input) + return &out, nil +} + +type H264RateControlMode string + +const ( + H264RateControlModeABR H264RateControlMode = "ABR" + H264RateControlModeCBR H264RateControlMode = "CBR" + H264RateControlModeCRF H264RateControlMode = "CRF" +) + +func PossibleValuesForH264RateControlMode() []string { + return []string{ + string(H264RateControlModeABR), + string(H264RateControlModeCBR), + string(H264RateControlModeCRF), + } +} + +func parseH264RateControlMode(input string) (*H264RateControlMode, error) { + vals := map[string]H264RateControlMode{ + "abr": H264RateControlModeABR, + "cbr": H264RateControlModeCBR, + "crf": H264RateControlModeCRF, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := H264RateControlMode(input) + return &out, nil +} + +type H264VideoProfile string + +const ( + H264VideoProfileAuto H264VideoProfile = "Auto" + H264VideoProfileBaseline H264VideoProfile = "Baseline" + H264VideoProfileHigh H264VideoProfile = "High" + H264VideoProfileHighFourFourFour H264VideoProfile = "High444" + H264VideoProfileHighFourTwoTwo H264VideoProfile = "High422" + H264VideoProfileMain H264VideoProfile = "Main" +) + +func PossibleValuesForH264VideoProfile() []string { + return []string{ + string(H264VideoProfileAuto), + string(H264VideoProfileBaseline), + string(H264VideoProfileHigh), + string(H264VideoProfileHighFourFourFour), + string(H264VideoProfileHighFourTwoTwo), + string(H264VideoProfileMain), + } +} + +func parseH264VideoProfile(input string) (*H264VideoProfile, error) { + vals := map[string]H264VideoProfile{ + "auto": H264VideoProfileAuto, + "baseline": H264VideoProfileBaseline, + "high": H264VideoProfileHigh, + "high444": H264VideoProfileHighFourFourFour, + "high422": H264VideoProfileHighFourTwoTwo, + "main": H264VideoProfileMain, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := H264VideoProfile(input) + return &out, nil +} + +type H265Complexity string + +const ( + H265ComplexityBalanced H265Complexity = "Balanced" + H265ComplexityQuality H265Complexity = "Quality" + H265ComplexitySpeed H265Complexity = "Speed" +) + +func PossibleValuesForH265Complexity() []string { + return []string{ + string(H265ComplexityBalanced), + string(H265ComplexityQuality), + string(H265ComplexitySpeed), + } +} + +func parseH265Complexity(input string) (*H265Complexity, error) { + vals := map[string]H265Complexity{ + "balanced": H265ComplexityBalanced, + "quality": H265ComplexityQuality, + "speed": H265ComplexitySpeed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := H265Complexity(input) + return &out, nil +} + +type H265VideoProfile string + +const ( + H265VideoProfileAuto H265VideoProfile = "Auto" + H265VideoProfileMain H265VideoProfile = "Main" + H265VideoProfileMainOneZero H265VideoProfile = "Main10" +) + +func PossibleValuesForH265VideoProfile() []string { + return []string{ + string(H265VideoProfileAuto), + string(H265VideoProfileMain), + string(H265VideoProfileMainOneZero), + } +} + +func parseH265VideoProfile(input string) (*H265VideoProfile, error) { + vals := map[string]H265VideoProfile{ + "auto": H265VideoProfileAuto, + "main": H265VideoProfileMain, + "main10": H265VideoProfileMainOneZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := H265VideoProfile(input) + return &out, nil +} + +type InsightsType string + +const ( + InsightsTypeAllInsights InsightsType = "AllInsights" + InsightsTypeAudioInsightsOnly InsightsType = "AudioInsightsOnly" + InsightsTypeVideoInsightsOnly InsightsType = "VideoInsightsOnly" +) + +func PossibleValuesForInsightsType() []string { + return []string{ + string(InsightsTypeAllInsights), + string(InsightsTypeAudioInsightsOnly), + string(InsightsTypeVideoInsightsOnly), + } +} + +func parseInsightsType(input string) (*InsightsType, error) { + vals := map[string]InsightsType{ + "allinsights": InsightsTypeAllInsights, + "audioinsightsonly": InsightsTypeAudioInsightsOnly, + "videoinsightsonly": InsightsTypeVideoInsightsOnly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InsightsType(input) + return &out, nil +} + +type InterleaveOutput string + +const ( + InterleaveOutputInterleavedOutput InterleaveOutput = "InterleavedOutput" + InterleaveOutputNonInterleavedOutput InterleaveOutput = "NonInterleavedOutput" +) + +func PossibleValuesForInterleaveOutput() []string { + return []string{ + string(InterleaveOutputInterleavedOutput), + string(InterleaveOutputNonInterleavedOutput), + } +} + +func parseInterleaveOutput(input string) (*InterleaveOutput, error) { + vals := map[string]InterleaveOutput{ + "interleavedoutput": InterleaveOutputInterleavedOutput, + "noninterleavedoutput": InterleaveOutputNonInterleavedOutput, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InterleaveOutput(input) + return &out, nil +} + +type JobErrorCategory string + +const ( + JobErrorCategoryAccount JobErrorCategory = "Account" + JobErrorCategoryConfiguration JobErrorCategory = "Configuration" + JobErrorCategoryContent JobErrorCategory = "Content" + JobErrorCategoryDownload JobErrorCategory = "Download" + JobErrorCategoryService JobErrorCategory = "Service" + JobErrorCategoryUpload JobErrorCategory = "Upload" +) + +func PossibleValuesForJobErrorCategory() []string { + return []string{ + string(JobErrorCategoryAccount), + string(JobErrorCategoryConfiguration), + string(JobErrorCategoryContent), + string(JobErrorCategoryDownload), + string(JobErrorCategoryService), + string(JobErrorCategoryUpload), + } +} + +func parseJobErrorCategory(input string) (*JobErrorCategory, error) { + vals := map[string]JobErrorCategory{ + "account": JobErrorCategoryAccount, + "configuration": JobErrorCategoryConfiguration, + "content": JobErrorCategoryContent, + "download": JobErrorCategoryDownload, + "service": JobErrorCategoryService, + "upload": JobErrorCategoryUpload, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobErrorCategory(input) + return &out, nil +} + +type JobErrorCode string + +const ( + JobErrorCodeConfigurationUnsupported JobErrorCode = "ConfigurationUnsupported" + JobErrorCodeContentMalformed JobErrorCode = "ContentMalformed" + JobErrorCodeContentUnsupported JobErrorCode = "ContentUnsupported" + JobErrorCodeDownloadNotAccessible JobErrorCode = "DownloadNotAccessible" + JobErrorCodeDownloadTransientError JobErrorCode = "DownloadTransientError" + JobErrorCodeIdentityUnsupported JobErrorCode = "IdentityUnsupported" + JobErrorCodeServiceError JobErrorCode = "ServiceError" + JobErrorCodeServiceTransientError JobErrorCode = "ServiceTransientError" + JobErrorCodeUploadNotAccessible JobErrorCode = "UploadNotAccessible" + JobErrorCodeUploadTransientError JobErrorCode = "UploadTransientError" +) + +func PossibleValuesForJobErrorCode() []string { + return []string{ + string(JobErrorCodeConfigurationUnsupported), + string(JobErrorCodeContentMalformed), + string(JobErrorCodeContentUnsupported), + string(JobErrorCodeDownloadNotAccessible), + string(JobErrorCodeDownloadTransientError), + string(JobErrorCodeIdentityUnsupported), + string(JobErrorCodeServiceError), + string(JobErrorCodeServiceTransientError), + string(JobErrorCodeUploadNotAccessible), + string(JobErrorCodeUploadTransientError), + } +} + +func parseJobErrorCode(input string) (*JobErrorCode, error) { + vals := map[string]JobErrorCode{ + "configurationunsupported": JobErrorCodeConfigurationUnsupported, + "contentmalformed": JobErrorCodeContentMalformed, + "contentunsupported": JobErrorCodeContentUnsupported, + "downloadnotaccessible": JobErrorCodeDownloadNotAccessible, + "downloadtransienterror": JobErrorCodeDownloadTransientError, + "identityunsupported": JobErrorCodeIdentityUnsupported, + "serviceerror": JobErrorCodeServiceError, + "servicetransienterror": JobErrorCodeServiceTransientError, + "uploadnotaccessible": JobErrorCodeUploadNotAccessible, + "uploadtransienterror": JobErrorCodeUploadTransientError, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobErrorCode(input) + return &out, nil +} + +type JobRetry string + +const ( + JobRetryDoNotRetry JobRetry = "DoNotRetry" + JobRetryMayRetry JobRetry = "MayRetry" +) + +func PossibleValuesForJobRetry() []string { + return []string{ + string(JobRetryDoNotRetry), + string(JobRetryMayRetry), + } +} + +func parseJobRetry(input string) (*JobRetry, error) { + vals := map[string]JobRetry{ + "donotretry": JobRetryDoNotRetry, + "mayretry": JobRetryMayRetry, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobRetry(input) + return &out, nil +} + +type JobState string + +const ( + JobStateCanceled JobState = "Canceled" + JobStateCanceling JobState = "Canceling" + JobStateError JobState = "Error" + JobStateFinished JobState = "Finished" + JobStateProcessing JobState = "Processing" + JobStateQueued JobState = "Queued" + JobStateScheduled JobState = "Scheduled" +) + +func PossibleValuesForJobState() []string { + return []string{ + string(JobStateCanceled), + string(JobStateCanceling), + string(JobStateError), + string(JobStateFinished), + string(JobStateProcessing), + string(JobStateQueued), + string(JobStateScheduled), + } +} + +func parseJobState(input string) (*JobState, error) { + vals := map[string]JobState{ + "canceled": JobStateCanceled, + "canceling": JobStateCanceling, + "error": JobStateError, + "finished": JobStateFinished, + "processing": JobStateProcessing, + "queued": JobStateQueued, + "scheduled": JobStateScheduled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobState(input) + return &out, nil +} + +type OnErrorType string + +const ( + OnErrorTypeContinueJob OnErrorType = "ContinueJob" + OnErrorTypeStopProcessingJob OnErrorType = "StopProcessingJob" +) + +func PossibleValuesForOnErrorType() []string { + return []string{ + string(OnErrorTypeContinueJob), + string(OnErrorTypeStopProcessingJob), + } +} + +func parseOnErrorType(input string) (*OnErrorType, error) { + vals := map[string]OnErrorType{ + "continuejob": OnErrorTypeContinueJob, + "stopprocessingjob": OnErrorTypeStopProcessingJob, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OnErrorType(input) + return &out, nil +} + +type Priority string + +const ( + PriorityHigh Priority = "High" + PriorityLow Priority = "Low" + PriorityNormal Priority = "Normal" +) + +func PossibleValuesForPriority() []string { + return []string{ + string(PriorityHigh), + string(PriorityLow), + string(PriorityNormal), + } +} + +func parsePriority(input string) (*Priority, error) { + vals := map[string]Priority{ + "high": PriorityHigh, + "low": PriorityLow, + "normal": PriorityNormal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Priority(input) + return &out, nil +} + +type Rotation string + +const ( + RotationAuto Rotation = "Auto" + RotationNone Rotation = "None" + RotationRotateNineZero Rotation = "Rotate90" + RotationRotateOneEightZero Rotation = "Rotate180" + RotationRotateTwoSevenZero Rotation = "Rotate270" + RotationRotateZero Rotation = "Rotate0" +) + +func PossibleValuesForRotation() []string { + return []string{ + string(RotationAuto), + string(RotationNone), + string(RotationRotateNineZero), + string(RotationRotateOneEightZero), + string(RotationRotateTwoSevenZero), + string(RotationRotateZero), + } +} + +func parseRotation(input string) (*Rotation, error) { + vals := map[string]Rotation{ + "auto": RotationAuto, + "none": RotationNone, + "rotate90": RotationRotateNineZero, + "rotate180": RotationRotateOneEightZero, + "rotate270": RotationRotateTwoSevenZero, + "rotate0": RotationRotateZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Rotation(input) + return &out, nil +} + +type StretchMode string + +const ( + StretchModeAutoFit StretchMode = "AutoFit" + StretchModeAutoSize StretchMode = "AutoSize" + StretchModeNone StretchMode = "None" +) + +func PossibleValuesForStretchMode() []string { + return []string{ + string(StretchModeAutoFit), + string(StretchModeAutoSize), + string(StretchModeNone), + } +} + +func parseStretchMode(input string) (*StretchMode, error) { + vals := map[string]StretchMode{ + "autofit": StretchModeAutoFit, + "autosize": StretchModeAutoSize, + "none": StretchModeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StretchMode(input) + return &out, nil +} + +type TrackAttribute string + +const ( + TrackAttributeBitrate TrackAttribute = "Bitrate" + TrackAttributeLanguage TrackAttribute = "Language" +) + +func PossibleValuesForTrackAttribute() []string { + return []string{ + string(TrackAttributeBitrate), + string(TrackAttributeLanguage), + } +} + +func parseTrackAttribute(input string) (*TrackAttribute, error) { + vals := map[string]TrackAttribute{ + "bitrate": TrackAttributeBitrate, + "language": TrackAttributeLanguage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TrackAttribute(input) + return &out, nil +} + +type VideoSyncMode string + +const ( + VideoSyncModeAuto VideoSyncMode = "Auto" + VideoSyncModeCfr VideoSyncMode = "Cfr" + VideoSyncModePassthrough VideoSyncMode = "Passthrough" + VideoSyncModeVfr VideoSyncMode = "Vfr" +) + +func PossibleValuesForVideoSyncMode() []string { + return []string{ + string(VideoSyncModeAuto), + string(VideoSyncModeCfr), + string(VideoSyncModePassthrough), + string(VideoSyncModeVfr), + } +} + +func parseVideoSyncMode(input string) (*VideoSyncMode, error) { + vals := map[string]VideoSyncMode{ + "auto": VideoSyncModeAuto, + "cfr": VideoSyncModeCfr, + "passthrough": VideoSyncModePassthrough, + "vfr": VideoSyncModeVfr, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VideoSyncMode(input) + return &out, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/id_job.go b/resource-manager/media/2022-07-01/encodings/id_job.go new file mode 100644 index 00000000000..16c0f06b2fa --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/id_job.go @@ -0,0 +1,153 @@ +package encodings + +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 = JobId{} + +// JobId is a struct representing the Resource ID for a Job +type JobId struct { + SubscriptionId string + ResourceGroupName string + MediaServiceName string + TransformName string + JobName string +} + +// NewJobID returns a new JobId struct +func NewJobID(subscriptionId string, resourceGroupName string, mediaServiceName string, transformName string, jobName string) JobId { + return JobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MediaServiceName: mediaServiceName, + TransformName: transformName, + JobName: jobName, + } +} + +// ParseJobID parses 'input' into a JobId +func ParseJobID(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(JobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := JobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.MediaServiceName, ok = parsed.Parsed["mediaServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'mediaServiceName' was not found in the resource id %q", input) + } + + if id.TransformName, ok = parsed.Parsed["transformName"]; !ok { + return nil, fmt.Errorf("the segment 'transformName' was not found in the resource id %q", input) + } + + if id.JobName, ok = parsed.Parsed["jobName"]; !ok { + return nil, fmt.Errorf("the segment 'jobName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseJobIDInsensitively parses 'input' case-insensitively into a JobId +// note: this method should only be used for API response data and not user input +func ParseJobIDInsensitively(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(JobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := JobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.MediaServiceName, ok = parsed.Parsed["mediaServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'mediaServiceName' was not found in the resource id %q", input) + } + + if id.TransformName, ok = parsed.Parsed["transformName"]; !ok { + return nil, fmt.Errorf("the segment 'transformName' was not found in the resource id %q", input) + } + + if id.JobName, ok = parsed.Parsed["jobName"]; !ok { + return nil, fmt.Errorf("the segment 'jobName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateJobID checks that 'input' can be parsed as a Job ID +func ValidateJobID(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 := ParseJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job ID +func (id JobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Media/mediaServices/%s/transforms/%s/jobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MediaServiceName, id.TransformName, id.JobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job ID +func (id JobId) 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("staticMicrosoftMedia", "Microsoft.Media", "Microsoft.Media"), + resourceids.StaticSegment("staticMediaServices", "mediaServices", "mediaServices"), + resourceids.UserSpecifiedSegment("mediaServiceName", "mediaServiceValue"), + resourceids.StaticSegment("staticTransforms", "transforms", "transforms"), + resourceids.UserSpecifiedSegment("transformName", "transformValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + } +} + +// String returns a human-readable description of this Job ID +func (id JobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Media Service Name: %q", id.MediaServiceName), + fmt.Sprintf("Transform Name: %q", id.TransformName), + fmt.Sprintf("Job Name: %q", id.JobName), + } + return fmt.Sprintf("Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/media/2022-07-01/encodings/id_job_test.go b/resource-manager/media/2022-07-01/encodings/id_job_test.go new file mode 100644 index 00000000000..e0afa9fec75 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/id_job_test.go @@ -0,0 +1,372 @@ +package encodings + +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 = JobId{} + +func TestNewJobID(t *testing.T) { + id := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue", "jobValue") + + 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.MediaServiceName != "mediaServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'MediaServiceName'", id.MediaServiceName, "mediaServiceValue") + } + + if id.TransformName != "transformValue" { + t.Fatalf("Expected %q but got %q for Segment 'TransformName'", id.TransformName, "transformValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue", "jobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/jobs/jobValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Media", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MediaServiceName: "mediaServiceValue", + TransformName: "transformValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/jobs/jobValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobID(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.MediaServiceName != v.Expected.MediaServiceName { + t.Fatalf("Expected %q but got %q for MediaServiceName", v.Expected.MediaServiceName, actual.MediaServiceName) + } + + if actual.TransformName != v.Expected.TransformName { + t.Fatalf("Expected %q but got %q for TransformName", v.Expected.TransformName, actual.TransformName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestParseJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Media", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS/tRaNsFoRmVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS/tRaNsFoRmVaLuE/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MediaServiceName: "mediaServiceValue", + TransformName: "transformValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/jobs/jobValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS/tRaNsFoRmVaLuE/jObS/jObVaLuE", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MediaServiceName: "mEdIaSeRvIcEvAlUe", + TransformName: "tRaNsFoRmVaLuE", + JobName: "jObVaLuE", + }, + }, + { + // 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.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS/tRaNsFoRmVaLuE/jObS/jObVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobIDInsensitively(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.MediaServiceName != v.Expected.MediaServiceName { + t.Fatalf("Expected %q but got %q for MediaServiceName", v.Expected.MediaServiceName, actual.MediaServiceName) + } + + if actual.TransformName != v.Expected.TransformName { + t.Fatalf("Expected %q but got %q for TransformName", v.Expected.TransformName, actual.TransformName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestSegmentsForJobId(t *testing.T) { + segments := JobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobId 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/media/2022-07-01/encodings/id_mediaservice.go b/resource-manager/media/2022-07-01/encodings/id_mediaservice.go new file mode 100644 index 00000000000..1d885884191 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/id_mediaservice.go @@ -0,0 +1,127 @@ +package encodings + +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 = MediaServiceId{} + +// MediaServiceId is a struct representing the Resource ID for a Media Service +type MediaServiceId struct { + SubscriptionId string + ResourceGroupName string + MediaServiceName string +} + +// NewMediaServiceID returns a new MediaServiceId struct +func NewMediaServiceID(subscriptionId string, resourceGroupName string, mediaServiceName string) MediaServiceId { + return MediaServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MediaServiceName: mediaServiceName, + } +} + +// ParseMediaServiceID parses 'input' into a MediaServiceId +func ParseMediaServiceID(input string) (*MediaServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(MediaServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MediaServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.MediaServiceName, ok = parsed.Parsed["mediaServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'mediaServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseMediaServiceIDInsensitively parses 'input' case-insensitively into a MediaServiceId +// note: this method should only be used for API response data and not user input +func ParseMediaServiceIDInsensitively(input string) (*MediaServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(MediaServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MediaServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.MediaServiceName, ok = parsed.Parsed["mediaServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'mediaServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateMediaServiceID checks that 'input' can be parsed as a Media Service ID +func ValidateMediaServiceID(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 := ParseMediaServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Media Service ID +func (id MediaServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Media/mediaServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MediaServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Media Service ID +func (id MediaServiceId) 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("staticMicrosoftMedia", "Microsoft.Media", "Microsoft.Media"), + resourceids.StaticSegment("staticMediaServices", "mediaServices", "mediaServices"), + resourceids.UserSpecifiedSegment("mediaServiceName", "mediaServiceValue"), + } +} + +// String returns a human-readable description of this Media Service ID +func (id MediaServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Media Service Name: %q", id.MediaServiceName), + } + return fmt.Sprintf("Media Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/media/2022-07-01/encodings/id_mediaservice_test.go b/resource-manager/media/2022-07-01/encodings/id_mediaservice_test.go new file mode 100644 index 00000000000..f5016b17121 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/id_mediaservice_test.go @@ -0,0 +1,282 @@ +package encodings + +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 = MediaServiceId{} + +func TestNewMediaServiceID(t *testing.T) { + id := NewMediaServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue") + + 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.MediaServiceName != "mediaServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'MediaServiceName'", id.MediaServiceName, "mediaServiceValue") + } +} + +func TestFormatMediaServiceID(t *testing.T) { + actual := NewMediaServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMediaServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MediaServiceId + }{ + { + // 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.Media", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue", + Expected: &MediaServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MediaServiceName: "mediaServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMediaServiceID(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.MediaServiceName != v.Expected.MediaServiceName { + t.Fatalf("Expected %q but got %q for MediaServiceName", v.Expected.MediaServiceName, actual.MediaServiceName) + } + + } +} + +func TestParseMediaServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MediaServiceId + }{ + { + // 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.Media", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue", + Expected: &MediaServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MediaServiceName: "mediaServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe", + Expected: &MediaServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MediaServiceName: "mEdIaSeRvIcEvAlUe", + }, + }, + { + // 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.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMediaServiceIDInsensitively(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.MediaServiceName != v.Expected.MediaServiceName { + t.Fatalf("Expected %q but got %q for MediaServiceName", v.Expected.MediaServiceName, actual.MediaServiceName) + } + + } +} + +func TestSegmentsForMediaServiceId(t *testing.T) { + segments := MediaServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MediaServiceId 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/media/2022-07-01/encodings/id_transform.go b/resource-manager/media/2022-07-01/encodings/id_transform.go new file mode 100644 index 00000000000..bcc44e24283 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/id_transform.go @@ -0,0 +1,140 @@ +package encodings + +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 = TransformId{} + +// TransformId is a struct representing the Resource ID for a Transform +type TransformId struct { + SubscriptionId string + ResourceGroupName string + MediaServiceName string + TransformName string +} + +// NewTransformID returns a new TransformId struct +func NewTransformID(subscriptionId string, resourceGroupName string, mediaServiceName string, transformName string) TransformId { + return TransformId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MediaServiceName: mediaServiceName, + TransformName: transformName, + } +} + +// ParseTransformID parses 'input' into a TransformId +func ParseTransformID(input string) (*TransformId, error) { + parser := resourceids.NewParserFromResourceIdType(TransformId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TransformId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.MediaServiceName, ok = parsed.Parsed["mediaServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'mediaServiceName' was not found in the resource id %q", input) + } + + if id.TransformName, ok = parsed.Parsed["transformName"]; !ok { + return nil, fmt.Errorf("the segment 'transformName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseTransformIDInsensitively parses 'input' case-insensitively into a TransformId +// note: this method should only be used for API response data and not user input +func ParseTransformIDInsensitively(input string) (*TransformId, error) { + parser := resourceids.NewParserFromResourceIdType(TransformId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TransformId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.MediaServiceName, ok = parsed.Parsed["mediaServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'mediaServiceName' was not found in the resource id %q", input) + } + + if id.TransformName, ok = parsed.Parsed["transformName"]; !ok { + return nil, fmt.Errorf("the segment 'transformName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateTransformID checks that 'input' can be parsed as a Transform ID +func ValidateTransformID(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 := ParseTransformID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Transform ID +func (id TransformId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Media/mediaServices/%s/transforms/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MediaServiceName, id.TransformName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Transform ID +func (id TransformId) 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("staticMicrosoftMedia", "Microsoft.Media", "Microsoft.Media"), + resourceids.StaticSegment("staticMediaServices", "mediaServices", "mediaServices"), + resourceids.UserSpecifiedSegment("mediaServiceName", "mediaServiceValue"), + resourceids.StaticSegment("staticTransforms", "transforms", "transforms"), + resourceids.UserSpecifiedSegment("transformName", "transformValue"), + } +} + +// String returns a human-readable description of this Transform ID +func (id TransformId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Media Service Name: %q", id.MediaServiceName), + fmt.Sprintf("Transform Name: %q", id.TransformName), + } + return fmt.Sprintf("Transform (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/media/2022-07-01/encodings/id_transform_test.go b/resource-manager/media/2022-07-01/encodings/id_transform_test.go new file mode 100644 index 00000000000..fe85fc024e9 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/id_transform_test.go @@ -0,0 +1,327 @@ +package encodings + +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 = TransformId{} + +func TestNewTransformID(t *testing.T) { + id := NewTransformID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue") + + 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.MediaServiceName != "mediaServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'MediaServiceName'", id.MediaServiceName, "mediaServiceValue") + } + + if id.TransformName != "transformValue" { + t.Fatalf("Expected %q but got %q for Segment 'TransformName'", id.TransformName, "transformValue") + } +} + +func TestFormatTransformID(t *testing.T) { + actual := NewTransformID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mediaServiceValue", "transformValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTransformID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TransformId + }{ + { + // 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.Media", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue", + Expected: &TransformId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MediaServiceName: "mediaServiceValue", + TransformName: "transformValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTransformID(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.MediaServiceName != v.Expected.MediaServiceName { + t.Fatalf("Expected %q but got %q for MediaServiceName", v.Expected.MediaServiceName, actual.MediaServiceName) + } + + if actual.TransformName != v.Expected.TransformName { + t.Fatalf("Expected %q but got %q for TransformName", v.Expected.TransformName, actual.TransformName) + } + + } +} + +func TestParseTransformIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TransformId + }{ + { + // 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.Media", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue", + Expected: &TransformId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MediaServiceName: "mediaServiceValue", + TransformName: "transformValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Media/mediaServices/mediaServiceValue/transforms/transformValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS/tRaNsFoRmVaLuE", + Expected: &TransformId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MediaServiceName: "mEdIaSeRvIcEvAlUe", + TransformName: "tRaNsFoRmVaLuE", + }, + }, + { + // 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.mEdIa/mEdIaSeRvIcEs/mEdIaSeRvIcEvAlUe/tRaNsFoRmS/tRaNsFoRmVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTransformIDInsensitively(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.MediaServiceName != v.Expected.MediaServiceName { + t.Fatalf("Expected %q but got %q for MediaServiceName", v.Expected.MediaServiceName, actual.MediaServiceName) + } + + if actual.TransformName != v.Expected.TransformName { + t.Fatalf("Expected %q but got %q for TransformName", v.Expected.TransformName, actual.TransformName) + } + + } +} + +func TestSegmentsForTransformId(t *testing.T) { + segments := TransformId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TransformId 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/media/2022-07-01/encodings/method_jobscanceljob.go b/resource-manager/media/2022-07-01/encodings/method_jobscanceljob.go new file mode 100644 index 00000000000..48985cf8b23 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_jobscanceljob.go @@ -0,0 +1,47 @@ +package encodings + +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 JobsCancelJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// JobsCancelJob ... +func (c EncodingsClient) JobsCancelJob(ctx context.Context, id JobId) (result JobsCancelJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancelJob", 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/media/2022-07-01/encodings/method_jobscreate.go b/resource-manager/media/2022-07-01/encodings/method_jobscreate.go new file mode 100644 index 00000000000..97a2dd339c2 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_jobscreate.go @@ -0,0 +1,55 @@ +package encodings + +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 JobsCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Job +} + +// JobsCreate ... +func (c EncodingsClient) JobsCreate(ctx context.Context, id JobId, input Job) (result JobsCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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/media/2022-07-01/encodings/method_jobsdelete.go b/resource-manager/media/2022-07-01/encodings/method_jobsdelete.go new file mode 100644 index 00000000000..c57670ea654 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_jobsdelete.go @@ -0,0 +1,47 @@ +package encodings + +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 JobsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// JobsDelete ... +func (c EncodingsClient) JobsDelete(ctx context.Context, id JobId) (result JobsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/media/2022-07-01/encodings/method_jobsget.go b/resource-manager/media/2022-07-01/encodings/method_jobsget.go new file mode 100644 index 00000000000..3242d1224d1 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_jobsget.go @@ -0,0 +1,51 @@ +package encodings + +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 *Job +} + +// JobsGet ... +func (c EncodingsClient) JobsGet(ctx context.Context, id JobId) (result JobsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/media/2022-07-01/encodings/method_jobslist.go b/resource-manager/media/2022-07-01/encodings/method_jobslist.go new file mode 100644 index 00000000000..d54fa2a56ff --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_jobslist.go @@ -0,0 +1,121 @@ +package encodings + +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 *[]Job +} + +type JobsListCompleteResult struct { + Items []Job +} + +type JobsListOperationOptions struct { + Filter *string + Orderby *string +} + +func DefaultJobsListOperationOptions() JobsListOperationOptions { + return JobsListOperationOptions{} +} + +func (o JobsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o JobsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o JobsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + return &out +} + +// JobsList ... +func (c EncodingsClient) JobsList(ctx context.Context, id TransformId, options JobsListOperationOptions) (result JobsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/jobs", 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 *[]Job `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// JobsListComplete retrieves all the results into a single object +func (c EncodingsClient) JobsListComplete(ctx context.Context, id TransformId, options JobsListOperationOptions) (JobsListCompleteResult, error) { + return c.JobsListCompleteMatchingPredicate(ctx, id, options, JobOperationPredicate{}) +} + +// JobsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EncodingsClient) JobsListCompleteMatchingPredicate(ctx context.Context, id TransformId, options JobsListOperationOptions, predicate JobOperationPredicate) (result JobsListCompleteResult, err error) { + items := make([]Job, 0) + + resp, err := c.JobsList(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 = JobsListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/media/2022-07-01/encodings/method_jobsupdate.go b/resource-manager/media/2022-07-01/encodings/method_jobsupdate.go new file mode 100644 index 00000000000..f26f1c4e228 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_jobsupdate.go @@ -0,0 +1,55 @@ +package encodings + +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 JobsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Job +} + +// JobsUpdate ... +func (c EncodingsClient) JobsUpdate(ctx context.Context, id JobId, input Job) (result JobsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/media/2022-07-01/encodings/method_transformscreateorupdate.go b/resource-manager/media/2022-07-01/encodings/method_transformscreateorupdate.go new file mode 100644 index 00000000000..e6d4e6254a6 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_transformscreateorupdate.go @@ -0,0 +1,56 @@ +package encodings + +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 TransformsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Transform +} + +// TransformsCreateOrUpdate ... +func (c EncodingsClient) TransformsCreateOrUpdate(ctx context.Context, id TransformId, input Transform) (result TransformsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/media/2022-07-01/encodings/method_transformsdelete.go b/resource-manager/media/2022-07-01/encodings/method_transformsdelete.go new file mode 100644 index 00000000000..2c40aeb7f23 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_transformsdelete.go @@ -0,0 +1,47 @@ +package encodings + +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 TransformsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TransformsDelete ... +func (c EncodingsClient) TransformsDelete(ctx context.Context, id TransformId) (result TransformsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/media/2022-07-01/encodings/method_transformsget.go b/resource-manager/media/2022-07-01/encodings/method_transformsget.go new file mode 100644 index 00000000000..044a299e363 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_transformsget.go @@ -0,0 +1,51 @@ +package encodings + +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 TransformsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Transform +} + +// TransformsGet ... +func (c EncodingsClient) TransformsGet(ctx context.Context, id TransformId) (result TransformsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/media/2022-07-01/encodings/method_transformslist.go b/resource-manager/media/2022-07-01/encodings/method_transformslist.go new file mode 100644 index 00000000000..07901783eaf --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_transformslist.go @@ -0,0 +1,121 @@ +package encodings + +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 TransformsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Transform +} + +type TransformsListCompleteResult struct { + Items []Transform +} + +type TransformsListOperationOptions struct { + Filter *string + Orderby *string +} + +func DefaultTransformsListOperationOptions() TransformsListOperationOptions { + return TransformsListOperationOptions{} +} + +func (o TransformsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o TransformsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o TransformsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + return &out +} + +// TransformsList ... +func (c EncodingsClient) TransformsList(ctx context.Context, id MediaServiceId, options TransformsListOperationOptions) (result TransformsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/transforms", 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 *[]Transform `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// TransformsListComplete retrieves all the results into a single object +func (c EncodingsClient) TransformsListComplete(ctx context.Context, id MediaServiceId, options TransformsListOperationOptions) (TransformsListCompleteResult, error) { + return c.TransformsListCompleteMatchingPredicate(ctx, id, options, TransformOperationPredicate{}) +} + +// TransformsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EncodingsClient) TransformsListCompleteMatchingPredicate(ctx context.Context, id MediaServiceId, options TransformsListOperationOptions, predicate TransformOperationPredicate) (result TransformsListCompleteResult, err error) { + items := make([]Transform, 0) + + resp, err := c.TransformsList(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 = TransformsListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/media/2022-07-01/encodings/method_transformsupdate.go b/resource-manager/media/2022-07-01/encodings/method_transformsupdate.go new file mode 100644 index 00000000000..191fd4ffa19 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/method_transformsupdate.go @@ -0,0 +1,55 @@ +package encodings + +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 TransformsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Transform +} + +// TransformsUpdate ... +func (c EncodingsClient) TransformsUpdate(ctx context.Context, id TransformId, input Transform) (result TransformsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/media/2022-07-01/encodings/model_aacaudio.go b/resource-manager/media/2022-07-01/encodings/model_aacaudio.go new file mode 100644 index 00000000000..067403385ae --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_aacaudio.go @@ -0,0 +1,45 @@ +package encodings + +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 _ Codec = AacAudio{} + +type AacAudio struct { + Bitrate *int64 `json:"bitrate,omitempty"` + Channels *int64 `json:"channels,omitempty"` + Profile *AacAudioProfile `json:"profile,omitempty"` + SamplingRate *int64 `json:"samplingRate,omitempty"` + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = AacAudio{} + +func (s AacAudio) MarshalJSON() ([]byte, error) { + type wrapper AacAudio + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AacAudio: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AacAudio: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.AacAudio" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AacAudio: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_absolutecliptime.go b/resource-manager/media/2022-07-01/encodings/model_absolutecliptime.go new file mode 100644 index 00000000000..e1e8cedcd10 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_absolutecliptime.go @@ -0,0 +1,41 @@ +package encodings + +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 _ ClipTime = AbsoluteClipTime{} + +type AbsoluteClipTime struct { + Time string `json:"time"` + + // Fields inherited from ClipTime +} + +var _ json.Marshaler = AbsoluteClipTime{} + +func (s AbsoluteClipTime) MarshalJSON() ([]byte, error) { + type wrapper AbsoluteClipTime + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AbsoluteClipTime: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AbsoluteClipTime: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.AbsoluteClipTime" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AbsoluteClipTime: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_audio.go b/resource-manager/media/2022-07-01/encodings/model_audio.go new file mode 100644 index 00000000000..a2007b0056c --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_audio.go @@ -0,0 +1,44 @@ +package encodings + +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 _ Codec = Audio{} + +type Audio struct { + Bitrate *int64 `json:"bitrate,omitempty"` + Channels *int64 `json:"channels,omitempty"` + SamplingRate *int64 `json:"samplingRate,omitempty"` + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = Audio{} + +func (s Audio) MarshalJSON() ([]byte, error) { + type wrapper Audio + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling Audio: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling Audio: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.Audio" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling Audio: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_audioanalyzerpreset.go b/resource-manager/media/2022-07-01/encodings/model_audioanalyzerpreset.go new file mode 100644 index 00000000000..45a7be9a1c1 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_audioanalyzerpreset.go @@ -0,0 +1,43 @@ +package encodings + +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 _ Preset = AudioAnalyzerPreset{} + +type AudioAnalyzerPreset struct { + AudioLanguage *string `json:"audioLanguage,omitempty"` + ExperimentalOptions *map[string]string `json:"experimentalOptions,omitempty"` + Mode *AudioAnalysisMode `json:"mode,omitempty"` + + // Fields inherited from Preset +} + +var _ json.Marshaler = AudioAnalyzerPreset{} + +func (s AudioAnalyzerPreset) MarshalJSON() ([]byte, error) { + type wrapper AudioAnalyzerPreset + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AudioAnalyzerPreset: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AudioAnalyzerPreset: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.AudioAnalyzerPreset" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AudioAnalyzerPreset: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_audiooverlay.go b/resource-manager/media/2022-07-01/encodings/model_audiooverlay.go new file mode 100644 index 00000000000..3d21e6aeb17 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_audiooverlay.go @@ -0,0 +1,46 @@ +package encodings + +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 _ Overlay = AudioOverlay{} + +type AudioOverlay struct { + + // Fields inherited from Overlay + AudioGainLevel *float64 `json:"audioGainLevel,omitempty"` + End *string `json:"end,omitempty"` + FadeInDuration *string `json:"fadeInDuration,omitempty"` + FadeOutDuration *string `json:"fadeOutDuration,omitempty"` + InputLabel string `json:"inputLabel"` + Start *string `json:"start,omitempty"` +} + +var _ json.Marshaler = AudioOverlay{} + +func (s AudioOverlay) MarshalJSON() ([]byte, error) { + type wrapper AudioOverlay + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AudioOverlay: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AudioOverlay: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.AudioOverlay" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AudioOverlay: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_audiotrackdescriptor.go b/resource-manager/media/2022-07-01/encodings/model_audiotrackdescriptor.go new file mode 100644 index 00000000000..81990a6d7d2 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_audiotrackdescriptor.go @@ -0,0 +1,41 @@ +package encodings + +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 _ TrackDescriptor = AudioTrackDescriptor{} + +type AudioTrackDescriptor struct { + ChannelMapping *ChannelMapping `json:"channelMapping,omitempty"` + + // Fields inherited from TrackDescriptor +} + +var _ json.Marshaler = AudioTrackDescriptor{} + +func (s AudioTrackDescriptor) MarshalJSON() ([]byte, error) { + type wrapper AudioTrackDescriptor + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AudioTrackDescriptor: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AudioTrackDescriptor: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.AudioTrackDescriptor" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AudioTrackDescriptor: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_builtinstandardencoderpreset.go b/resource-manager/media/2022-07-01/encodings/model_builtinstandardencoderpreset.go new file mode 100644 index 00000000000..a11bfb0f219 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_builtinstandardencoderpreset.go @@ -0,0 +1,42 @@ +package encodings + +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 _ Preset = BuiltInStandardEncoderPreset{} + +type BuiltInStandardEncoderPreset struct { + Configurations *PresetConfigurations `json:"configurations,omitempty"` + PresetName EncoderNamedPreset `json:"presetName"` + + // Fields inherited from Preset +} + +var _ json.Marshaler = BuiltInStandardEncoderPreset{} + +func (s BuiltInStandardEncoderPreset) MarshalJSON() ([]byte, error) { + type wrapper BuiltInStandardEncoderPreset + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BuiltInStandardEncoderPreset: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BuiltInStandardEncoderPreset: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.BuiltInStandardEncoderPreset" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BuiltInStandardEncoderPreset: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_cliptime.go b/resource-manager/media/2022-07-01/encodings/model_cliptime.go new file mode 100644 index 00000000000..603c023e1fe --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_cliptime.go @@ -0,0 +1,56 @@ +package encodings + +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 ClipTime interface { +} + +func unmarshalClipTimeImplementation(input []byte) (ClipTime, 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 ClipTime into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.AbsoluteClipTime") { + var out AbsoluteClipTime + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AbsoluteClipTime: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.UtcClipTime") { + var out UtcClipTime + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UtcClipTime: %+v", err) + } + return out, nil + } + + type RawClipTimeImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawClipTimeImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_codec.go b/resource-manager/media/2022-07-01/encodings/model_codec.go new file mode 100644 index 00000000000..670cbda06bb --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_codec.go @@ -0,0 +1,112 @@ +package encodings + +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 Codec interface { +} + +func unmarshalCodecImplementation(input []byte) (Codec, 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 Codec into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.AacAudio") { + var out AacAudio + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AacAudio: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.Audio") { + var out Audio + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into Audio: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.CopyAudio") { + var out CopyAudio + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CopyAudio: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.CopyVideo") { + var out CopyVideo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CopyVideo: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.DDAudio") { + var out DDAudio + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DDAudio: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.H264Video") { + var out H264Video + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into H264Video: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.H265Video") { + var out H265Video + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into H265Video: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.Image") { + var out Image + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into Image: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.Video") { + var out Video + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into Video: %+v", err) + } + return out, nil + } + + type RawCodecImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawCodecImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_copyaudio.go b/resource-manager/media/2022-07-01/encodings/model_copyaudio.go new file mode 100644 index 00000000000..5d1be89597e --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_copyaudio.go @@ -0,0 +1,41 @@ +package encodings + +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 _ Codec = CopyAudio{} + +type CopyAudio struct { + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = CopyAudio{} + +func (s CopyAudio) MarshalJSON() ([]byte, error) { + type wrapper CopyAudio + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CopyAudio: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CopyAudio: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.CopyAudio" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CopyAudio: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_copyvideo.go b/resource-manager/media/2022-07-01/encodings/model_copyvideo.go new file mode 100644 index 00000000000..5f663b6d2bf --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_copyvideo.go @@ -0,0 +1,41 @@ +package encodings + +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 _ Codec = CopyVideo{} + +type CopyVideo struct { + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = CopyVideo{} + +func (s CopyVideo) MarshalJSON() ([]byte, error) { + type wrapper CopyVideo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CopyVideo: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CopyVideo: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.CopyVideo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CopyVideo: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_ddaudio.go b/resource-manager/media/2022-07-01/encodings/model_ddaudio.go new file mode 100644 index 00000000000..aac613abee8 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_ddaudio.go @@ -0,0 +1,44 @@ +package encodings + +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 _ Codec = DDAudio{} + +type DDAudio struct { + Bitrate *int64 `json:"bitrate,omitempty"` + Channels *int64 `json:"channels,omitempty"` + SamplingRate *int64 `json:"samplingRate,omitempty"` + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = DDAudio{} + +func (s DDAudio) MarshalJSON() ([]byte, error) { + type wrapper DDAudio + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DDAudio: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DDAudio: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.DDAudio" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DDAudio: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_deinterlace.go b/resource-manager/media/2022-07-01/encodings/model_deinterlace.go new file mode 100644 index 00000000000..e32750ed4a7 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_deinterlace.go @@ -0,0 +1,9 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Deinterlace struct { + Mode *DeinterlaceMode `json:"mode,omitempty"` + Parity *DeinterlaceParity `json:"parity,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_facedetectorpreset.go b/resource-manager/media/2022-07-01/encodings/model_facedetectorpreset.go new file mode 100644 index 00000000000..b6b9b66de46 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_facedetectorpreset.go @@ -0,0 +1,44 @@ +package encodings + +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 _ Preset = FaceDetectorPreset{} + +type FaceDetectorPreset struct { + BlurType *BlurType `json:"blurType,omitempty"` + ExperimentalOptions *map[string]string `json:"experimentalOptions,omitempty"` + Mode *FaceRedactorMode `json:"mode,omitempty"` + Resolution *AnalysisResolution `json:"resolution,omitempty"` + + // Fields inherited from Preset +} + +var _ json.Marshaler = FaceDetectorPreset{} + +func (s FaceDetectorPreset) MarshalJSON() ([]byte, error) { + type wrapper FaceDetectorPreset + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FaceDetectorPreset: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FaceDetectorPreset: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.FaceDetectorPreset" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FaceDetectorPreset: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_fade.go b/resource-manager/media/2022-07-01/encodings/model_fade.go new file mode 100644 index 00000000000..9108869895d --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_fade.go @@ -0,0 +1,10 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Fade struct { + Duration string `json:"duration"` + FadeColor string `json:"fadeColor"` + Start *string `json:"start,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_filters.go b/resource-manager/media/2022-07-01/encodings/model_filters.go new file mode 100644 index 00000000000..fb55f7a8267 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_filters.go @@ -0,0 +1,57 @@ +package encodings + +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 Filters struct { + Crop *Rectangle `json:"crop,omitempty"` + Deinterlace *Deinterlace `json:"deinterlace,omitempty"` + FadeIn *Fade `json:"fadeIn,omitempty"` + FadeOut *Fade `json:"fadeOut,omitempty"` + Overlays *[]Overlay `json:"overlays,omitempty"` + Rotation *Rotation `json:"rotation,omitempty"` +} + +var _ json.Unmarshaler = &Filters{} + +func (s *Filters) UnmarshalJSON(bytes []byte) error { + type alias Filters + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into Filters: %+v", err) + } + + s.Crop = decoded.Crop + s.Deinterlace = decoded.Deinterlace + s.FadeIn = decoded.FadeIn + s.FadeOut = decoded.FadeOut + s.Rotation = decoded.Rotation + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling Filters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["overlays"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Overlays into list []json.RawMessage: %+v", err) + } + + output := make([]Overlay, 0) + for i, val := range listTemp { + impl, err := unmarshalOverlayImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Overlays' for 'Filters': %+v", i, err) + } + output = append(output, impl) + } + s.Overlays = &output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_format.go b/resource-manager/media/2022-07-01/encodings/model_format.go new file mode 100644 index 00000000000..bc756a0bb28 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_format.go @@ -0,0 +1,88 @@ +package encodings + +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 Format interface { +} + +func unmarshalFormatImplementation(input []byte) (Format, 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 Format into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.ImageFormat") { + var out ImageFormat + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ImageFormat: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.JpgFormat") { + var out JpgFormat + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JpgFormat: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.Mp4Format") { + var out Mp4Format + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into Mp4Format: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.MultiBitrateFormat") { + var out MultiBitrateFormat + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MultiBitrateFormat: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.PngFormat") { + var out PngFormat + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PngFormat: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.TransportStreamFormat") { + var out TransportStreamFormat + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into TransportStreamFormat: %+v", err) + } + return out, nil + } + + type RawFormatImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawFormatImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_fromallinputfile.go b/resource-manager/media/2022-07-01/encodings/model_fromallinputfile.go new file mode 100644 index 00000000000..c1a7d3860e4 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_fromallinputfile.go @@ -0,0 +1,69 @@ +package encodings + +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 _ InputDefinition = FromAllInputFile{} + +type FromAllInputFile struct { + + // Fields inherited from InputDefinition + IncludedTracks *[]TrackDescriptor `json:"includedTracks,omitempty"` +} + +var _ json.Marshaler = FromAllInputFile{} + +func (s FromAllInputFile) MarshalJSON() ([]byte, error) { + type wrapper FromAllInputFile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FromAllInputFile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FromAllInputFile: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.FromAllInputFile" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FromAllInputFile: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &FromAllInputFile{} + +func (s *FromAllInputFile) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling FromAllInputFile into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["includedTracks"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling IncludedTracks into list []json.RawMessage: %+v", err) + } + + output := make([]TrackDescriptor, 0) + for i, val := range listTemp { + impl, err := unmarshalTrackDescriptorImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'IncludedTracks' for 'FromAllInputFile': %+v", i, err) + } + output = append(output, impl) + } + s.IncludedTracks = &output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_fromeachinputfile.go b/resource-manager/media/2022-07-01/encodings/model_fromeachinputfile.go new file mode 100644 index 00000000000..02137a86e8a --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_fromeachinputfile.go @@ -0,0 +1,69 @@ +package encodings + +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 _ InputDefinition = FromEachInputFile{} + +type FromEachInputFile struct { + + // Fields inherited from InputDefinition + IncludedTracks *[]TrackDescriptor `json:"includedTracks,omitempty"` +} + +var _ json.Marshaler = FromEachInputFile{} + +func (s FromEachInputFile) MarshalJSON() ([]byte, error) { + type wrapper FromEachInputFile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FromEachInputFile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FromEachInputFile: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.FromEachInputFile" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FromEachInputFile: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &FromEachInputFile{} + +func (s *FromEachInputFile) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling FromEachInputFile into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["includedTracks"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling IncludedTracks into list []json.RawMessage: %+v", err) + } + + output := make([]TrackDescriptor, 0) + for i, val := range listTemp { + impl, err := unmarshalTrackDescriptorImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'IncludedTracks' for 'FromEachInputFile': %+v", i, err) + } + output = append(output, impl) + } + s.IncludedTracks = &output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_h264layer.go b/resource-manager/media/2022-07-01/encodings/model_h264layer.go new file mode 100644 index 00000000000..6320f6b1b41 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_h264layer.go @@ -0,0 +1,22 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type H264Layer struct { + AdaptiveBFrame *bool `json:"adaptiveBFrame,omitempty"` + BFrames *int64 `json:"bFrames,omitempty"` + Bitrate int64 `json:"bitrate"` + BufferWindow *string `json:"bufferWindow,omitempty"` + Crf *float64 `json:"crf,omitempty"` + EntropyMode *EntropyMode `json:"entropyMode,omitempty"` + FrameRate *string `json:"frameRate,omitempty"` + Height *string `json:"height,omitempty"` + Label *string `json:"label,omitempty"` + Level *string `json:"level,omitempty"` + MaxBitrate *int64 `json:"maxBitrate,omitempty"` + Profile *H264VideoProfile `json:"profile,omitempty"` + ReferenceFrames *int64 `json:"referenceFrames,omitempty"` + Slices *int64 `json:"slices,omitempty"` + Width *string `json:"width,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_h264video.go b/resource-manager/media/2022-07-01/encodings/model_h264video.go new file mode 100644 index 00000000000..fbcd311e539 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_h264video.go @@ -0,0 +1,48 @@ +package encodings + +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 _ Codec = H264Video{} + +type H264Video struct { + Complexity *H264Complexity `json:"complexity,omitempty"` + KeyFrameInterval *string `json:"keyFrameInterval,omitempty"` + Layers *[]H264Layer `json:"layers,omitempty"` + RateControlMode *H264RateControlMode `json:"rateControlMode,omitempty"` + SceneChangeDetection *bool `json:"sceneChangeDetection,omitempty"` + StretchMode *StretchMode `json:"stretchMode,omitempty"` + SyncMode *VideoSyncMode `json:"syncMode,omitempty"` + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = H264Video{} + +func (s H264Video) MarshalJSON() ([]byte, error) { + type wrapper H264Video + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling H264Video: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling H264Video: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.H264Video" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling H264Video: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_h265layer.go b/resource-manager/media/2022-07-01/encodings/model_h265layer.go new file mode 100644 index 00000000000..1580e51ffca --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_h265layer.go @@ -0,0 +1,21 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type H265Layer struct { + AdaptiveBFrame *bool `json:"adaptiveBFrame,omitempty"` + BFrames *int64 `json:"bFrames,omitempty"` + Bitrate int64 `json:"bitrate"` + BufferWindow *string `json:"bufferWindow,omitempty"` + Crf *float64 `json:"crf,omitempty"` + FrameRate *string `json:"frameRate,omitempty"` + Height *string `json:"height,omitempty"` + Label *string `json:"label,omitempty"` + Level *string `json:"level,omitempty"` + MaxBitrate *int64 `json:"maxBitrate,omitempty"` + Profile *H265VideoProfile `json:"profile,omitempty"` + ReferenceFrames *int64 `json:"referenceFrames,omitempty"` + Slices *int64 `json:"slices,omitempty"` + Width *string `json:"width,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_h265video.go b/resource-manager/media/2022-07-01/encodings/model_h265video.go new file mode 100644 index 00000000000..9edadac194a --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_h265video.go @@ -0,0 +1,47 @@ +package encodings + +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 _ Codec = H265Video{} + +type H265Video struct { + Complexity *H265Complexity `json:"complexity,omitempty"` + KeyFrameInterval *string `json:"keyFrameInterval,omitempty"` + Layers *[]H265Layer `json:"layers,omitempty"` + SceneChangeDetection *bool `json:"sceneChangeDetection,omitempty"` + StretchMode *StretchMode `json:"stretchMode,omitempty"` + SyncMode *VideoSyncMode `json:"syncMode,omitempty"` + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = H265Video{} + +func (s H265Video) MarshalJSON() ([]byte, error) { + type wrapper H265Video + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling H265Video: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling H265Video: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.H265Video" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling H265Video: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_image.go b/resource-manager/media/2022-07-01/encodings/model_image.go new file mode 100644 index 00000000000..072a1a7537e --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_image.go @@ -0,0 +1,47 @@ +package encodings + +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 _ Codec = Image{} + +type Image struct { + KeyFrameInterval *string `json:"keyFrameInterval,omitempty"` + Range *string `json:"range,omitempty"` + Start string `json:"start"` + Step *string `json:"step,omitempty"` + StretchMode *StretchMode `json:"stretchMode,omitempty"` + SyncMode *VideoSyncMode `json:"syncMode,omitempty"` + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = Image{} + +func (s Image) MarshalJSON() ([]byte, error) { + type wrapper Image + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling Image: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling Image: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.Image" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling Image: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_imageformat.go b/resource-manager/media/2022-07-01/encodings/model_imageformat.go new file mode 100644 index 00000000000..0e390a0c6f3 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_imageformat.go @@ -0,0 +1,41 @@ +package encodings + +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 _ Format = ImageFormat{} + +type ImageFormat struct { + + // Fields inherited from Format + FilenamePattern string `json:"filenamePattern"` +} + +var _ json.Marshaler = ImageFormat{} + +func (s ImageFormat) MarshalJSON() ([]byte, error) { + type wrapper ImageFormat + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ImageFormat: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ImageFormat: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.ImageFormat" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ImageFormat: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_inputdefinition.go b/resource-manager/media/2022-07-01/encodings/model_inputdefinition.go new file mode 100644 index 00000000000..bf5faf47a4c --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_inputdefinition.go @@ -0,0 +1,64 @@ +package encodings + +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 InputDefinition interface { +} + +func unmarshalInputDefinitionImplementation(input []byte) (InputDefinition, 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 InputDefinition into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.FromAllInputFile") { + var out FromAllInputFile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FromAllInputFile: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.FromEachInputFile") { + var out FromEachInputFile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FromEachInputFile: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.InputFile") { + var out InputFile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InputFile: %+v", err) + } + return out, nil + } + + type RawInputDefinitionImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawInputDefinitionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_inputfile.go b/resource-manager/media/2022-07-01/encodings/model_inputfile.go new file mode 100644 index 00000000000..4c3f11b6d7f --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_inputfile.go @@ -0,0 +1,77 @@ +package encodings + +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 _ InputDefinition = InputFile{} + +type InputFile struct { + Filename *string `json:"filename,omitempty"` + + // Fields inherited from InputDefinition + IncludedTracks *[]TrackDescriptor `json:"includedTracks,omitempty"` +} + +var _ json.Marshaler = InputFile{} + +func (s InputFile) MarshalJSON() ([]byte, error) { + type wrapper InputFile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InputFile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InputFile: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.InputFile" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InputFile: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &InputFile{} + +func (s *InputFile) UnmarshalJSON(bytes []byte) error { + type alias InputFile + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into InputFile: %+v", err) + } + + s.Filename = decoded.Filename + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling InputFile into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["includedTracks"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling IncludedTracks into list []json.RawMessage: %+v", err) + } + + output := make([]TrackDescriptor, 0) + for i, val := range listTemp { + impl, err := unmarshalTrackDescriptorImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'IncludedTracks' for 'InputFile': %+v", i, err) + } + output = append(output, impl) + } + s.IncludedTracks = &output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_job.go b/resource-manager/media/2022-07-01/encodings/model_job.go new file mode 100644 index 00000000000..db973712dda --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_job.go @@ -0,0 +1,16 @@ +package encodings + +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 Job struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_joberror.go b/resource-manager/media/2022-07-01/encodings/model_joberror.go new file mode 100644 index 00000000000..c14b785a690 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_joberror.go @@ -0,0 +1,12 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobError struct { + Category *JobErrorCategory `json:"category,omitempty"` + Code *JobErrorCode `json:"code,omitempty"` + Details *[]JobErrorDetail `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Retry *JobRetry `json:"retry,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_joberrordetail.go b/resource-manager/media/2022-07-01/encodings/model_joberrordetail.go new file mode 100644 index 00000000000..80595e90276 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_joberrordetail.go @@ -0,0 +1,9 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jobinput.go b/resource-manager/media/2022-07-01/encodings/model_jobinput.go new file mode 100644 index 00000000000..e44a0cf5249 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jobinput.go @@ -0,0 +1,80 @@ +package encodings + +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 JobInput interface { +} + +func unmarshalJobInputImplementation(input []byte) (JobInput, 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 JobInput into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.JobInputAsset") { + var out JobInputAsset + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobInputAsset: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.JobInputClip") { + var out JobInputClip + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobInputClip: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.JobInputHttp") { + var out JobInputHTTP + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobInputHTTP: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.JobInputSequence") { + var out JobInputSequence + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobInputSequence: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.JobInputs") { + var out JobInputs + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobInputs: %+v", err) + } + return out, nil + } + + type RawJobInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawJobInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jobinputasset.go b/resource-manager/media/2022-07-01/encodings/model_jobinputasset.go new file mode 100644 index 00000000000..689f8282884 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jobinputasset.go @@ -0,0 +1,99 @@ +package encodings + +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 _ JobInput = JobInputAsset{} + +type JobInputAsset struct { + AssetName string `json:"assetName"` + End ClipTime `json:"end"` + Files *[]string `json:"files,omitempty"` + InputDefinitions *[]InputDefinition `json:"inputDefinitions,omitempty"` + Label *string `json:"label,omitempty"` + Start ClipTime `json:"start"` + + // Fields inherited from JobInput +} + +var _ json.Marshaler = JobInputAsset{} + +func (s JobInputAsset) MarshalJSON() ([]byte, error) { + type wrapper JobInputAsset + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobInputAsset: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobInputAsset: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.JobInputAsset" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobInputAsset: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &JobInputAsset{} + +func (s *JobInputAsset) UnmarshalJSON(bytes []byte) error { + type alias JobInputAsset + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobInputAsset: %+v", err) + } + + s.AssetName = decoded.AssetName + s.Files = decoded.Files + s.Label = decoded.Label + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobInputAsset into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["end"]; ok { + impl, err := unmarshalClipTimeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'End' for 'JobInputAsset': %+v", err) + } + s.End = impl + } + + if v, ok := temp["inputDefinitions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling InputDefinitions into list []json.RawMessage: %+v", err) + } + + output := make([]InputDefinition, 0) + for i, val := range listTemp { + impl, err := unmarshalInputDefinitionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'InputDefinitions' for 'JobInputAsset': %+v", i, err) + } + output = append(output, impl) + } + s.InputDefinitions = &output + } + + if v, ok := temp["start"]; ok { + impl, err := unmarshalClipTimeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Start' for 'JobInputAsset': %+v", err) + } + s.Start = impl + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jobinputclip.go b/resource-manager/media/2022-07-01/encodings/model_jobinputclip.go new file mode 100644 index 00000000000..5136c539d5b --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jobinputclip.go @@ -0,0 +1,97 @@ +package encodings + +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 _ JobInput = JobInputClip{} + +type JobInputClip struct { + End ClipTime `json:"end"` + Files *[]string `json:"files,omitempty"` + InputDefinitions *[]InputDefinition `json:"inputDefinitions,omitempty"` + Label *string `json:"label,omitempty"` + Start ClipTime `json:"start"` + + // Fields inherited from JobInput +} + +var _ json.Marshaler = JobInputClip{} + +func (s JobInputClip) MarshalJSON() ([]byte, error) { + type wrapper JobInputClip + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobInputClip: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobInputClip: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.JobInputClip" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobInputClip: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &JobInputClip{} + +func (s *JobInputClip) UnmarshalJSON(bytes []byte) error { + type alias JobInputClip + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobInputClip: %+v", err) + } + + s.Files = decoded.Files + s.Label = decoded.Label + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobInputClip into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["end"]; ok { + impl, err := unmarshalClipTimeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'End' for 'JobInputClip': %+v", err) + } + s.End = impl + } + + if v, ok := temp["inputDefinitions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling InputDefinitions into list []json.RawMessage: %+v", err) + } + + output := make([]InputDefinition, 0) + for i, val := range listTemp { + impl, err := unmarshalInputDefinitionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'InputDefinitions' for 'JobInputClip': %+v", i, err) + } + output = append(output, impl) + } + s.InputDefinitions = &output + } + + if v, ok := temp["start"]; ok { + impl, err := unmarshalClipTimeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Start' for 'JobInputClip': %+v", err) + } + s.Start = impl + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jobinputhttp.go b/resource-manager/media/2022-07-01/encodings/model_jobinputhttp.go new file mode 100644 index 00000000000..57beddd3fde --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jobinputhttp.go @@ -0,0 +1,99 @@ +package encodings + +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 _ JobInput = JobInputHTTP{} + +type JobInputHTTP struct { + BaseUri *string `json:"baseUri,omitempty"` + End ClipTime `json:"end"` + Files *[]string `json:"files,omitempty"` + InputDefinitions *[]InputDefinition `json:"inputDefinitions,omitempty"` + Label *string `json:"label,omitempty"` + Start ClipTime `json:"start"` + + // Fields inherited from JobInput +} + +var _ json.Marshaler = JobInputHTTP{} + +func (s JobInputHTTP) MarshalJSON() ([]byte, error) { + type wrapper JobInputHTTP + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobInputHTTP: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobInputHTTP: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.JobInputHttp" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobInputHTTP: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &JobInputHTTP{} + +func (s *JobInputHTTP) UnmarshalJSON(bytes []byte) error { + type alias JobInputHTTP + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobInputHTTP: %+v", err) + } + + s.BaseUri = decoded.BaseUri + s.Files = decoded.Files + s.Label = decoded.Label + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobInputHTTP into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["end"]; ok { + impl, err := unmarshalClipTimeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'End' for 'JobInputHTTP': %+v", err) + } + s.End = impl + } + + if v, ok := temp["inputDefinitions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling InputDefinitions into list []json.RawMessage: %+v", err) + } + + output := make([]InputDefinition, 0) + for i, val := range listTemp { + impl, err := unmarshalInputDefinitionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'InputDefinitions' for 'JobInputHTTP': %+v", i, err) + } + output = append(output, impl) + } + s.InputDefinitions = &output + } + + if v, ok := temp["start"]; ok { + impl, err := unmarshalClipTimeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Start' for 'JobInputHTTP': %+v", err) + } + s.Start = impl + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jobinputs.go b/resource-manager/media/2022-07-01/encodings/model_jobinputs.go new file mode 100644 index 00000000000..b63a141b6e0 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jobinputs.go @@ -0,0 +1,69 @@ +package encodings + +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 _ JobInput = JobInputs{} + +type JobInputs struct { + Inputs *[]JobInput `json:"inputs,omitempty"` + + // Fields inherited from JobInput +} + +var _ json.Marshaler = JobInputs{} + +func (s JobInputs) MarshalJSON() ([]byte, error) { + type wrapper JobInputs + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobInputs: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobInputs: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.JobInputs" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobInputs: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &JobInputs{} + +func (s *JobInputs) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobInputs into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["inputs"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Inputs into list []json.RawMessage: %+v", err) + } + + output := make([]JobInput, 0) + for i, val := range listTemp { + impl, err := unmarshalJobInputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Inputs' for 'JobInputs': %+v", i, err) + } + output = append(output, impl) + } + s.Inputs = &output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jobinputsequence.go b/resource-manager/media/2022-07-01/encodings/model_jobinputsequence.go new file mode 100644 index 00000000000..1d87ba0ce47 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jobinputsequence.go @@ -0,0 +1,69 @@ +package encodings + +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 _ JobInput = JobInputSequence{} + +type JobInputSequence struct { + Inputs *[]JobInput `json:"inputs,omitempty"` + + // Fields inherited from JobInput +} + +var _ json.Marshaler = JobInputSequence{} + +func (s JobInputSequence) MarshalJSON() ([]byte, error) { + type wrapper JobInputSequence + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobInputSequence: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobInputSequence: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.JobInputSequence" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobInputSequence: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &JobInputSequence{} + +func (s *JobInputSequence) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobInputSequence into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["inputs"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Inputs into list []json.RawMessage: %+v", err) + } + + output := make([]JobInput, 0) + for i, val := range listTemp { + impl, err := unmarshalJobInputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Inputs' for 'JobInputSequence': %+v", i, err) + } + output = append(output, impl) + } + s.Inputs = &output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_joboutput.go b/resource-manager/media/2022-07-01/encodings/model_joboutput.go new file mode 100644 index 00000000000..39bd27d3041 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_joboutput.go @@ -0,0 +1,48 @@ +package encodings + +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 JobOutput interface { +} + +func unmarshalJobOutputImplementation(input []byte) (JobOutput, 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 JobOutput into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.JobOutputAsset") { + var out JobOutputAsset + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobOutputAsset: %+v", err) + } + return out, nil + } + + type RawJobOutputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawJobOutputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_joboutputasset.go b/resource-manager/media/2022-07-01/encodings/model_joboutputasset.go new file mode 100644 index 00000000000..ed0aa4672cc --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_joboutputasset.go @@ -0,0 +1,107 @@ +package encodings + +import ( + "encoding/json" + "fmt" + "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. + +var _ JobOutput = JobOutputAsset{} + +type JobOutputAsset struct { + AssetName string `json:"assetName"` + + // Fields inherited from JobOutput + EndTime *string `json:"endTime,omitempty"` + Error *JobError `json:"error,omitempty"` + Label *string `json:"label,omitempty"` + PresetOverride Preset `json:"presetOverride"` + Progress *int64 `json:"progress,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *JobState `json:"state,omitempty"` +} + +func (o *JobOutputAsset) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobOutputAsset) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobOutputAsset) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobOutputAsset) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = JobOutputAsset{} + +func (s JobOutputAsset) MarshalJSON() ([]byte, error) { + type wrapper JobOutputAsset + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobOutputAsset: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobOutputAsset: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.JobOutputAsset" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobOutputAsset: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &JobOutputAsset{} + +func (s *JobOutputAsset) UnmarshalJSON(bytes []byte) error { + type alias JobOutputAsset + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobOutputAsset: %+v", err) + } + + s.AssetName = decoded.AssetName + s.EndTime = decoded.EndTime + s.Error = decoded.Error + s.Label = decoded.Label + s.Progress = decoded.Progress + s.StartTime = decoded.StartTime + s.State = decoded.State + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobOutputAsset into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["presetOverride"]; ok { + impl, err := unmarshalPresetImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'PresetOverride' for 'JobOutputAsset': %+v", err) + } + s.PresetOverride = impl + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jobproperties.go b/resource-manager/media/2022-07-01/encodings/model_jobproperties.go new file mode 100644 index 00000000000..d1d9fcd58d5 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jobproperties.go @@ -0,0 +1,123 @@ +package encodings + +import ( + "encoding/json" + "fmt" + "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 JobProperties struct { + CorrelationData *map[string]string `json:"correlationData,omitempty"` + Created *string `json:"created,omitempty"` + Description *string `json:"description,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Input JobInput `json:"input"` + LastModified *string `json:"lastModified,omitempty"` + Outputs []JobOutput `json:"outputs"` + Priority *Priority `json:"priority,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *JobState `json:"state,omitempty"` +} + +func (o *JobProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *JobProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobProperties) GetLastModifiedAsTime() (*time.Time, error) { + if o.LastModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobProperties) SetLastModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModified = &formatted +} + +func (o *JobProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Unmarshaler = &JobProperties{} + +func (s *JobProperties) UnmarshalJSON(bytes []byte) error { + type alias JobProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobProperties: %+v", err) + } + + s.CorrelationData = decoded.CorrelationData + s.Created = decoded.Created + s.Description = decoded.Description + s.EndTime = decoded.EndTime + s.LastModified = decoded.LastModified + s.Priority = decoded.Priority + s.StartTime = decoded.StartTime + s.State = decoded.State + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["input"]; ok { + impl, err := unmarshalJobInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Input' for 'JobProperties': %+v", err) + } + s.Input = impl + } + + if v, ok := temp["outputs"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Outputs into list []json.RawMessage: %+v", err) + } + + output := make([]JobOutput, 0) + for i, val := range listTemp { + impl, err := unmarshalJobOutputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Outputs' for 'JobProperties': %+v", i, err) + } + output = append(output, impl) + } + s.Outputs = output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_jpgformat.go b/resource-manager/media/2022-07-01/encodings/model_jpgformat.go new file mode 100644 index 00000000000..de3e7aba6df --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_jpgformat.go @@ -0,0 +1,41 @@ +package encodings + +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 _ Format = JpgFormat{} + +type JpgFormat struct { + + // Fields inherited from Format + FilenamePattern string `json:"filenamePattern"` +} + +var _ json.Marshaler = JpgFormat{} + +func (s JpgFormat) MarshalJSON() ([]byte, error) { + type wrapper JpgFormat + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JpgFormat: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JpgFormat: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.JpgFormat" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JpgFormat: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_mp4format.go b/resource-manager/media/2022-07-01/encodings/model_mp4format.go new file mode 100644 index 00000000000..44e41dd9492 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_mp4format.go @@ -0,0 +1,42 @@ +package encodings + +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 _ Format = Mp4Format{} + +type Mp4Format struct { + OutputFiles *[]OutputFile `json:"outputFiles,omitempty"` + + // Fields inherited from Format + FilenamePattern string `json:"filenamePattern"` +} + +var _ json.Marshaler = Mp4Format{} + +func (s Mp4Format) MarshalJSON() ([]byte, error) { + type wrapper Mp4Format + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling Mp4Format: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling Mp4Format: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.Mp4Format" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling Mp4Format: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_multibitrateformat.go b/resource-manager/media/2022-07-01/encodings/model_multibitrateformat.go new file mode 100644 index 00000000000..fec53d0e680 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_multibitrateformat.go @@ -0,0 +1,42 @@ +package encodings + +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 _ Format = MultiBitrateFormat{} + +type MultiBitrateFormat struct { + OutputFiles *[]OutputFile `json:"outputFiles,omitempty"` + + // Fields inherited from Format + FilenamePattern string `json:"filenamePattern"` +} + +var _ json.Marshaler = MultiBitrateFormat{} + +func (s MultiBitrateFormat) MarshalJSON() ([]byte, error) { + type wrapper MultiBitrateFormat + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MultiBitrateFormat: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MultiBitrateFormat: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.MultiBitrateFormat" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MultiBitrateFormat: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_outputfile.go b/resource-manager/media/2022-07-01/encodings/model_outputfile.go new file mode 100644 index 00000000000..e83b5bdb27f --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_outputfile.go @@ -0,0 +1,8 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutputFile struct { + Labels []string `json:"labels"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_overlay.go b/resource-manager/media/2022-07-01/encodings/model_overlay.go new file mode 100644 index 00000000000..0b3ec59cc8a --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_overlay.go @@ -0,0 +1,56 @@ +package encodings + +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 Overlay interface { +} + +func unmarshalOverlayImplementation(input []byte) (Overlay, 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 Overlay into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.AudioOverlay") { + var out AudioOverlay + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AudioOverlay: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.VideoOverlay") { + var out VideoOverlay + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VideoOverlay: %+v", err) + } + return out, nil + } + + type RawOverlayImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawOverlayImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_pngformat.go b/resource-manager/media/2022-07-01/encodings/model_pngformat.go new file mode 100644 index 00000000000..e9b5216bb86 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_pngformat.go @@ -0,0 +1,41 @@ +package encodings + +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 _ Format = PngFormat{} + +type PngFormat struct { + + // Fields inherited from Format + FilenamePattern string `json:"filenamePattern"` +} + +var _ json.Marshaler = PngFormat{} + +func (s PngFormat) MarshalJSON() ([]byte, error) { + type wrapper PngFormat + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PngFormat: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PngFormat: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.PngFormat" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PngFormat: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_preset.go b/resource-manager/media/2022-07-01/encodings/model_preset.go new file mode 100644 index 00000000000..dd860f8e981 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_preset.go @@ -0,0 +1,80 @@ +package encodings + +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 Preset interface { +} + +func unmarshalPresetImplementation(input []byte) (Preset, 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 Preset into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.AudioAnalyzerPreset") { + var out AudioAnalyzerPreset + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AudioAnalyzerPreset: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.BuiltInStandardEncoderPreset") { + var out BuiltInStandardEncoderPreset + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BuiltInStandardEncoderPreset: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.FaceDetectorPreset") { + var out FaceDetectorPreset + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FaceDetectorPreset: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.StandardEncoderPreset") { + var out StandardEncoderPreset + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StandardEncoderPreset: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.VideoAnalyzerPreset") { + var out VideoAnalyzerPreset + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VideoAnalyzerPreset: %+v", err) + } + return out, nil + } + + type RawPresetImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawPresetImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_presetconfigurations.go b/resource-manager/media/2022-07-01/encodings/model_presetconfigurations.go new file mode 100644 index 00000000000..56262e5ad96 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_presetconfigurations.go @@ -0,0 +1,15 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PresetConfigurations struct { + Complexity *Complexity `json:"complexity,omitempty"` + InterleaveOutput *InterleaveOutput `json:"interleaveOutput,omitempty"` + KeyFrameIntervalInSeconds *float64 `json:"keyFrameIntervalInSeconds,omitempty"` + MaxBitrateBps *int64 `json:"maxBitrateBps,omitempty"` + MaxHeight *int64 `json:"maxHeight,omitempty"` + MaxLayers *int64 `json:"maxLayers,omitempty"` + MinBitrateBps *int64 `json:"minBitrateBps,omitempty"` + MinHeight *int64 `json:"minHeight,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_rectangle.go b/resource-manager/media/2022-07-01/encodings/model_rectangle.go new file mode 100644 index 00000000000..09b1ba538a9 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_rectangle.go @@ -0,0 +1,11 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Rectangle struct { + Height *string `json:"height,omitempty"` + Left *string `json:"left,omitempty"` + Top *string `json:"top,omitempty"` + Width *string `json:"width,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_selectaudiotrackbyattribute.go b/resource-manager/media/2022-07-01/encodings/model_selectaudiotrackbyattribute.go new file mode 100644 index 00000000000..ae6bafef503 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_selectaudiotrackbyattribute.go @@ -0,0 +1,44 @@ +package encodings + +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 _ TrackDescriptor = SelectAudioTrackByAttribute{} + +type SelectAudioTrackByAttribute struct { + Attribute TrackAttribute `json:"attribute"` + ChannelMapping *ChannelMapping `json:"channelMapping,omitempty"` + Filter AttributeFilter `json:"filter"` + FilterValue *string `json:"filterValue,omitempty"` + + // Fields inherited from TrackDescriptor +} + +var _ json.Marshaler = SelectAudioTrackByAttribute{} + +func (s SelectAudioTrackByAttribute) MarshalJSON() ([]byte, error) { + type wrapper SelectAudioTrackByAttribute + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SelectAudioTrackByAttribute: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SelectAudioTrackByAttribute: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.SelectAudioTrackByAttribute" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SelectAudioTrackByAttribute: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_selectaudiotrackbyid.go b/resource-manager/media/2022-07-01/encodings/model_selectaudiotrackbyid.go new file mode 100644 index 00000000000..e9b4587be0c --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_selectaudiotrackbyid.go @@ -0,0 +1,42 @@ +package encodings + +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 _ TrackDescriptor = SelectAudioTrackById{} + +type SelectAudioTrackById struct { + ChannelMapping *ChannelMapping `json:"channelMapping,omitempty"` + TrackId int64 `json:"trackId"` + + // Fields inherited from TrackDescriptor +} + +var _ json.Marshaler = SelectAudioTrackById{} + +func (s SelectAudioTrackById) MarshalJSON() ([]byte, error) { + type wrapper SelectAudioTrackById + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SelectAudioTrackById: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SelectAudioTrackById: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.SelectAudioTrackById" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SelectAudioTrackById: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_selectvideotrackbyattribute.go b/resource-manager/media/2022-07-01/encodings/model_selectvideotrackbyattribute.go new file mode 100644 index 00000000000..82305909c36 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_selectvideotrackbyattribute.go @@ -0,0 +1,43 @@ +package encodings + +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 _ TrackDescriptor = SelectVideoTrackByAttribute{} + +type SelectVideoTrackByAttribute struct { + Attribute TrackAttribute `json:"attribute"` + Filter AttributeFilter `json:"filter"` + FilterValue *string `json:"filterValue,omitempty"` + + // Fields inherited from TrackDescriptor +} + +var _ json.Marshaler = SelectVideoTrackByAttribute{} + +func (s SelectVideoTrackByAttribute) MarshalJSON() ([]byte, error) { + type wrapper SelectVideoTrackByAttribute + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SelectVideoTrackByAttribute: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SelectVideoTrackByAttribute: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.SelectVideoTrackByAttribute" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SelectVideoTrackByAttribute: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_selectvideotrackbyid.go b/resource-manager/media/2022-07-01/encodings/model_selectvideotrackbyid.go new file mode 100644 index 00000000000..4527e73336e --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_selectvideotrackbyid.go @@ -0,0 +1,41 @@ +package encodings + +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 _ TrackDescriptor = SelectVideoTrackById{} + +type SelectVideoTrackById struct { + TrackId int64 `json:"trackId"` + + // Fields inherited from TrackDescriptor +} + +var _ json.Marshaler = SelectVideoTrackById{} + +func (s SelectVideoTrackById) MarshalJSON() ([]byte, error) { + type wrapper SelectVideoTrackById + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SelectVideoTrackById: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SelectVideoTrackById: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.SelectVideoTrackById" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SelectVideoTrackById: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_standardencoderpreset.go b/resource-manager/media/2022-07-01/encodings/model_standardencoderpreset.go new file mode 100644 index 00000000000..e542f813478 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_standardencoderpreset.go @@ -0,0 +1,97 @@ +package encodings + +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 _ Preset = StandardEncoderPreset{} + +type StandardEncoderPreset struct { + Codecs []Codec `json:"codecs"` + ExperimentalOptions *map[string]string `json:"experimentalOptions,omitempty"` + Filters *Filters `json:"filters,omitempty"` + Formats []Format `json:"formats"` + + // Fields inherited from Preset +} + +var _ json.Marshaler = StandardEncoderPreset{} + +func (s StandardEncoderPreset) MarshalJSON() ([]byte, error) { + type wrapper StandardEncoderPreset + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StandardEncoderPreset: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StandardEncoderPreset: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.StandardEncoderPreset" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StandardEncoderPreset: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &StandardEncoderPreset{} + +func (s *StandardEncoderPreset) UnmarshalJSON(bytes []byte) error { + type alias StandardEncoderPreset + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into StandardEncoderPreset: %+v", err) + } + + s.ExperimentalOptions = decoded.ExperimentalOptions + s.Filters = decoded.Filters + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling StandardEncoderPreset into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["codecs"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Codecs into list []json.RawMessage: %+v", err) + } + + output := make([]Codec, 0) + for i, val := range listTemp { + impl, err := unmarshalCodecImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Codecs' for 'StandardEncoderPreset': %+v", i, err) + } + output = append(output, impl) + } + s.Codecs = output + } + + if v, ok := temp["formats"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Formats into list []json.RawMessage: %+v", err) + } + + output := make([]Format, 0) + for i, val := range listTemp { + impl, err := unmarshalFormatImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Formats' for 'StandardEncoderPreset': %+v", i, err) + } + output = append(output, impl) + } + s.Formats = output + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_trackdescriptor.go b/resource-manager/media/2022-07-01/encodings/model_trackdescriptor.go new file mode 100644 index 00000000000..d9a61383ca2 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_trackdescriptor.go @@ -0,0 +1,88 @@ +package encodings + +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 TrackDescriptor interface { +} + +func unmarshalTrackDescriptorImplementation(input []byte) (TrackDescriptor, 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 TrackDescriptor into map[string]interface: %+v", err) + } + + value, ok := temp["@odata.type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.AudioTrackDescriptor") { + var out AudioTrackDescriptor + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AudioTrackDescriptor: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.SelectAudioTrackByAttribute") { + var out SelectAudioTrackByAttribute + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SelectAudioTrackByAttribute: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.SelectAudioTrackById") { + var out SelectAudioTrackById + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SelectAudioTrackById: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.SelectVideoTrackByAttribute") { + var out SelectVideoTrackByAttribute + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SelectVideoTrackByAttribute: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.SelectVideoTrackById") { + var out SelectVideoTrackById + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SelectVideoTrackById: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "#Microsoft.Media.VideoTrackDescriptor") { + var out VideoTrackDescriptor + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VideoTrackDescriptor: %+v", err) + } + return out, nil + } + + type RawTrackDescriptorImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawTrackDescriptorImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/media/2022-07-01/encodings/model_transform.go b/resource-manager/media/2022-07-01/encodings/model_transform.go new file mode 100644 index 00000000000..01cf33e3480 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_transform.go @@ -0,0 +1,16 @@ +package encodings + +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 Transform struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TransformProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/media/2022-07-01/encodings/model_transformoutput.go b/resource-manager/media/2022-07-01/encodings/model_transformoutput.go new file mode 100644 index 00000000000..8532442b750 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_transformoutput.go @@ -0,0 +1,42 @@ +package encodings + +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 TransformOutput struct { + OnError *OnErrorType `json:"onError,omitempty"` + Preset Preset `json:"preset"` + RelativePriority *Priority `json:"relativePriority,omitempty"` +} + +var _ json.Unmarshaler = &TransformOutput{} + +func (s *TransformOutput) UnmarshalJSON(bytes []byte) error { + type alias TransformOutput + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into TransformOutput: %+v", err) + } + + s.OnError = decoded.OnError + s.RelativePriority = decoded.RelativePriority + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TransformOutput into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["preset"]; ok { + impl, err := unmarshalPresetImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Preset' for 'TransformOutput': %+v", err) + } + s.Preset = impl + } + return nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_transformproperties.go b/resource-manager/media/2022-07-01/encodings/model_transformproperties.go new file mode 100644 index 00000000000..74e7048d696 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_transformproperties.go @@ -0,0 +1,41 @@ +package encodings + +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 TransformProperties struct { + Created *string `json:"created,omitempty"` + Description *string `json:"description,omitempty"` + LastModified *string `json:"lastModified,omitempty"` + Outputs []TransformOutput `json:"outputs"` +} + +func (o *TransformProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *TransformProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *TransformProperties) GetLastModifiedAsTime() (*time.Time, error) { + if o.LastModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *TransformProperties) SetLastModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModified = &formatted +} diff --git a/resource-manager/media/2022-07-01/encodings/model_transportstreamformat.go b/resource-manager/media/2022-07-01/encodings/model_transportstreamformat.go new file mode 100644 index 00000000000..5a869925fa5 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_transportstreamformat.go @@ -0,0 +1,42 @@ +package encodings + +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 _ Format = TransportStreamFormat{} + +type TransportStreamFormat struct { + OutputFiles *[]OutputFile `json:"outputFiles,omitempty"` + + // Fields inherited from Format + FilenamePattern string `json:"filenamePattern"` +} + +var _ json.Marshaler = TransportStreamFormat{} + +func (s TransportStreamFormat) MarshalJSON() ([]byte, error) { + type wrapper TransportStreamFormat + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling TransportStreamFormat: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling TransportStreamFormat: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.TransportStreamFormat" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling TransportStreamFormat: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_utccliptime.go b/resource-manager/media/2022-07-01/encodings/model_utccliptime.go new file mode 100644 index 00000000000..0787e406a94 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_utccliptime.go @@ -0,0 +1,41 @@ +package encodings + +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 _ ClipTime = UtcClipTime{} + +type UtcClipTime struct { + Time string `json:"time"` + + // Fields inherited from ClipTime +} + +var _ json.Marshaler = UtcClipTime{} + +func (s UtcClipTime) MarshalJSON() ([]byte, error) { + type wrapper UtcClipTime + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UtcClipTime: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UtcClipTime: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.UtcClipTime" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UtcClipTime: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_video.go b/resource-manager/media/2022-07-01/encodings/model_video.go new file mode 100644 index 00000000000..35e566481c9 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_video.go @@ -0,0 +1,44 @@ +package encodings + +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 _ Codec = Video{} + +type Video struct { + KeyFrameInterval *string `json:"keyFrameInterval,omitempty"` + StretchMode *StretchMode `json:"stretchMode,omitempty"` + SyncMode *VideoSyncMode `json:"syncMode,omitempty"` + + // Fields inherited from Codec + Label *string `json:"label,omitempty"` +} + +var _ json.Marshaler = Video{} + +func (s Video) MarshalJSON() ([]byte, error) { + type wrapper Video + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling Video: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling Video: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.Video" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling Video: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_videoanalyzerpreset.go b/resource-manager/media/2022-07-01/encodings/model_videoanalyzerpreset.go new file mode 100644 index 00000000000..d98ab1914de --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_videoanalyzerpreset.go @@ -0,0 +1,44 @@ +package encodings + +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 _ Preset = VideoAnalyzerPreset{} + +type VideoAnalyzerPreset struct { + AudioLanguage *string `json:"audioLanguage,omitempty"` + ExperimentalOptions *map[string]string `json:"experimentalOptions,omitempty"` + InsightsToExtract *InsightsType `json:"insightsToExtract,omitempty"` + Mode *AudioAnalysisMode `json:"mode,omitempty"` + + // Fields inherited from Preset +} + +var _ json.Marshaler = VideoAnalyzerPreset{} + +func (s VideoAnalyzerPreset) MarshalJSON() ([]byte, error) { + type wrapper VideoAnalyzerPreset + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VideoAnalyzerPreset: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VideoAnalyzerPreset: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.VideoAnalyzerPreset" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VideoAnalyzerPreset: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_videooverlay.go b/resource-manager/media/2022-07-01/encodings/model_videooverlay.go new file mode 100644 index 00000000000..27d0f028256 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_videooverlay.go @@ -0,0 +1,49 @@ +package encodings + +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 _ Overlay = VideoOverlay{} + +type VideoOverlay struct { + CropRectangle *Rectangle `json:"cropRectangle,omitempty"` + Opacity *float64 `json:"opacity,omitempty"` + Position *Rectangle `json:"position,omitempty"` + + // Fields inherited from Overlay + AudioGainLevel *float64 `json:"audioGainLevel,omitempty"` + End *string `json:"end,omitempty"` + FadeInDuration *string `json:"fadeInDuration,omitempty"` + FadeOutDuration *string `json:"fadeOutDuration,omitempty"` + InputLabel string `json:"inputLabel"` + Start *string `json:"start,omitempty"` +} + +var _ json.Marshaler = VideoOverlay{} + +func (s VideoOverlay) MarshalJSON() ([]byte, error) { + type wrapper VideoOverlay + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VideoOverlay: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VideoOverlay: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.VideoOverlay" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VideoOverlay: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/model_videotrackdescriptor.go b/resource-manager/media/2022-07-01/encodings/model_videotrackdescriptor.go new file mode 100644 index 00000000000..ff1f690b1d0 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/model_videotrackdescriptor.go @@ -0,0 +1,40 @@ +package encodings + +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 _ TrackDescriptor = VideoTrackDescriptor{} + +type VideoTrackDescriptor struct { + + // Fields inherited from TrackDescriptor +} + +var _ json.Marshaler = VideoTrackDescriptor{} + +func (s VideoTrackDescriptor) MarshalJSON() ([]byte, error) { + type wrapper VideoTrackDescriptor + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VideoTrackDescriptor: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VideoTrackDescriptor: %+v", err) + } + decoded["@odata.type"] = "#Microsoft.Media.VideoTrackDescriptor" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VideoTrackDescriptor: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/media/2022-07-01/encodings/predicates.go b/resource-manager/media/2022-07-01/encodings/predicates.go new file mode 100644 index 00000000000..ac8accb332f --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/predicates.go @@ -0,0 +1,50 @@ +package encodings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobOperationPredicate) Matches(input Job) 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 TransformOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TransformOperationPredicate) Matches(input Transform) 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/media/2022-07-01/encodings/version.go b/resource-manager/media/2022-07-01/encodings/version.go new file mode 100644 index 00000000000..2873abea310 --- /dev/null +++ b/resource-manager/media/2022-07-01/encodings/version.go @@ -0,0 +1,12 @@ +package encodings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-07-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/encodings/%s", defaultApiVersion) +} diff --git a/resource-manager/orbital/2022-11-01/client.go b/resource-manager/orbital/2022-11-01/client.go new file mode 100644 index 00000000000..25f8428af18 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/client.go @@ -0,0 +1,41 @@ +package v2022_11_01 + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/contact" + "github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/contactprofile" + "github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/groundstation" + "github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/spacecraft" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Client struct { + Contact *contact.ContactClient + ContactProfile *contactprofile.ContactProfileClient + GroundStation *groundstation.GroundStationClient + Spacecraft *spacecraft.SpacecraftClient +} + +func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { + + contactClient := contact.NewContactClientWithBaseURI(endpoint) + configureAuthFunc(&contactClient.Client) + + contactProfileClient := contactprofile.NewContactProfileClientWithBaseURI(endpoint) + configureAuthFunc(&contactProfileClient.Client) + + groundStationClient := groundstation.NewGroundStationClientWithBaseURI(endpoint) + configureAuthFunc(&groundStationClient.Client) + + spacecraftClient := spacecraft.NewSpacecraftClientWithBaseURI(endpoint) + configureAuthFunc(&spacecraftClient.Client) + + return Client{ + Contact: &contactClient, + ContactProfile: &contactProfileClient, + GroundStation: &groundStationClient, + Spacecraft: &spacecraftClient, + } +} diff --git a/resource-manager/orbital/2022-11-01/contact/README.md b/resource-manager/orbital/2022-11-01/contact/README.md new file mode 100644 index 00000000000..d3ae58ffa69 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/README.md @@ -0,0 +1,104 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/contact` Documentation + +The `contact` SDK allows for interaction with the Azure Resource Manager Service `orbital` (API Version `2022-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/orbital/2022-11-01/contact" +``` + + +### Client Initialization + +```go +client := contact.NewContactClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContactClient.Create` + +```go +ctx := context.TODO() +id := contact.NewContactID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue", "contactValue") + +payload := contact.Contact{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContactClient.Delete` + +```go +ctx := context.TODO() +id := contact.NewContactID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue", "contactValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContactClient.Get` + +```go +ctx := context.TODO() +id := contact.NewContactID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue", "contactValue") + +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: `ContactClient.List` + +```go +ctx := context.TODO() +id := contact.NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + +// 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: `ContactClient.SpacecraftsListAvailableContacts` + +```go +ctx := context.TODO() +id := contact.NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + +payload := contact.ContactParameters{ + // ... +} + + +// alternatively `client.SpacecraftsListAvailableContacts(ctx, id, payload)` can be used to do batched pagination +items, err := client.SpacecraftsListAvailableContactsComplete(ctx, id, payload) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/orbital/2022-11-01/contact/client.go b/resource-manager/orbital/2022-11-01/contact/client.go new file mode 100644 index 00000000000..ff7cb641ed8 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/client.go @@ -0,0 +1,18 @@ +package contact + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactClient struct { + Client autorest.Client + baseUri string +} + +func NewContactClientWithBaseURI(endpoint string) ContactClient { + return ContactClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/orbital/2022-11-01/contact/constants.go b/resource-manager/orbital/2022-11-01/contact/constants.go new file mode 100644 index 00000000000..00df14ebc3d --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/constants.go @@ -0,0 +1,83 @@ +package contact + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactsStatus string + +const ( + ContactsStatusCancelled ContactsStatus = "cancelled" + ContactsStatusFailed ContactsStatus = "failed" + ContactsStatusProviderCancelled ContactsStatus = "providerCancelled" + ContactsStatusScheduled ContactsStatus = "scheduled" + ContactsStatusSucceeded ContactsStatus = "succeeded" +) + +func PossibleValuesForContactsStatus() []string { + return []string{ + string(ContactsStatusCancelled), + string(ContactsStatusFailed), + string(ContactsStatusProviderCancelled), + string(ContactsStatusScheduled), + string(ContactsStatusSucceeded), + } +} + +func parseContactsStatus(input string) (*ContactsStatus, error) { + vals := map[string]ContactsStatus{ + "cancelled": ContactsStatusCancelled, + "failed": ContactsStatusFailed, + "providercancelled": ContactsStatusProviderCancelled, + "scheduled": ContactsStatusScheduled, + "succeeded": ContactsStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContactsStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "canceled" + ProvisioningStateCreating ProvisioningState = "creating" + ProvisioningStateDeleting ProvisioningState = "deleting" + ProvisioningStateFailed ProvisioningState = "failed" + ProvisioningStateSucceeded ProvisioningState = "succeeded" + ProvisioningStateUpdating ProvisioningState = "updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "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/orbital/2022-11-01/contact/id_contact.go b/resource-manager/orbital/2022-11-01/contact/id_contact.go new file mode 100644 index 00000000000..2ea6b64ef0d --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/id_contact.go @@ -0,0 +1,140 @@ +package contact + +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 = ContactId{} + +// ContactId is a struct representing the Resource ID for a Contact +type ContactId struct { + SubscriptionId string + ResourceGroupName string + SpacecraftName string + ContactName string +} + +// NewContactID returns a new ContactId struct +func NewContactID(subscriptionId string, resourceGroupName string, spacecraftName string, contactName string) ContactId { + return ContactId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SpacecraftName: spacecraftName, + ContactName: contactName, + } +} + +// ParseContactID parses 'input' into a ContactId +func ParseContactID(input string) (*ContactId, error) { + parser := resourceids.NewParserFromResourceIdType(ContactId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ContactId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SpacecraftName, ok = parsed.Parsed["spacecraftName"]; !ok { + return nil, fmt.Errorf("the segment 'spacecraftName' was not found in the resource id %q", input) + } + + if id.ContactName, ok = parsed.Parsed["contactName"]; !ok { + return nil, fmt.Errorf("the segment 'contactName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseContactIDInsensitively parses 'input' case-insensitively into a ContactId +// note: this method should only be used for API response data and not user input +func ParseContactIDInsensitively(input string) (*ContactId, error) { + parser := resourceids.NewParserFromResourceIdType(ContactId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ContactId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SpacecraftName, ok = parsed.Parsed["spacecraftName"]; !ok { + return nil, fmt.Errorf("the segment 'spacecraftName' was not found in the resource id %q", input) + } + + if id.ContactName, ok = parsed.Parsed["contactName"]; !ok { + return nil, fmt.Errorf("the segment 'contactName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateContactID checks that 'input' can be parsed as a Contact ID +func ValidateContactID(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 := ParseContactID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Contact ID +func (id ContactId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Orbital/spacecrafts/%s/contacts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SpacecraftName, id.ContactName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Contact ID +func (id ContactId) 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("staticMicrosoftOrbital", "Microsoft.Orbital", "Microsoft.Orbital"), + resourceids.StaticSegment("staticSpacecrafts", "spacecrafts", "spacecrafts"), + resourceids.UserSpecifiedSegment("spacecraftName", "spacecraftValue"), + resourceids.StaticSegment("staticContacts", "contacts", "contacts"), + resourceids.UserSpecifiedSegment("contactName", "contactValue"), + } +} + +// String returns a human-readable description of this Contact ID +func (id ContactId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Spacecraft Name: %q", id.SpacecraftName), + fmt.Sprintf("Contact Name: %q", id.ContactName), + } + return fmt.Sprintf("Contact (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/orbital/2022-11-01/contact/id_contact_test.go b/resource-manager/orbital/2022-11-01/contact/id_contact_test.go new file mode 100644 index 00000000000..c78308fd209 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/id_contact_test.go @@ -0,0 +1,327 @@ +package contact + +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 = ContactId{} + +func TestNewContactID(t *testing.T) { + id := NewContactID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue", "contactValue") + + 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.SpacecraftName != "spacecraftValue" { + t.Fatalf("Expected %q but got %q for Segment 'SpacecraftName'", id.SpacecraftName, "spacecraftValue") + } + + if id.ContactName != "contactValue" { + t.Fatalf("Expected %q but got %q for Segment 'ContactName'", id.ContactName, "contactValue") + } +} + +func TestFormatContactID(t *testing.T) { + actual := NewContactID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue", "contactValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/contacts/contactValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContactID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContactId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/contacts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/contacts/contactValue", + Expected: &ContactId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SpacecraftName: "spacecraftValue", + ContactName: "contactValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/contacts/contactValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContactID(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.SpacecraftName != v.Expected.SpacecraftName { + t.Fatalf("Expected %q but got %q for SpacecraftName", v.Expected.SpacecraftName, actual.SpacecraftName) + } + + if actual.ContactName != v.Expected.ContactName { + t.Fatalf("Expected %q but got %q for ContactName", v.Expected.ContactName, actual.ContactName) + } + + } +} + +func TestParseContactIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContactId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/contacts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe/cOnTaCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/contacts/contactValue", + Expected: &ContactId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SpacecraftName: "spacecraftValue", + ContactName: "contactValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/contacts/contactValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe/cOnTaCtS/cOnTaCtVaLuE", + Expected: &ContactId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SpacecraftName: "sPaCeCrAfTvAlUe", + ContactName: "cOnTaCtVaLuE", + }, + }, + { + // 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.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe/cOnTaCtS/cOnTaCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContactIDInsensitively(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.SpacecraftName != v.Expected.SpacecraftName { + t.Fatalf("Expected %q but got %q for SpacecraftName", v.Expected.SpacecraftName, actual.SpacecraftName) + } + + if actual.ContactName != v.Expected.ContactName { + t.Fatalf("Expected %q but got %q for ContactName", v.Expected.ContactName, actual.ContactName) + } + + } +} + +func TestSegmentsForContactId(t *testing.T) { + segments := ContactId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContactId 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/orbital/2022-11-01/contact/id_spacecraft.go b/resource-manager/orbital/2022-11-01/contact/id_spacecraft.go new file mode 100644 index 00000000000..6dcabdbfc17 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/id_spacecraft.go @@ -0,0 +1,127 @@ +package contact + +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 = SpacecraftId{} + +// SpacecraftId is a struct representing the Resource ID for a Spacecraft +type SpacecraftId struct { + SubscriptionId string + ResourceGroupName string + SpacecraftName string +} + +// NewSpacecraftID returns a new SpacecraftId struct +func NewSpacecraftID(subscriptionId string, resourceGroupName string, spacecraftName string) SpacecraftId { + return SpacecraftId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SpacecraftName: spacecraftName, + } +} + +// ParseSpacecraftID parses 'input' into a SpacecraftId +func ParseSpacecraftID(input string) (*SpacecraftId, error) { + parser := resourceids.NewParserFromResourceIdType(SpacecraftId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SpacecraftId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SpacecraftName, ok = parsed.Parsed["spacecraftName"]; !ok { + return nil, fmt.Errorf("the segment 'spacecraftName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSpacecraftIDInsensitively parses 'input' case-insensitively into a SpacecraftId +// note: this method should only be used for API response data and not user input +func ParseSpacecraftIDInsensitively(input string) (*SpacecraftId, error) { + parser := resourceids.NewParserFromResourceIdType(SpacecraftId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SpacecraftId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SpacecraftName, ok = parsed.Parsed["spacecraftName"]; !ok { + return nil, fmt.Errorf("the segment 'spacecraftName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSpacecraftID checks that 'input' can be parsed as a Spacecraft ID +func ValidateSpacecraftID(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 := ParseSpacecraftID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Spacecraft ID +func (id SpacecraftId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Orbital/spacecrafts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SpacecraftName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Spacecraft ID +func (id SpacecraftId) 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("staticMicrosoftOrbital", "Microsoft.Orbital", "Microsoft.Orbital"), + resourceids.StaticSegment("staticSpacecrafts", "spacecrafts", "spacecrafts"), + resourceids.UserSpecifiedSegment("spacecraftName", "spacecraftValue"), + } +} + +// String returns a human-readable description of this Spacecraft ID +func (id SpacecraftId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Spacecraft Name: %q", id.SpacecraftName), + } + return fmt.Sprintf("Spacecraft (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/orbital/2022-11-01/contact/id_spacecraft_test.go b/resource-manager/orbital/2022-11-01/contact/id_spacecraft_test.go new file mode 100644 index 00000000000..a1b3ca5b73e --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/id_spacecraft_test.go @@ -0,0 +1,282 @@ +package contact + +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 = SpacecraftId{} + +func TestNewSpacecraftID(t *testing.T) { + id := NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + + 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.SpacecraftName != "spacecraftValue" { + t.Fatalf("Expected %q but got %q for Segment 'SpacecraftName'", id.SpacecraftName, "spacecraftValue") + } +} + +func TestFormatSpacecraftID(t *testing.T) { + actual := NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSpacecraftID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpacecraftId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue", + Expected: &SpacecraftId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SpacecraftName: "spacecraftValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSpacecraftID(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.SpacecraftName != v.Expected.SpacecraftName { + t.Fatalf("Expected %q but got %q for SpacecraftName", v.Expected.SpacecraftName, actual.SpacecraftName) + } + + } +} + +func TestParseSpacecraftIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpacecraftId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue", + Expected: &SpacecraftId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SpacecraftName: "spacecraftValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe", + Expected: &SpacecraftId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SpacecraftName: "sPaCeCrAfTvAlUe", + }, + }, + { + // 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.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSpacecraftIDInsensitively(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.SpacecraftName != v.Expected.SpacecraftName { + t.Fatalf("Expected %q but got %q for SpacecraftName", v.Expected.SpacecraftName, actual.SpacecraftName) + } + + } +} + +func TestSegmentsForSpacecraftId(t *testing.T) { + segments := SpacecraftId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SpacecraftId 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/orbital/2022-11-01/contact/method_create_autorest.go b/resource-manager/orbital/2022-11-01/contact/method_create_autorest.go new file mode 100644 index 00000000000..1adb20e5486 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/method_create_autorest.go @@ -0,0 +1,79 @@ +package contact + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ContactClient) Create(ctx context.Context, id ContactId, input Contact) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ContactClient) CreateThenPoll(ctx context.Context, id ContactId, input Contact) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ContactClient) preparerForCreate(ctx context.Context, id ContactId, input Contact) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ContactClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/contact/method_delete_autorest.go b/resource-manager/orbital/2022-11-01/contact/method_delete_autorest.go new file mode 100644 index 00000000000..2a53c31219a --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/method_delete_autorest.go @@ -0,0 +1,78 @@ +package contact + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ContactClient) Delete(ctx context.Context, id ContactId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ContactClient) DeleteThenPoll(ctx context.Context, id ContactId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ContactClient) preparerForDelete(ctx context.Context, id ContactId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ContactClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/contact/method_get_autorest.go b/resource-manager/orbital/2022-11-01/contact/method_get_autorest.go new file mode 100644 index 00000000000..c28088588f1 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/method_get_autorest.go @@ -0,0 +1,68 @@ +package contact + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Contact +} + +// Get ... +func (c ContactClient) Get(ctx context.Context, id ContactId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ContactClient) preparerForGet(ctx context.Context, id ContactId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ContactClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/orbital/2022-11-01/contact/method_list_autorest.go b/resource-manager/orbital/2022-11-01/contact/method_list_autorest.go new file mode 100644 index 00000000000..bd504ab68bd --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/method_list_autorest.go @@ -0,0 +1,186 @@ +package contact + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Contact + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Contact +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ContactClient) List(ctx context.Context, id SpacecraftId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ContactClient) preparerForList(ctx context.Context, id SpacecraftId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/contacts", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ContactClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ContactClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Contact `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ContactClient) ListComplete(ctx context.Context, id SpacecraftId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ContactOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ContactClient) ListCompleteMatchingPredicate(ctx context.Context, id SpacecraftId, predicate ContactOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Contact, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/orbital/2022-11-01/contact/method_spacecraftslistavailablecontacts_autorest.go b/resource-manager/orbital/2022-11-01/contact/method_spacecraftslistavailablecontacts_autorest.go new file mode 100644 index 00000000000..a767002c487 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/method_spacecraftslistavailablecontacts_autorest.go @@ -0,0 +1,125 @@ +package contact + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SpacecraftsListAvailableContactsOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response + Model *[]AvailableContacts + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (SpacecraftsListAvailableContactsOperationResponse, error) +} + +type SpacecraftsListAvailableContactsCompleteResult struct { + Items []AvailableContacts +} + +func (r SpacecraftsListAvailableContactsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r SpacecraftsListAvailableContactsOperationResponse) LoadMore(ctx context.Context) (resp SpacecraftsListAvailableContactsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// SpacecraftsListAvailableContacts ... +func (c ContactClient) SpacecraftsListAvailableContacts(ctx context.Context, id SpacecraftId, input ContactParameters) (result SpacecraftsListAvailableContactsOperationResponse, err error) { + req, err := c.preparerForSpacecraftsListAvailableContacts(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "SpacecraftsListAvailableContacts", nil, "Failure preparing request") + return + } + + result, err = c.senderForSpacecraftsListAvailableContacts(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "contact.ContactClient", "SpacecraftsListAvailableContacts", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// SpacecraftsListAvailableContactsThenPoll performs SpacecraftsListAvailableContacts then polls until it's completed +func (c ContactClient) SpacecraftsListAvailableContactsThenPoll(ctx context.Context, id SpacecraftId, input ContactParameters) error { + result, err := c.SpacecraftsListAvailableContacts(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SpacecraftsListAvailableContacts: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after SpacecraftsListAvailableContacts: %+v", err) + } + + return nil +} + +// preparerForSpacecraftsListAvailableContacts prepares the SpacecraftsListAvailableContacts request. +func (c ContactClient) preparerForSpacecraftsListAvailableContacts(ctx context.Context, id SpacecraftId, input ContactParameters) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/listAvailableContacts", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForSpacecraftsListAvailableContactsWithNextLink prepares the SpacecraftsListAvailableContacts request with the given nextLink token. +func (c ContactClient) preparerForSpacecraftsListAvailableContactsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForSpacecraftsListAvailableContacts sends the SpacecraftsListAvailableContacts request. The method will close the +// http.Response Body if it receives an error. +func (c ContactClient) senderForSpacecraftsListAvailableContacts(ctx context.Context, req *http.Request) (future SpacecraftsListAvailableContactsOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/contact/model_availablecontacts.go b/resource-manager/orbital/2022-11-01/contact/model_availablecontacts.go new file mode 100644 index 00000000000..ada5a5a14df --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/model_availablecontacts.go @@ -0,0 +1,10 @@ +package contact + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableContacts struct { + GroundStationName *string `json:"groundStationName,omitempty"` + Properties *ContactInstanceProperties `json:"properties,omitempty"` + Spacecraft *ResourceReference `json:"spacecraft,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/contact/model_contact.go b/resource-manager/orbital/2022-11-01/contact/model_contact.go new file mode 100644 index 00000000000..120a848f187 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/model_contact.go @@ -0,0 +1,16 @@ +package contact + +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 Contact struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties ContactsProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/contact/model_contactinstanceproperties.go b/resource-manager/orbital/2022-11-01/contact/model_contactinstanceproperties.go new file mode 100644 index 00000000000..71650180107 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/model_contactinstanceproperties.go @@ -0,0 +1,70 @@ +package contact + +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 ContactInstanceProperties struct { + EndAzimuthDegrees *float64 `json:"endAzimuthDegrees,omitempty"` + EndElevationDegrees *float64 `json:"endElevationDegrees,omitempty"` + MaximumElevationDegrees *float64 `json:"maximumElevationDegrees,omitempty"` + RxEndTime *string `json:"rxEndTime,omitempty"` + RxStartTime *string `json:"rxStartTime,omitempty"` + StartAzimuthDegrees *float64 `json:"startAzimuthDegrees,omitempty"` + StartElevationDegrees *float64 `json:"startElevationDegrees,omitempty"` + TxEndTime *string `json:"txEndTime,omitempty"` + TxStartTime *string `json:"txStartTime,omitempty"` +} + +func (o *ContactInstanceProperties) GetRxEndTimeAsTime() (*time.Time, error) { + if o.RxEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RxEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactInstanceProperties) SetRxEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RxEndTime = &formatted +} + +func (o *ContactInstanceProperties) GetRxStartTimeAsTime() (*time.Time, error) { + if o.RxStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RxStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactInstanceProperties) SetRxStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RxStartTime = &formatted +} + +func (o *ContactInstanceProperties) GetTxEndTimeAsTime() (*time.Time, error) { + if o.TxEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TxEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactInstanceProperties) SetTxEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TxEndTime = &formatted +} + +func (o *ContactInstanceProperties) GetTxStartTimeAsTime() (*time.Time, error) { + if o.TxStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TxStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactInstanceProperties) SetTxStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TxStartTime = &formatted +} diff --git a/resource-manager/orbital/2022-11-01/contact/model_contactparameters.go b/resource-manager/orbital/2022-11-01/contact/model_contactparameters.go new file mode 100644 index 00000000000..220d2bacaa0 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/model_contactparameters.go @@ -0,0 +1,35 @@ +package contact + +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 ContactParameters struct { + ContactProfile ResourceReference `json:"contactProfile"` + EndTime string `json:"endTime"` + GroundStationName string `json:"groundStationName"` + StartTime string `json:"startTime"` +} + +func (o *ContactParameters) GetEndTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactParameters) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = formatted +} + +func (o *ContactParameters) GetStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactParameters) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = formatted +} diff --git a/resource-manager/orbital/2022-11-01/contact/model_contactsproperties.go b/resource-manager/orbital/2022-11-01/contact/model_contactsproperties.go new file mode 100644 index 00000000000..de517643282 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/model_contactsproperties.go @@ -0,0 +1,96 @@ +package contact + +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 ContactsProperties struct { + AntennaConfiguration *ContactsPropertiesAntennaConfiguration `json:"antennaConfiguration,omitempty"` + ContactProfile ResourceReference `json:"contactProfile"` + EndAzimuthDegrees *float64 `json:"endAzimuthDegrees,omitempty"` + EndElevationDegrees *float64 `json:"endElevationDegrees,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + GroundStationName string `json:"groundStationName"` + MaximumElevationDegrees *float64 `json:"maximumElevationDegrees,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ReservationEndTime string `json:"reservationEndTime"` + ReservationStartTime string `json:"reservationStartTime"` + RxEndTime *string `json:"rxEndTime,omitempty"` + RxStartTime *string `json:"rxStartTime,omitempty"` + StartAzimuthDegrees *float64 `json:"startAzimuthDegrees,omitempty"` + StartElevationDegrees *float64 `json:"startElevationDegrees,omitempty"` + Status *ContactsStatus `json:"status,omitempty"` + TxEndTime *string `json:"txEndTime,omitempty"` + TxStartTime *string `json:"txStartTime,omitempty"` +} + +func (o *ContactsProperties) GetReservationEndTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.ReservationEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactsProperties) SetReservationEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ReservationEndTime = formatted +} + +func (o *ContactsProperties) GetReservationStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.ReservationStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactsProperties) SetReservationStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ReservationStartTime = formatted +} + +func (o *ContactsProperties) GetRxEndTimeAsTime() (*time.Time, error) { + if o.RxEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RxEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactsProperties) SetRxEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RxEndTime = &formatted +} + +func (o *ContactsProperties) GetRxStartTimeAsTime() (*time.Time, error) { + if o.RxStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RxStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactsProperties) SetRxStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RxStartTime = &formatted +} + +func (o *ContactsProperties) GetTxEndTimeAsTime() (*time.Time, error) { + if o.TxEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TxEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactsProperties) SetTxEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TxEndTime = &formatted +} + +func (o *ContactsProperties) GetTxStartTimeAsTime() (*time.Time, error) { + if o.TxStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TxStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContactsProperties) SetTxStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TxStartTime = &formatted +} diff --git a/resource-manager/orbital/2022-11-01/contact/model_contactspropertiesantennaconfiguration.go b/resource-manager/orbital/2022-11-01/contact/model_contactspropertiesantennaconfiguration.go new file mode 100644 index 00000000000..6db8a48bc16 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/model_contactspropertiesantennaconfiguration.go @@ -0,0 +1,9 @@ +package contact + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactsPropertiesAntennaConfiguration struct { + DestinationIP *string `json:"destinationIp,omitempty"` + SourceIPs *[]string `json:"sourceIps,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/contact/model_resourcereference.go b/resource-manager/orbital/2022-11-01/contact/model_resourcereference.go new file mode 100644 index 00000000000..5714949cc1d --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/model_resourcereference.go @@ -0,0 +1,8 @@ +package contact + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceReference struct { + Id string `json:"id"` +} diff --git a/resource-manager/orbital/2022-11-01/contact/predicates.go b/resource-manager/orbital/2022-11-01/contact/predicates.go new file mode 100644 index 00000000000..0ee6c4d93a4 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/predicates.go @@ -0,0 +1,40 @@ +package contact + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableContactsOperationPredicate struct { + GroundStationName *string +} + +func (p AvailableContactsOperationPredicate) Matches(input AvailableContacts) bool { + + if p.GroundStationName != nil && (input.GroundStationName == nil && *p.GroundStationName != *input.GroundStationName) { + return false + } + + return true +} + +type ContactOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ContactOperationPredicate) Matches(input Contact) 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/orbital/2022-11-01/contact/version.go b/resource-manager/orbital/2022-11-01/contact/version.go new file mode 100644 index 00000000000..ceec4d3407b --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contact/version.go @@ -0,0 +1,12 @@ +package contact + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contact/%s", defaultApiVersion) +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/README.md b/resource-manager/orbital/2022-11-01/contactprofile/README.md new file mode 100644 index 00000000000..7daae24ef0d --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/contactprofile` Documentation + +The `contactprofile` SDK allows for interaction with the Azure Resource Manager Service `orbital` (API Version `2022-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/orbital/2022-11-01/contactprofile" +``` + + +### Client Initialization + +```go +client := contactprofile.NewContactProfileClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContactProfileClient.ContactProfilesCreateOrUpdate` + +```go +ctx := context.TODO() +id := contactprofile.NewContactProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "contactProfileValue") + +payload := contactprofile.ContactProfile{ + // ... +} + + +if err := client.ContactProfilesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContactProfileClient.ContactProfilesDelete` + +```go +ctx := context.TODO() +id := contactprofile.NewContactProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "contactProfileValue") + +if err := client.ContactProfilesDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContactProfileClient.ContactProfilesGet` + +```go +ctx := context.TODO() +id := contactprofile.NewContactProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "contactProfileValue") + +read, err := client.ContactProfilesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContactProfileClient.ContactProfilesList` + +```go +ctx := context.TODO() +id := contactprofile.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ContactProfilesList(ctx, id)` can be used to do batched pagination +items, err := client.ContactProfilesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ContactProfileClient.ContactProfilesListBySubscription` + +```go +ctx := context.TODO() +id := contactprofile.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ContactProfilesListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ContactProfilesListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ContactProfileClient.ContactProfilesUpdateTags` + +```go +ctx := context.TODO() +id := contactprofile.NewContactProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "contactProfileValue") + +payload := contactprofile.TagsObject{ + // ... +} + + +if err := client.ContactProfilesUpdateTagsThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/orbital/2022-11-01/contactprofile/client.go b/resource-manager/orbital/2022-11-01/contactprofile/client.go new file mode 100644 index 00000000000..a46f4d053ec --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/client.go @@ -0,0 +1,18 @@ +package contactprofile + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfileClient struct { + Client autorest.Client + baseUri string +} + +func NewContactProfileClientWithBaseURI(endpoint string) ContactProfileClient { + return ContactProfileClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/constants.go b/resource-manager/orbital/2022-11-01/contactprofile/constants.go new file mode 100644 index 00000000000..1a61e972a54 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/constants.go @@ -0,0 +1,167 @@ +package contactprofile + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutoTrackingConfiguration string + +const ( + AutoTrackingConfigurationDisabled AutoTrackingConfiguration = "disabled" + AutoTrackingConfigurationSBand AutoTrackingConfiguration = "sBand" + AutoTrackingConfigurationXBand AutoTrackingConfiguration = "xBand" +) + +func PossibleValuesForAutoTrackingConfiguration() []string { + return []string{ + string(AutoTrackingConfigurationDisabled), + string(AutoTrackingConfigurationSBand), + string(AutoTrackingConfigurationXBand), + } +} + +func parseAutoTrackingConfiguration(input string) (*AutoTrackingConfiguration, error) { + vals := map[string]AutoTrackingConfiguration{ + "disabled": AutoTrackingConfigurationDisabled, + "sband": AutoTrackingConfigurationSBand, + "xband": AutoTrackingConfigurationXBand, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoTrackingConfiguration(input) + return &out, nil +} + +type Direction string + +const ( + DirectionDownlink Direction = "Downlink" + DirectionUplink Direction = "Uplink" +) + +func PossibleValuesForDirection() []string { + return []string{ + string(DirectionDownlink), + string(DirectionUplink), + } +} + +func parseDirection(input string) (*Direction, error) { + vals := map[string]Direction{ + "downlink": DirectionDownlink, + "uplink": DirectionUplink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Direction(input) + return &out, nil +} + +type Polarization string + +const ( + PolarizationLHCP Polarization = "LHCP" + PolarizationLinearHorizontal Polarization = "linearHorizontal" + PolarizationLinearVertical Polarization = "linearVertical" + PolarizationRHCP Polarization = "RHCP" +) + +func PossibleValuesForPolarization() []string { + return []string{ + string(PolarizationLHCP), + string(PolarizationLinearHorizontal), + string(PolarizationLinearVertical), + string(PolarizationRHCP), + } +} + +func parsePolarization(input string) (*Polarization, error) { + vals := map[string]Polarization{ + "lhcp": PolarizationLHCP, + "linearhorizontal": PolarizationLinearHorizontal, + "linearvertical": PolarizationLinearVertical, + "rhcp": PolarizationRHCP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Polarization(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolTCP Protocol = "TCP" + ProtocolUDP Protocol = "UDP" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolTCP), + string(ProtocolUDP), + } +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "tcp": ProtocolTCP, + "udp": ProtocolUDP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "canceled" + ProvisioningStateCreating ProvisioningState = "creating" + ProvisioningStateDeleting ProvisioningState = "deleting" + ProvisioningStateFailed ProvisioningState = "failed" + ProvisioningStateSucceeded ProvisioningState = "succeeded" + ProvisioningStateUpdating ProvisioningState = "updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "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/orbital/2022-11-01/contactprofile/id_contactprofile.go b/resource-manager/orbital/2022-11-01/contactprofile/id_contactprofile.go new file mode 100644 index 00000000000..7b0b2b314f4 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/id_contactprofile.go @@ -0,0 +1,127 @@ +package contactprofile + +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 = ContactProfileId{} + +// ContactProfileId is a struct representing the Resource ID for a Contact Profile +type ContactProfileId struct { + SubscriptionId string + ResourceGroupName string + ContactProfileName string +} + +// NewContactProfileID returns a new ContactProfileId struct +func NewContactProfileID(subscriptionId string, resourceGroupName string, contactProfileName string) ContactProfileId { + return ContactProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContactProfileName: contactProfileName, + } +} + +// ParseContactProfileID parses 'input' into a ContactProfileId +func ParseContactProfileID(input string) (*ContactProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(ContactProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ContactProfileId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ContactProfileName, ok = parsed.Parsed["contactProfileName"]; !ok { + return nil, fmt.Errorf("the segment 'contactProfileName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseContactProfileIDInsensitively parses 'input' case-insensitively into a ContactProfileId +// note: this method should only be used for API response data and not user input +func ParseContactProfileIDInsensitively(input string) (*ContactProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(ContactProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ContactProfileId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ContactProfileName, ok = parsed.Parsed["contactProfileName"]; !ok { + return nil, fmt.Errorf("the segment 'contactProfileName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateContactProfileID checks that 'input' can be parsed as a Contact Profile ID +func ValidateContactProfileID(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 := ParseContactProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Contact Profile ID +func (id ContactProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Orbital/contactProfiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContactProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Contact Profile ID +func (id ContactProfileId) 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("staticMicrosoftOrbital", "Microsoft.Orbital", "Microsoft.Orbital"), + resourceids.StaticSegment("staticContactProfiles", "contactProfiles", "contactProfiles"), + resourceids.UserSpecifiedSegment("contactProfileName", "contactProfileValue"), + } +} + +// String returns a human-readable description of this Contact Profile ID +func (id ContactProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Contact Profile Name: %q", id.ContactProfileName), + } + return fmt.Sprintf("Contact Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/id_contactprofile_test.go b/resource-manager/orbital/2022-11-01/contactprofile/id_contactprofile_test.go new file mode 100644 index 00000000000..480a819df5c --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/id_contactprofile_test.go @@ -0,0 +1,282 @@ +package contactprofile + +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 = ContactProfileId{} + +func TestNewContactProfileID(t *testing.T) { + id := NewContactProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "contactProfileValue") + + 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.ContactProfileName != "contactProfileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ContactProfileName'", id.ContactProfileName, "contactProfileValue") + } +} + +func TestFormatContactProfileID(t *testing.T) { + actual := NewContactProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "contactProfileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/contactProfiles/contactProfileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContactProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContactProfileId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/contactProfiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/contactProfiles/contactProfileValue", + Expected: &ContactProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContactProfileName: "contactProfileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/contactProfiles/contactProfileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContactProfileID(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.ContactProfileName != v.Expected.ContactProfileName { + t.Fatalf("Expected %q but got %q for ContactProfileName", v.Expected.ContactProfileName, actual.ContactProfileName) + } + + } +} + +func TestParseContactProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContactProfileId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/contactProfiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/cOnTaCtPrOfIlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/contactProfiles/contactProfileValue", + Expected: &ContactProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContactProfileName: "contactProfileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/contactProfiles/contactProfileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/cOnTaCtPrOfIlEs/cOnTaCtPrOfIlEvAlUe", + Expected: &ContactProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContactProfileName: "cOnTaCtPrOfIlEvAlUe", + }, + }, + { + // 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.oRbItAl/cOnTaCtPrOfIlEs/cOnTaCtPrOfIlEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContactProfileIDInsensitively(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.ContactProfileName != v.Expected.ContactProfileName { + t.Fatalf("Expected %q but got %q for ContactProfileName", v.Expected.ContactProfileName, actual.ContactProfileName) + } + + } +} + +func TestSegmentsForContactProfileId(t *testing.T) { + segments := ContactProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContactProfileId 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/orbital/2022-11-01/contactprofile/method_contactprofilescreateorupdate_autorest.go b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilescreateorupdate_autorest.go new file mode 100644 index 00000000000..5a08e142f91 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilescreateorupdate_autorest.go @@ -0,0 +1,79 @@ +package contactprofile + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesCreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ContactProfilesCreateOrUpdate ... +func (c ContactProfileClient) ContactProfilesCreateOrUpdate(ctx context.Context, id ContactProfileId, input ContactProfile) (result ContactProfilesCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForContactProfilesCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesCreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForContactProfilesCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ContactProfilesCreateOrUpdateThenPoll performs ContactProfilesCreateOrUpdate then polls until it's completed +func (c ContactProfileClient) ContactProfilesCreateOrUpdateThenPoll(ctx context.Context, id ContactProfileId, input ContactProfile) error { + result, err := c.ContactProfilesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ContactProfilesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ContactProfilesCreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForContactProfilesCreateOrUpdate prepares the ContactProfilesCreateOrUpdate request. +func (c ContactProfileClient) preparerForContactProfilesCreateOrUpdate(ctx context.Context, id ContactProfileId, input ContactProfile) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForContactProfilesCreateOrUpdate sends the ContactProfilesCreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c ContactProfileClient) senderForContactProfilesCreateOrUpdate(ctx context.Context, req *http.Request) (future ContactProfilesCreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesdelete_autorest.go b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesdelete_autorest.go new file mode 100644 index 00000000000..08f2d705f09 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesdelete_autorest.go @@ -0,0 +1,78 @@ +package contactprofile + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesDeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ContactProfilesDelete ... +func (c ContactProfileClient) ContactProfilesDelete(ctx context.Context, id ContactProfileId) (result ContactProfilesDeleteOperationResponse, err error) { + req, err := c.preparerForContactProfilesDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForContactProfilesDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ContactProfilesDeleteThenPoll performs ContactProfilesDelete then polls until it's completed +func (c ContactProfileClient) ContactProfilesDeleteThenPoll(ctx context.Context, id ContactProfileId) error { + result, err := c.ContactProfilesDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing ContactProfilesDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ContactProfilesDelete: %+v", err) + } + + return nil +} + +// preparerForContactProfilesDelete prepares the ContactProfilesDelete request. +func (c ContactProfileClient) preparerForContactProfilesDelete(ctx context.Context, id ContactProfileId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForContactProfilesDelete sends the ContactProfilesDelete request. The method will close the +// http.Response Body if it receives an error. +func (c ContactProfileClient) senderForContactProfilesDelete(ctx context.Context, req *http.Request) (future ContactProfilesDeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesget_autorest.go b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesget_autorest.go new file mode 100644 index 00000000000..200c00a149d --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesget_autorest.go @@ -0,0 +1,68 @@ +package contactprofile + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesGetOperationResponse struct { + HttpResponse *http.Response + Model *ContactProfile +} + +// ContactProfilesGet ... +func (c ContactProfileClient) ContactProfilesGet(ctx context.Context, id ContactProfileId) (result ContactProfilesGetOperationResponse, err error) { + req, err := c.preparerForContactProfilesGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForContactProfilesGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForContactProfilesGet prepares the ContactProfilesGet request. +func (c ContactProfileClient) preparerForContactProfilesGet(ctx context.Context, id ContactProfileId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForContactProfilesGet handles the response to the ContactProfilesGet request. The method always +// closes the http.Response Body. +func (c ContactProfileClient) responderForContactProfilesGet(resp *http.Response) (result ContactProfilesGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofileslist_autorest.go b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofileslist_autorest.go new file mode 100644 index 00000000000..247e74550b9 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofileslist_autorest.go @@ -0,0 +1,187 @@ +package contactprofile + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesListOperationResponse struct { + HttpResponse *http.Response + Model *[]ContactProfile + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ContactProfilesListOperationResponse, error) +} + +type ContactProfilesListCompleteResult struct { + Items []ContactProfile +} + +func (r ContactProfilesListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ContactProfilesListOperationResponse) LoadMore(ctx context.Context) (resp ContactProfilesListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ContactProfilesList ... +func (c ContactProfileClient) ContactProfilesList(ctx context.Context, id commonids.ResourceGroupId) (resp ContactProfilesListOperationResponse, err error) { + req, err := c.preparerForContactProfilesList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForContactProfilesList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForContactProfilesList prepares the ContactProfilesList request. +func (c ContactProfileClient) preparerForContactProfilesList(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Orbital/contactProfiles", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForContactProfilesListWithNextLink prepares the ContactProfilesList request with the given nextLink token. +func (c ContactProfileClient) preparerForContactProfilesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForContactProfilesList handles the response to the ContactProfilesList request. The method always +// closes the http.Response Body. +func (c ContactProfileClient) responderForContactProfilesList(resp *http.Response) (result ContactProfilesListOperationResponse, err error) { + type page struct { + Values []ContactProfile `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ContactProfilesListOperationResponse, err error) { + req, err := c.preparerForContactProfilesListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForContactProfilesList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ContactProfilesListComplete retrieves all of the results into a single object +func (c ContactProfileClient) ContactProfilesListComplete(ctx context.Context, id commonids.ResourceGroupId) (ContactProfilesListCompleteResult, error) { + return c.ContactProfilesListCompleteMatchingPredicate(ctx, id, ContactProfileOperationPredicate{}) +} + +// ContactProfilesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ContactProfileClient) ContactProfilesListCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ContactProfileOperationPredicate) (resp ContactProfilesListCompleteResult, err error) { + items := make([]ContactProfile, 0) + + page, err := c.ContactProfilesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ContactProfilesListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofileslistbysubscription_autorest.go b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofileslistbysubscription_autorest.go new file mode 100644 index 00000000000..4e33b1767ed --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofileslistbysubscription_autorest.go @@ -0,0 +1,187 @@ +package contactprofile + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ContactProfile + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ContactProfilesListBySubscriptionOperationResponse, error) +} + +type ContactProfilesListBySubscriptionCompleteResult struct { + Items []ContactProfile +} + +func (r ContactProfilesListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ContactProfilesListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ContactProfilesListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ContactProfilesListBySubscription ... +func (c ContactProfileClient) ContactProfilesListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ContactProfilesListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForContactProfilesListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForContactProfilesListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForContactProfilesListBySubscription prepares the ContactProfilesListBySubscription request. +func (c ContactProfileClient) preparerForContactProfilesListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Orbital/contactProfiles", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForContactProfilesListBySubscriptionWithNextLink prepares the ContactProfilesListBySubscription request with the given nextLink token. +func (c ContactProfileClient) preparerForContactProfilesListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForContactProfilesListBySubscription handles the response to the ContactProfilesListBySubscription request. The method always +// closes the http.Response Body. +func (c ContactProfileClient) responderForContactProfilesListBySubscription(resp *http.Response) (result ContactProfilesListBySubscriptionOperationResponse, err error) { + type page struct { + Values []ContactProfile `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ContactProfilesListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForContactProfilesListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForContactProfilesListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ContactProfilesListBySubscriptionComplete retrieves all of the results into a single object +func (c ContactProfileClient) ContactProfilesListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ContactProfilesListBySubscriptionCompleteResult, error) { + return c.ContactProfilesListBySubscriptionCompleteMatchingPredicate(ctx, id, ContactProfileOperationPredicate{}) +} + +// ContactProfilesListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ContactProfileClient) ContactProfilesListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ContactProfileOperationPredicate) (resp ContactProfilesListBySubscriptionCompleteResult, err error) { + items := make([]ContactProfile, 0) + + page, err := c.ContactProfilesListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ContactProfilesListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesupdatetags_autorest.go b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesupdatetags_autorest.go new file mode 100644 index 00000000000..8a23aecf55b --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/method_contactprofilesupdatetags_autorest.go @@ -0,0 +1,79 @@ +package contactprofile + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesUpdateTagsOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ContactProfilesUpdateTags ... +func (c ContactProfileClient) ContactProfilesUpdateTags(ctx context.Context, id ContactProfileId, input TagsObject) (result ContactProfilesUpdateTagsOperationResponse, err error) { + req, err := c.preparerForContactProfilesUpdateTags(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesUpdateTags", nil, "Failure preparing request") + return + } + + result, err = c.senderForContactProfilesUpdateTags(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "contactprofile.ContactProfileClient", "ContactProfilesUpdateTags", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ContactProfilesUpdateTagsThenPoll performs ContactProfilesUpdateTags then polls until it's completed +func (c ContactProfileClient) ContactProfilesUpdateTagsThenPoll(ctx context.Context, id ContactProfileId, input TagsObject) error { + result, err := c.ContactProfilesUpdateTags(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ContactProfilesUpdateTags: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ContactProfilesUpdateTags: %+v", err) + } + + return nil +} + +// preparerForContactProfilesUpdateTags prepares the ContactProfilesUpdateTags request. +func (c ContactProfileClient) preparerForContactProfilesUpdateTags(ctx context.Context, id ContactProfileId, input TagsObject) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForContactProfilesUpdateTags sends the ContactProfilesUpdateTags request. The method will close the +// http.Response Body if it receives an error. +func (c ContactProfileClient) senderForContactProfilesUpdateTags(ctx context.Context, req *http.Request) (future ContactProfilesUpdateTagsOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofile.go b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofile.go new file mode 100644 index 00000000000..65a04a570dc --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofile.go @@ -0,0 +1,18 @@ +package contactprofile + +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 ContactProfile struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties ContactProfilesProperties `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/orbital/2022-11-01/contactprofile/model_contactprofilelink.go b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilelink.go new file mode 100644 index 00000000000..b18c81d6900 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilelink.go @@ -0,0 +1,13 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfileLink struct { + Channels []ContactProfileLinkChannel `json:"channels"` + Direction Direction `json:"direction"` + EirpdBW *float64 `json:"eirpdBW,omitempty"` + GainOverTemperature *float64 `json:"gainOverTemperature,omitempty"` + Name string `json:"name"` + Polarization Polarization `json:"polarization"` +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilelinkchannel.go b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilelinkchannel.go new file mode 100644 index 00000000000..f20d7dbac48 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilelinkchannel.go @@ -0,0 +1,15 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfileLinkChannel struct { + BandwidthMHz float64 `json:"bandwidthMHz"` + CenterFrequencyMHz float64 `json:"centerFrequencyMHz"` + DecodingConfiguration *string `json:"decodingConfiguration,omitempty"` + DemodulationConfiguration *string `json:"demodulationConfiguration,omitempty"` + EncodingConfiguration *string `json:"encodingConfiguration,omitempty"` + EndPoint EndPoint `json:"endPoint"` + ModulationConfiguration *string `json:"modulationConfiguration,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilesproperties.go b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilesproperties.go new file mode 100644 index 00000000000..73496ef6a92 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilesproperties.go @@ -0,0 +1,15 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesProperties struct { + AutoTrackingConfiguration *AutoTrackingConfiguration `json:"autoTrackingConfiguration,omitempty"` + EventHubUri *string `json:"eventHubUri,omitempty"` + Links []ContactProfileLink `json:"links"` + MinimumElevationDegrees *float64 `json:"minimumElevationDegrees,omitempty"` + MinimumViableContactDuration *string `json:"minimumViableContactDuration,omitempty"` + NetworkConfiguration ContactProfilesPropertiesNetworkConfiguration `json:"networkConfiguration"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ThirdPartyConfigurations *[]ContactProfileThirdPartyConfiguration `json:"thirdPartyConfigurations,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilespropertiesnetworkconfiguration.go b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilespropertiesnetworkconfiguration.go new file mode 100644 index 00000000000..143070a41e2 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilespropertiesnetworkconfiguration.go @@ -0,0 +1,8 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfilesPropertiesNetworkConfiguration struct { + SubnetId string `json:"subnetId"` +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilethirdpartyconfiguration.go b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilethirdpartyconfiguration.go new file mode 100644 index 00000000000..13994fbeb26 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_contactprofilethirdpartyconfiguration.go @@ -0,0 +1,9 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfileThirdPartyConfiguration struct { + MissionConfiguration string `json:"missionConfiguration"` + ProviderName string `json:"providerName"` +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/model_endpoint.go b/resource-manager/orbital/2022-11-01/contactprofile/model_endpoint.go new file mode 100644 index 00000000000..064842e450a --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_endpoint.go @@ -0,0 +1,11 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndPoint struct { + EndPointName string `json:"endPointName"` + IPAddress string `json:"ipAddress"` + Port string `json:"port"` + Protocol Protocol `json:"protocol"` +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/model_tagsobject.go b/resource-manager/orbital/2022-11-01/contactprofile/model_tagsobject.go new file mode 100644 index 00000000000..f6ef8146e49 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/model_tagsobject.go @@ -0,0 +1,8 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsObject struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/contactprofile/predicates.go b/resource-manager/orbital/2022-11-01/contactprofile/predicates.go new file mode 100644 index 00000000000..087e26c90b7 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/predicates.go @@ -0,0 +1,32 @@ +package contactprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContactProfileOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ContactProfileOperationPredicate) Matches(input ContactProfile) bool { + + 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/orbital/2022-11-01/contactprofile/version.go b/resource-manager/orbital/2022-11-01/contactprofile/version.go new file mode 100644 index 00000000000..2b4ad08b2af --- /dev/null +++ b/resource-manager/orbital/2022-11-01/contactprofile/version.go @@ -0,0 +1,12 @@ +package contactprofile + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contactprofile/%s", defaultApiVersion) +} diff --git a/resource-manager/orbital/2022-11-01/groundstation/README.md b/resource-manager/orbital/2022-11-01/groundstation/README.md new file mode 100644 index 00000000000..78c9a6e2ce2 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/groundstation` Documentation + +The `groundstation` SDK allows for interaction with the Azure Resource Manager Service `orbital` (API Version `2022-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/orbital/2022-11-01/groundstation" +``` + + +### Client Initialization + +```go +client := groundstation.NewGroundStationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroundStationClient.AvailableGroundStationsListByCapability` + +```go +ctx := context.TODO() +id := groundstation.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.AvailableGroundStationsListByCapability(ctx, id, groundstation.DefaultAvailableGroundStationsListByCapabilityOperationOptions())` can be used to do batched pagination +items, err := client.AvailableGroundStationsListByCapabilityComplete(ctx, id, groundstation.DefaultAvailableGroundStationsListByCapabilityOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/orbital/2022-11-01/groundstation/client.go b/resource-manager/orbital/2022-11-01/groundstation/client.go new file mode 100644 index 00000000000..aa6f10df6e5 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/client.go @@ -0,0 +1,18 @@ +package groundstation + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroundStationClient struct { + Client autorest.Client + baseUri string +} + +func NewGroundStationClientWithBaseURI(endpoint string) GroundStationClient { + return GroundStationClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/orbital/2022-11-01/groundstation/constants.go b/resource-manager/orbital/2022-11-01/groundstation/constants.go new file mode 100644 index 00000000000..8df58c6d329 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/constants.go @@ -0,0 +1,62 @@ +package groundstation + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CapabilityParameter string + +const ( + CapabilityParameterCommunication CapabilityParameter = "Communication" + CapabilityParameterEarthObservation CapabilityParameter = "EarthObservation" +) + +func PossibleValuesForCapabilityParameter() []string { + return []string{ + string(CapabilityParameterCommunication), + string(CapabilityParameterEarthObservation), + } +} + +func parseCapabilityParameter(input string) (*CapabilityParameter, error) { + vals := map[string]CapabilityParameter{ + "communication": CapabilityParameterCommunication, + "earthobservation": CapabilityParameterEarthObservation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CapabilityParameter(input) + return &out, nil +} + +type ReleaseMode string + +const ( + ReleaseModeGA ReleaseMode = "GA" + ReleaseModePreview ReleaseMode = "Preview" +) + +func PossibleValuesForReleaseMode() []string { + return []string{ + string(ReleaseModeGA), + string(ReleaseModePreview), + } +} + +func parseReleaseMode(input string) (*ReleaseMode, error) { + vals := map[string]ReleaseMode{ + "ga": ReleaseModeGA, + "preview": ReleaseModePreview, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReleaseMode(input) + return &out, nil +} diff --git a/resource-manager/orbital/2022-11-01/groundstation/method_availablegroundstationslistbycapability_autorest.go b/resource-manager/orbital/2022-11-01/groundstation/method_availablegroundstationslistbycapability_autorest.go new file mode 100644 index 00000000000..2ef8b5ea5d4 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/method_availablegroundstationslistbycapability_autorest.go @@ -0,0 +1,216 @@ +package groundstation + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableGroundStationsListByCapabilityOperationResponse struct { + HttpResponse *http.Response + Model *[]AvailableGroundStation + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (AvailableGroundStationsListByCapabilityOperationResponse, error) +} + +type AvailableGroundStationsListByCapabilityCompleteResult struct { + Items []AvailableGroundStation +} + +func (r AvailableGroundStationsListByCapabilityOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r AvailableGroundStationsListByCapabilityOperationResponse) LoadMore(ctx context.Context) (resp AvailableGroundStationsListByCapabilityOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type AvailableGroundStationsListByCapabilityOperationOptions struct { + Capability *CapabilityParameter +} + +func DefaultAvailableGroundStationsListByCapabilityOperationOptions() AvailableGroundStationsListByCapabilityOperationOptions { + return AvailableGroundStationsListByCapabilityOperationOptions{} +} + +func (o AvailableGroundStationsListByCapabilityOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o AvailableGroundStationsListByCapabilityOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Capability != nil { + out["capability"] = *o.Capability + } + + return out +} + +// AvailableGroundStationsListByCapability ... +func (c GroundStationClient) AvailableGroundStationsListByCapability(ctx context.Context, id commonids.SubscriptionId, options AvailableGroundStationsListByCapabilityOperationOptions) (resp AvailableGroundStationsListByCapabilityOperationResponse, err error) { + req, err := c.preparerForAvailableGroundStationsListByCapability(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "groundstation.GroundStationClient", "AvailableGroundStationsListByCapability", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "groundstation.GroundStationClient", "AvailableGroundStationsListByCapability", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForAvailableGroundStationsListByCapability(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "groundstation.GroundStationClient", "AvailableGroundStationsListByCapability", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForAvailableGroundStationsListByCapability prepares the AvailableGroundStationsListByCapability request. +func (c GroundStationClient) preparerForAvailableGroundStationsListByCapability(ctx context.Context, id commonids.SubscriptionId, options AvailableGroundStationsListByCapabilityOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Orbital/availableGroundStations", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForAvailableGroundStationsListByCapabilityWithNextLink prepares the AvailableGroundStationsListByCapability request with the given nextLink token. +func (c GroundStationClient) preparerForAvailableGroundStationsListByCapabilityWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForAvailableGroundStationsListByCapability handles the response to the AvailableGroundStationsListByCapability request. The method always +// closes the http.Response Body. +func (c GroundStationClient) responderForAvailableGroundStationsListByCapability(resp *http.Response) (result AvailableGroundStationsListByCapabilityOperationResponse, err error) { + type page struct { + Values []AvailableGroundStation `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result AvailableGroundStationsListByCapabilityOperationResponse, err error) { + req, err := c.preparerForAvailableGroundStationsListByCapabilityWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "groundstation.GroundStationClient", "AvailableGroundStationsListByCapability", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "groundstation.GroundStationClient", "AvailableGroundStationsListByCapability", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForAvailableGroundStationsListByCapability(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "groundstation.GroundStationClient", "AvailableGroundStationsListByCapability", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// AvailableGroundStationsListByCapabilityComplete retrieves all of the results into a single object +func (c GroundStationClient) AvailableGroundStationsListByCapabilityComplete(ctx context.Context, id commonids.SubscriptionId, options AvailableGroundStationsListByCapabilityOperationOptions) (AvailableGroundStationsListByCapabilityCompleteResult, error) { + return c.AvailableGroundStationsListByCapabilityCompleteMatchingPredicate(ctx, id, options, AvailableGroundStationOperationPredicate{}) +} + +// AvailableGroundStationsListByCapabilityCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c GroundStationClient) AvailableGroundStationsListByCapabilityCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options AvailableGroundStationsListByCapabilityOperationOptions, predicate AvailableGroundStationOperationPredicate) (resp AvailableGroundStationsListByCapabilityCompleteResult, err error) { + items := make([]AvailableGroundStation, 0) + + page, err := c.AvailableGroundStationsListByCapability(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := AvailableGroundStationsListByCapabilityCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/orbital/2022-11-01/groundstation/model_availablegroundstation.go b/resource-manager/orbital/2022-11-01/groundstation/model_availablegroundstation.go new file mode 100644 index 00000000000..c3cecc6381a --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/model_availablegroundstation.go @@ -0,0 +1,12 @@ +package groundstation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableGroundStation struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties AvailableGroundStationProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/groundstation/model_availablegroundstationproperties.go b/resource-manager/orbital/2022-11-01/groundstation/model_availablegroundstationproperties.go new file mode 100644 index 00000000000..618c8f38678 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/model_availablegroundstationproperties.go @@ -0,0 +1,13 @@ +package groundstation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableGroundStationProperties struct { + AltitudeMeters *float64 `json:"altitudeMeters,omitempty"` + City *string `json:"city,omitempty"` + LatitudeDegrees *float64 `json:"latitudeDegrees,omitempty"` + LongitudeDegrees *float64 `json:"longitudeDegrees,omitempty"` + ProviderName *string `json:"providerName,omitempty"` + ReleaseMode *ReleaseMode `json:"releaseMode,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/groundstation/predicates.go b/resource-manager/orbital/2022-11-01/groundstation/predicates.go new file mode 100644 index 00000000000..2e49f722062 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/predicates.go @@ -0,0 +1,32 @@ +package groundstation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableGroundStationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p AvailableGroundStationOperationPredicate) Matches(input AvailableGroundStation) bool { + + 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/orbital/2022-11-01/groundstation/version.go b/resource-manager/orbital/2022-11-01/groundstation/version.go new file mode 100644 index 00000000000..d1ad6a03aac --- /dev/null +++ b/resource-manager/orbital/2022-11-01/groundstation/version.go @@ -0,0 +1,12 @@ +package groundstation + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/groundstation/%s", defaultApiVersion) +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/README.md b/resource-manager/orbital/2022-11-01/spacecraft/README.md new file mode 100644 index 00000000000..b6bdd4f0447 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/orbital/2022-11-01/spacecraft` Documentation + +The `spacecraft` SDK allows for interaction with the Azure Resource Manager Service `orbital` (API Version `2022-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/orbital/2022-11-01/spacecraft" +``` + + +### Client Initialization + +```go +client := spacecraft.NewSpacecraftClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SpacecraftClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := spacecraft.NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + +payload := spacecraft.Spacecraft{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SpacecraftClient.Delete` + +```go +ctx := context.TODO() +id := spacecraft.NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SpacecraftClient.Get` + +```go +ctx := context.TODO() +id := spacecraft.NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + +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: `SpacecraftClient.List` + +```go +ctx := context.TODO() +id := spacecraft.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// 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: `SpacecraftClient.ListBySubscription` + +```go +ctx := context.TODO() +id := spacecraft.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SpacecraftClient.UpdateTags` + +```go +ctx := context.TODO() +id := spacecraft.NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + +payload := spacecraft.TagsObject{ + // ... +} + + +if err := client.UpdateTagsThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/orbital/2022-11-01/spacecraft/client.go b/resource-manager/orbital/2022-11-01/spacecraft/client.go new file mode 100644 index 00000000000..b5c2ccabab6 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/client.go @@ -0,0 +1,18 @@ +package spacecraft + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SpacecraftClient struct { + Client autorest.Client + baseUri string +} + +func NewSpacecraftClientWithBaseURI(endpoint string) SpacecraftClient { + return SpacecraftClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/constants.go b/resource-manager/orbital/2022-11-01/spacecraft/constants.go new file mode 100644 index 00000000000..20e58a4ac9c --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/constants.go @@ -0,0 +1,108 @@ +package spacecraft + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Direction string + +const ( + DirectionDownlink Direction = "Downlink" + DirectionUplink Direction = "Uplink" +) + +func PossibleValuesForDirection() []string { + return []string{ + string(DirectionDownlink), + string(DirectionUplink), + } +} + +func parseDirection(input string) (*Direction, error) { + vals := map[string]Direction{ + "downlink": DirectionDownlink, + "uplink": DirectionUplink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Direction(input) + return &out, nil +} + +type Polarization string + +const ( + PolarizationLHCP Polarization = "LHCP" + PolarizationLinearHorizontal Polarization = "linearHorizontal" + PolarizationLinearVertical Polarization = "linearVertical" + PolarizationRHCP Polarization = "RHCP" +) + +func PossibleValuesForPolarization() []string { + return []string{ + string(PolarizationLHCP), + string(PolarizationLinearHorizontal), + string(PolarizationLinearVertical), + string(PolarizationRHCP), + } +} + +func parsePolarization(input string) (*Polarization, error) { + vals := map[string]Polarization{ + "lhcp": PolarizationLHCP, + "linearhorizontal": PolarizationLinearHorizontal, + "linearvertical": PolarizationLinearVertical, + "rhcp": PolarizationRHCP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Polarization(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "canceled" + ProvisioningStateCreating ProvisioningState = "creating" + ProvisioningStateDeleting ProvisioningState = "deleting" + ProvisioningStateFailed ProvisioningState = "failed" + ProvisioningStateSucceeded ProvisioningState = "succeeded" + ProvisioningStateUpdating ProvisioningState = "updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "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/orbital/2022-11-01/spacecraft/id_spacecraft.go b/resource-manager/orbital/2022-11-01/spacecraft/id_spacecraft.go new file mode 100644 index 00000000000..9f9cad58179 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/id_spacecraft.go @@ -0,0 +1,127 @@ +package spacecraft + +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 = SpacecraftId{} + +// SpacecraftId is a struct representing the Resource ID for a Spacecraft +type SpacecraftId struct { + SubscriptionId string + ResourceGroupName string + SpacecraftName string +} + +// NewSpacecraftID returns a new SpacecraftId struct +func NewSpacecraftID(subscriptionId string, resourceGroupName string, spacecraftName string) SpacecraftId { + return SpacecraftId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SpacecraftName: spacecraftName, + } +} + +// ParseSpacecraftID parses 'input' into a SpacecraftId +func ParseSpacecraftID(input string) (*SpacecraftId, error) { + parser := resourceids.NewParserFromResourceIdType(SpacecraftId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SpacecraftId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SpacecraftName, ok = parsed.Parsed["spacecraftName"]; !ok { + return nil, fmt.Errorf("the segment 'spacecraftName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSpacecraftIDInsensitively parses 'input' case-insensitively into a SpacecraftId +// note: this method should only be used for API response data and not user input +func ParseSpacecraftIDInsensitively(input string) (*SpacecraftId, error) { + parser := resourceids.NewParserFromResourceIdType(SpacecraftId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SpacecraftId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SpacecraftName, ok = parsed.Parsed["spacecraftName"]; !ok { + return nil, fmt.Errorf("the segment 'spacecraftName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSpacecraftID checks that 'input' can be parsed as a Spacecraft ID +func ValidateSpacecraftID(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 := ParseSpacecraftID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Spacecraft ID +func (id SpacecraftId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Orbital/spacecrafts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SpacecraftName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Spacecraft ID +func (id SpacecraftId) 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("staticMicrosoftOrbital", "Microsoft.Orbital", "Microsoft.Orbital"), + resourceids.StaticSegment("staticSpacecrafts", "spacecrafts", "spacecrafts"), + resourceids.UserSpecifiedSegment("spacecraftName", "spacecraftValue"), + } +} + +// String returns a human-readable description of this Spacecraft ID +func (id SpacecraftId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Spacecraft Name: %q", id.SpacecraftName), + } + return fmt.Sprintf("Spacecraft (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/id_spacecraft_test.go b/resource-manager/orbital/2022-11-01/spacecraft/id_spacecraft_test.go new file mode 100644 index 00000000000..a1ce203edc6 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/id_spacecraft_test.go @@ -0,0 +1,282 @@ +package spacecraft + +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 = SpacecraftId{} + +func TestNewSpacecraftID(t *testing.T) { + id := NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue") + + 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.SpacecraftName != "spacecraftValue" { + t.Fatalf("Expected %q but got %q for Segment 'SpacecraftName'", id.SpacecraftName, "spacecraftValue") + } +} + +func TestFormatSpacecraftID(t *testing.T) { + actual := NewSpacecraftID("12345678-1234-9876-4563-123456789012", "example-resource-group", "spacecraftValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSpacecraftID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpacecraftId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue", + Expected: &SpacecraftId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SpacecraftName: "spacecraftValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSpacecraftID(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.SpacecraftName != v.Expected.SpacecraftName { + t.Fatalf("Expected %q but got %q for SpacecraftName", v.Expected.SpacecraftName, actual.SpacecraftName) + } + + } +} + +func TestParseSpacecraftIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SpacecraftId + }{ + { + // 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.Orbital", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue", + Expected: &SpacecraftId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SpacecraftName: "spacecraftValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Orbital/spacecrafts/spacecraftValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe", + Expected: &SpacecraftId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SpacecraftName: "sPaCeCrAfTvAlUe", + }, + }, + { + // 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.oRbItAl/sPaCeCrAfTs/sPaCeCrAfTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSpacecraftIDInsensitively(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.SpacecraftName != v.Expected.SpacecraftName { + t.Fatalf("Expected %q but got %q for SpacecraftName", v.Expected.SpacecraftName, actual.SpacecraftName) + } + + } +} + +func TestSegmentsForSpacecraftId(t *testing.T) { + segments := SpacecraftId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SpacecraftId 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/orbital/2022-11-01/spacecraft/method_createorupdate_autorest.go b/resource-manager/orbital/2022-11-01/spacecraft/method_createorupdate_autorest.go new file mode 100644 index 00000000000..7b56cad06ba --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package spacecraft + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c SpacecraftClient) CreateOrUpdate(ctx context.Context, id SpacecraftId, input Spacecraft) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c SpacecraftClient) CreateOrUpdateThenPoll(ctx context.Context, id SpacecraftId, input Spacecraft) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c SpacecraftClient) preparerForCreateOrUpdate(ctx context.Context, id SpacecraftId, input Spacecraft) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c SpacecraftClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/method_delete_autorest.go b/resource-manager/orbital/2022-11-01/spacecraft/method_delete_autorest.go new file mode 100644 index 00000000000..c2ee787941e --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/method_delete_autorest.go @@ -0,0 +1,78 @@ +package spacecraft + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c SpacecraftClient) Delete(ctx context.Context, id SpacecraftId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SpacecraftClient) DeleteThenPoll(ctx context.Context, id SpacecraftId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c SpacecraftClient) preparerForDelete(ctx context.Context, id SpacecraftId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c SpacecraftClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/method_get_autorest.go b/resource-manager/orbital/2022-11-01/spacecraft/method_get_autorest.go new file mode 100644 index 00000000000..7327081e66a --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/method_get_autorest.go @@ -0,0 +1,68 @@ +package spacecraft + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Spacecraft +} + +// Get ... +func (c SpacecraftClient) Get(ctx context.Context, id SpacecraftId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c SpacecraftClient) preparerForGet(ctx context.Context, id SpacecraftId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c SpacecraftClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/method_list_autorest.go b/resource-manager/orbital/2022-11-01/spacecraft/method_list_autorest.go new file mode 100644 index 00000000000..dbd038c9975 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/method_list_autorest.go @@ -0,0 +1,187 @@ +package spacecraft + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Spacecraft + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Spacecraft +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c SpacecraftClient) List(ctx context.Context, id commonids.ResourceGroupId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c SpacecraftClient) preparerForList(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Orbital/spacecrafts", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c SpacecraftClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c SpacecraftClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Spacecraft `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c SpacecraftClient) ListComplete(ctx context.Context, id commonids.ResourceGroupId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SpacecraftOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SpacecraftClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SpacecraftOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Spacecraft, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/method_listbysubscription_autorest.go b/resource-manager/orbital/2022-11-01/spacecraft/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..fd75f9d77a1 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/method_listbysubscription_autorest.go @@ -0,0 +1,187 @@ +package spacecraft + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]Spacecraft + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []Spacecraft +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c SpacecraftClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c SpacecraftClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Orbital/spacecrafts", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c SpacecraftClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c SpacecraftClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []Spacecraft `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c SpacecraftClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, SpacecraftOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SpacecraftClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SpacecraftOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]Spacecraft, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/method_updatetags_autorest.go b/resource-manager/orbital/2022-11-01/spacecraft/method_updatetags_autorest.go new file mode 100644 index 00000000000..bc69cc2c5c0 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/method_updatetags_autorest.go @@ -0,0 +1,79 @@ +package spacecraft + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateTagsOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// UpdateTags ... +func (c SpacecraftClient) UpdateTags(ctx context.Context, id SpacecraftId, input TagsObject) (result UpdateTagsOperationResponse, err error) { + req, err := c.preparerForUpdateTags(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "UpdateTags", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdateTags(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "spacecraft.SpacecraftClient", "UpdateTags", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateTagsThenPoll performs UpdateTags then polls until it's completed +func (c SpacecraftClient) UpdateTagsThenPoll(ctx context.Context, id SpacecraftId, input TagsObject) error { + result, err := c.UpdateTags(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UpdateTags: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after UpdateTags: %+v", err) + } + + return nil +} + +// preparerForUpdateTags prepares the UpdateTags request. +func (c SpacecraftClient) preparerForUpdateTags(ctx context.Context, id SpacecraftId, input TagsObject) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdateTags sends the UpdateTags request. The method will close the +// http.Response Body if it receives an error. +func (c SpacecraftClient) senderForUpdateTags(ctx context.Context, req *http.Request) (future UpdateTagsOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/model_authorizedgroundstation.go b/resource-manager/orbital/2022-11-01/spacecraft/model_authorizedgroundstation.go new file mode 100644 index 00000000000..b13297d7774 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/model_authorizedgroundstation.go @@ -0,0 +1,9 @@ +package spacecraft + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizedGroundstation struct { + ExpirationDate string `json:"expirationDate"` + GroundStation string `json:"groundStation"` +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraft.go b/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraft.go new file mode 100644 index 00000000000..487b77933cf --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraft.go @@ -0,0 +1,18 @@ +package spacecraft + +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 Spacecraft struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties SpacecraftsProperties `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/orbital/2022-11-01/spacecraft/model_spacecraftlink.go b/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraftlink.go new file mode 100644 index 00000000000..38e673044db --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraftlink.go @@ -0,0 +1,13 @@ +package spacecraft + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SpacecraftLink struct { + Authorizations *[]AuthorizedGroundstation `json:"authorizations,omitempty"` + BandwidthMHz float64 `json:"bandwidthMHz"` + CenterFrequencyMHz float64 `json:"centerFrequencyMHz"` + Direction Direction `json:"direction"` + Name string `json:"name"` + Polarization Polarization `json:"polarization"` +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraftsproperties.go b/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraftsproperties.go new file mode 100644 index 00000000000..fce0ecf0162 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/model_spacecraftsproperties.go @@ -0,0 +1,13 @@ +package spacecraft + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SpacecraftsProperties struct { + Links []SpacecraftLink `json:"links"` + NoradId *string `json:"noradId,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + TitleLine string `json:"titleLine"` + TleLine1 string `json:"tleLine1"` + TleLine2 string `json:"tleLine2"` +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/model_tagsobject.go b/resource-manager/orbital/2022-11-01/spacecraft/model_tagsobject.go new file mode 100644 index 00000000000..8e186ae42de --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/model_tagsobject.go @@ -0,0 +1,8 @@ +package spacecraft + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsObject struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/orbital/2022-11-01/spacecraft/predicates.go b/resource-manager/orbital/2022-11-01/spacecraft/predicates.go new file mode 100644 index 00000000000..a7f29698b1c --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/predicates.go @@ -0,0 +1,32 @@ +package spacecraft + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SpacecraftOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SpacecraftOperationPredicate) Matches(input Spacecraft) bool { + + 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/orbital/2022-11-01/spacecraft/version.go b/resource-manager/orbital/2022-11-01/spacecraft/version.go new file mode 100644 index 00000000000..e8ab09d9962 --- /dev/null +++ b/resource-manager/orbital/2022-11-01/spacecraft/version.go @@ -0,0 +1,12 @@ +package spacecraft + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/spacecraft/%s", defaultApiVersion) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/client.go b/resource-manager/postgresqlhsc/2022-11-08/client.go new file mode 100644 index 00000000000..285a896d627 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/client.go @@ -0,0 +1,59 @@ +package v2022_11_08 + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/clusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/configurations" + "github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/firewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/roles" + "github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/servers" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Client struct { + Clusters *clusters.ClustersClient + Configurations *configurations.ConfigurationsClient + FirewallRules *firewallrules.FirewallRulesClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + Roles *roles.RolesClient + Servers *servers.ServersClient +} + +func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { + + clustersClient := clusters.NewClustersClientWithBaseURI(endpoint) + configureAuthFunc(&clustersClient.Client) + + configurationsClient := configurations.NewConfigurationsClientWithBaseURI(endpoint) + configureAuthFunc(&configurationsClient.Client) + + firewallRulesClient := firewallrules.NewFirewallRulesClientWithBaseURI(endpoint) + configureAuthFunc(&firewallRulesClient.Client) + + privateEndpointConnectionsClient := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(endpoint) + configureAuthFunc(&privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(endpoint) + configureAuthFunc(&privateLinkResourcesClient.Client) + + rolesClient := roles.NewRolesClientWithBaseURI(endpoint) + configureAuthFunc(&rolesClient.Client) + + serversClient := servers.NewServersClientWithBaseURI(endpoint) + configureAuthFunc(&serversClient.Client) + + return Client{ + Clusters: &clustersClient, + Configurations: &configurationsClient, + FirewallRules: &firewallRulesClient, + PrivateEndpointConnections: &privateEndpointConnectionsClient, + PrivateLinkResources: &privateLinkResourcesClient, + Roles: &rolesClient, + Servers: &serversClient, + } +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/README.md b/resource-manager/postgresqlhsc/2022-11-08/clusters/README.md new file mode 100644 index 00000000000..da20b7845a1 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/README.md @@ -0,0 +1,137 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/clusters` Documentation + +The `clusters` SDK allows for interaction with the Azure Resource Manager Service `postgresqlhsc` (API Version `2022-11-08`). + +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/postgresqlhsc/2022-11-08/clusters" +``` + + +### Client Initialization + +```go +client := clusters.NewClustersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ClustersClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := clusters.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := clusters.NameAvailabilityRequest{ + // ... +} + + +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: `ClustersClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := clusters.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +payload := clusters.Cluster{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClustersClient.Delete` + +```go +ctx := context.TODO() +id := clusters.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClustersClient.Get` + +```go +ctx := context.TODO() +id := clusters.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +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: `ClustersClient.List` + +```go +ctx := context.TODO() +id := clusters.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `ClustersClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := clusters.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ClustersClient.Update` + +```go +ctx := context.TODO() +id := clusters.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +payload := clusters.ClusterForUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/client.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/client.go new file mode 100644 index 00000000000..1e6fabf8cba --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/client.go @@ -0,0 +1,18 @@ +package clusters + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClustersClient struct { + Client autorest.Client + baseUri string +} + +func NewClustersClientWithBaseURI(endpoint string) ClustersClient { + return ClustersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/constants.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/constants.go new file mode 100644 index 00000000000..13f05f52814 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/constants.go @@ -0,0 +1,62 @@ +package clusters + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResourceType string + +const ( + CheckNameAvailabilityResourceTypeMicrosoftPointDBforPostgreSQLServerGroupsvTwo CheckNameAvailabilityResourceType = "Microsoft.DBforPostgreSQL/serverGroupsv2" +) + +func PossibleValuesForCheckNameAvailabilityResourceType() []string { + return []string{ + string(CheckNameAvailabilityResourceTypeMicrosoftPointDBforPostgreSQLServerGroupsvTwo), + } +} + +func parseCheckNameAvailabilityResourceType(input string) (*CheckNameAvailabilityResourceType, error) { + vals := map[string]CheckNameAvailabilityResourceType{ + "microsoft.dbforpostgresql/servergroupsv2": CheckNameAvailabilityResourceTypeMicrosoftPointDBforPostgreSQLServerGroupsvTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityResourceType(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/id_servergroupsv2.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/id_servergroupsv2.go new file mode 100644 index 00000000000..f5974473dcc --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/id_servergroupsv2.go @@ -0,0 +1,127 @@ +package clusters + +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 = ServerGroupsv2Id{} + +// ServerGroupsv2Id is a struct representing the Resource ID for a Server Groupsv 2 +type ServerGroupsv2Id struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string +} + +// NewServerGroupsv2ID returns a new ServerGroupsv2Id struct +func NewServerGroupsv2ID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string) ServerGroupsv2Id { + return ServerGroupsv2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + } +} + +// ParseServerGroupsv2ID parses 'input' into a ServerGroupsv2Id +func ParseServerGroupsv2ID(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerGroupsv2IDInsensitively parses 'input' case-insensitively into a ServerGroupsv2Id +// note: this method should only be used for API response data and not user input +func ParseServerGroupsv2IDInsensitively(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerGroupsv2ID checks that 'input' can be parsed as a Server Groupsv 2 ID +func ValidateServerGroupsv2ID(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 := ParseServerGroupsv2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Groupsv 2 ID +func (id ServerGroupsv2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Groupsv 2 ID +func (id ServerGroupsv2Id) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + } +} + +// String returns a human-readable description of this Server Groupsv 2 ID +func (id ServerGroupsv2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + } + return fmt.Sprintf("Server Groupsv 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/id_servergroupsv2_test.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/id_servergroupsv2_test.go new file mode 100644 index 00000000000..69c08825f9c --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/id_servergroupsv2_test.go @@ -0,0 +1,282 @@ +package clusters + +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 = ServerGroupsv2Id{} + +func TestNewServerGroupsv2ID(t *testing.T) { + id := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } +} + +func TestFormatServerGroupsv2ID(t *testing.T) { + actual := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerGroupsv2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2ID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestParseServerGroupsv2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2IDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestSegmentsForServerGroupsv2Id(t *testing.T) { + segments := ServerGroupsv2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerGroupsv2Id 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/postgresqlhsc/2022-11-08/clusters/method_checknameavailability_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_checknameavailability_autorest.go new file mode 100644 index 00000000000..49e097ad32e --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_checknameavailability_autorest.go @@ -0,0 +1,71 @@ +package clusters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + Model *NameAvailability +} + +// CheckNameAvailability ... +func (c ClustersClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input NameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + req, err := c.preparerForCheckNameAvailability(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "CheckNameAvailability", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "CheckNameAvailability", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCheckNameAvailability(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "CheckNameAvailability", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCheckNameAvailability prepares the CheckNameAvailability request. +func (c ClustersClient) preparerForCheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input NameAvailabilityRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.DBforPostgreSQL/checkNameAvailability", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCheckNameAvailability handles the response to the CheckNameAvailability request. The method always +// closes the http.Response Body. +func (c ClustersClient) responderForCheckNameAvailability(resp *http.Response) (result CheckNameAvailabilityOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/method_createorupdate_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_createorupdate_autorest.go new file mode 100644 index 00000000000..fc3a0dcccb4 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package clusters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c ClustersClient) CreateOrUpdate(ctx context.Context, id ServerGroupsv2Id, input Cluster) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ClustersClient) CreateOrUpdateThenPoll(ctx context.Context, id ServerGroupsv2Id, input Cluster) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ClustersClient) preparerForCreateOrUpdate(ctx context.Context, id ServerGroupsv2Id, input Cluster) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c ClustersClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/method_delete_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_delete_autorest.go new file mode 100644 index 00000000000..1a87de63156 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_delete_autorest.go @@ -0,0 +1,78 @@ +package clusters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ClustersClient) Delete(ctx context.Context, id ServerGroupsv2Id) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ClustersClient) DeleteThenPoll(ctx context.Context, id ServerGroupsv2Id) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ClustersClient) preparerForDelete(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ClustersClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/method_get_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_get_autorest.go new file mode 100644 index 00000000000..4f28bbb7aae --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_get_autorest.go @@ -0,0 +1,68 @@ +package clusters + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Cluster +} + +// Get ... +func (c ClustersClient) Get(ctx context.Context, id ServerGroupsv2Id) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ClustersClient) preparerForGet(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ClustersClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/method_list_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_list_autorest.go new file mode 100644 index 00000000000..3fd703ed090 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_list_autorest.go @@ -0,0 +1,187 @@ +package clusters + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Cluster + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Cluster +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ClustersClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ClustersClient) preparerForList(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ClustersClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ClustersClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Cluster `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ClustersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ClustersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ClusterOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Cluster, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/method_listbyresourcegroup_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..b24c613771e --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package clusters + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]Cluster + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []Cluster +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c ClustersClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c ClustersClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c ClustersClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c ClustersClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []Cluster `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c ClustersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ClustersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ClusterOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]Cluster, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/method_update_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_update_autorest.go new file mode 100644 index 00000000000..98f895e3271 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/method_update_autorest.go @@ -0,0 +1,79 @@ +package clusters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ClustersClient) Update(ctx context.Context, id ServerGroupsv2Id, input ClusterForUpdate) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ClustersClient) UpdateThenPoll(ctx context.Context, id ServerGroupsv2Id, input ClusterForUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ClustersClient) preparerForUpdate(ctx context.Context, id ServerGroupsv2Id, input ClusterForUpdate) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ClustersClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_cluster.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_cluster.go new file mode 100644 index 00000000000..e551e3f2e59 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_cluster.go @@ -0,0 +1,18 @@ +package clusters + +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 Cluster struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ClusterProperties `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/postgresqlhsc/2022-11-08/clusters/model_clusterforupdate.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterforupdate.go new file mode 100644 index 00000000000..630f0b1f621 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterforupdate.go @@ -0,0 +1,9 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterForUpdate struct { + Properties *ClusterPropertiesForUpdate `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterproperties.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterproperties.go new file mode 100644 index 00000000000..cd971b2ef05 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterproperties.go @@ -0,0 +1,63 @@ +package clusters + +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 ClusterProperties struct { + AdministratorLogin *string `json:"administratorLogin,omitempty"` + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + CitusVersion *string `json:"citusVersion,omitempty"` + CoordinatorEnablePublicIPAccess *bool `json:"coordinatorEnablePublicIpAccess,omitempty"` + CoordinatorServerEdition *string `json:"coordinatorServerEdition,omitempty"` + CoordinatorStorageQuotaInMb *int64 `json:"coordinatorStorageQuotaInMb,omitempty"` + CoordinatorVCores *int64 `json:"coordinatorVCores,omitempty"` + EarliestRestoreTime *string `json:"earliestRestoreTime,omitempty"` + EnableHa *bool `json:"enableHa,omitempty"` + EnableShardsOnCoordinator *bool `json:"enableShardsOnCoordinator,omitempty"` + MaintenanceWindow *MaintenanceWindow `json:"maintenanceWindow,omitempty"` + NodeCount *int64 `json:"nodeCount,omitempty"` + NodeEnablePublicIPAccess *bool `json:"nodeEnablePublicIpAccess,omitempty"` + NodeServerEdition *string `json:"nodeServerEdition,omitempty"` + NodeStorageQuotaInMb *int64 `json:"nodeStorageQuotaInMb,omitempty"` + NodeVCores *int64 `json:"nodeVCores,omitempty"` + PointInTimeUTC *string `json:"pointInTimeUTC,omitempty"` + PostgresqlVersion *string `json:"postgresqlVersion,omitempty"` + PreferredPrimaryZone *string `json:"preferredPrimaryZone,omitempty"` + PrivateEndpointConnections *[]SimplePrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ReadReplicas *[]string `json:"readReplicas,omitempty"` + ServerNames *[]ServerNameItem `json:"serverNames,omitempty"` + SourceLocation *string `json:"sourceLocation,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + State *string `json:"state,omitempty"` +} + +func (o *ClusterProperties) GetEarliestRestoreTimeAsTime() (*time.Time, error) { + if o.EarliestRestoreTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetEarliestRestoreTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreTime = &formatted +} + +func (o *ClusterProperties) GetPointInTimeUTCAsTime() (*time.Time, error) { + if o.PointInTimeUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PointInTimeUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetPointInTimeUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PointInTimeUTC = &formatted +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterpropertiesforupdate.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterpropertiesforupdate.go new file mode 100644 index 00000000000..9abc4a9ebef --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_clusterpropertiesforupdate.go @@ -0,0 +1,23 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPropertiesForUpdate struct { + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + CitusVersion *string `json:"citusVersion,omitempty"` + CoordinatorEnablePublicIPAccess *bool `json:"coordinatorEnablePublicIpAccess,omitempty"` + CoordinatorServerEdition *string `json:"coordinatorServerEdition,omitempty"` + CoordinatorStorageQuotaInMb *int64 `json:"coordinatorStorageQuotaInMb,omitempty"` + CoordinatorVCores *int64 `json:"coordinatorVCores,omitempty"` + EnableHa *bool `json:"enableHa,omitempty"` + EnableShardsOnCoordinator *bool `json:"enableShardsOnCoordinator,omitempty"` + MaintenanceWindow *MaintenanceWindow `json:"maintenanceWindow,omitempty"` + NodeCount *int64 `json:"nodeCount,omitempty"` + NodeEnablePublicIPAccess *bool `json:"nodeEnablePublicIpAccess,omitempty"` + NodeServerEdition *string `json:"nodeServerEdition,omitempty"` + NodeStorageQuotaInMb *int64 `json:"nodeStorageQuotaInMb,omitempty"` + NodeVCores *int64 `json:"nodeVCores,omitempty"` + PostgresqlVersion *string `json:"postgresqlVersion,omitempty"` + PreferredPrimaryZone *string `json:"preferredPrimaryZone,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_maintenancewindow.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_maintenancewindow.go new file mode 100644 index 00000000000..bef3bf8d703 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_maintenancewindow.go @@ -0,0 +1,11 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindow struct { + CustomWindow *string `json:"customWindow,omitempty"` + DayOfWeek *int64 `json:"dayOfWeek,omitempty"` + StartHour *int64 `json:"startHour,omitempty"` + StartMinute *int64 `json:"startMinute,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_nameavailability.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_nameavailability.go new file mode 100644 index 00000000000..e6e74ed2ffa --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_nameavailability.go @@ -0,0 +1,11 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameAvailability struct { + Message *string `json:"message,omitempty"` + Name *string `json:"name,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_nameavailabilityrequest.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_nameavailabilityrequest.go new file mode 100644 index 00000000000..065de5ca09f --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_nameavailabilityrequest.go @@ -0,0 +1,9 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameAvailabilityRequest struct { + Name string `json:"name"` + Type CheckNameAvailabilityResourceType `json:"type"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privateendpointconnectionsimpleproperties.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privateendpointconnectionsimpleproperties.go new file mode 100644 index 00000000000..c88e3f35a6e --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privateendpointconnectionsimpleproperties.go @@ -0,0 +1,10 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionSimpleProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpointProperty `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privateendpointproperty.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privateendpointproperty.go new file mode 100644 index 00000000000..5da9b341454 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privateendpointproperty.go @@ -0,0 +1,8 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointProperty struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privatelinkserviceconnectionstate.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..5d6f3d63de1 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_servernameitem.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_servernameitem.go new file mode 100644 index 00000000000..3571474fac8 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_servernameitem.go @@ -0,0 +1,9 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerNameItem struct { + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/model_simpleprivateendpointconnection.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_simpleprivateendpointconnection.go new file mode 100644 index 00000000000..cb0ca63239a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/model_simpleprivateendpointconnection.go @@ -0,0 +1,16 @@ +package clusters + +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 SimplePrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionSimpleProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/clusters/predicates.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/predicates.go new file mode 100644 index 00000000000..7c9c4692854 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/predicates.go @@ -0,0 +1,32 @@ +package clusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ClusterOperationPredicate) Matches(input Cluster) bool { + + 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/postgresqlhsc/2022-11-08/clusters/version.go b/resource-manager/postgresqlhsc/2022-11-08/clusters/version.go new file mode 100644 index 00000000000..ba6590cb36b --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/clusters/version.go @@ -0,0 +1,12 @@ +package clusters + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-08" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/clusters/%s", defaultApiVersion) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/README.md b/resource-manager/postgresqlhsc/2022-11-08/configurations/README.md new file mode 100644 index 00000000000..ffb53dca92e --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/README.md @@ -0,0 +1,136 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/configurations` Documentation + +The `configurations` SDK allows for interaction with the Azure Resource Manager Service `postgresqlhsc` (API Version `2022-11-08`). + +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/postgresqlhsc/2022-11-08/configurations" +``` + + +### Client Initialization + +```go +client := configurations.NewConfigurationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ConfigurationsClient.CreateOrUpdateCoordinator` + +```go +ctx := context.TODO() +id := configurations.NewCoordinatorConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "coordinatorConfigurationValue") + +payload := configurations.ServerConfiguration{ + // ... +} + + +if err := client.CreateOrUpdateCoordinatorThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConfigurationsClient.CreateOrUpdateNode` + +```go +ctx := context.TODO() +id := configurations.NewNodeConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "nodeConfigurationValue") + +payload := configurations.ServerConfiguration{ + // ... +} + + +if err := client.CreateOrUpdateNodeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConfigurationsClient.Get` + +```go +ctx := context.TODO() +id := configurations.NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "configurationValue") + +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: `ConfigurationsClient.GetCoordinator` + +```go +ctx := context.TODO() +id := configurations.NewCoordinatorConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "coordinatorConfigurationValue") + +read, err := client.GetCoordinator(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConfigurationsClient.GetNode` + +```go +ctx := context.TODO() +id := configurations.NewNodeConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "nodeConfigurationValue") + +read, err := client.GetNode(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConfigurationsClient.ListByCluster` + +```go +ctx := context.TODO() +id := configurations.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +// alternatively `client.ListByCluster(ctx, id)` can be used to do batched pagination +items, err := client.ListByClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ConfigurationsClient.ListByServer` + +```go +ctx := context.TODO() +id := configurations.NewServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "serverValue") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/client.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/client.go new file mode 100644 index 00000000000..bbe813edd98 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/client.go @@ -0,0 +1,18 @@ +package configurations + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsClient struct { + Client autorest.Client + baseUri string +} + +func NewConfigurationsClientWithBaseURI(endpoint string) ConfigurationsClient { + return ConfigurationsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/constants.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/constants.go new file mode 100644 index 00000000000..6ec130affe3 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/constants.go @@ -0,0 +1,102 @@ +package configurations + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationDataType string + +const ( + ConfigurationDataTypeBoolean ConfigurationDataType = "Boolean" + ConfigurationDataTypeEnumeration ConfigurationDataType = "Enumeration" + ConfigurationDataTypeInteger ConfigurationDataType = "Integer" + ConfigurationDataTypeNumeric ConfigurationDataType = "Numeric" +) + +func PossibleValuesForConfigurationDataType() []string { + return []string{ + string(ConfigurationDataTypeBoolean), + string(ConfigurationDataTypeEnumeration), + string(ConfigurationDataTypeInteger), + string(ConfigurationDataTypeNumeric), + } +} + +func parseConfigurationDataType(input string) (*ConfigurationDataType, error) { + vals := map[string]ConfigurationDataType{ + "boolean": ConfigurationDataTypeBoolean, + "enumeration": ConfigurationDataTypeEnumeration, + "integer": ConfigurationDataTypeInteger, + "numeric": ConfigurationDataTypeNumeric, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfigurationDataType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateSucceeded), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "succeeded": ProvisioningStateSucceeded, + } + 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 ServerRole string + +const ( + ServerRoleCoordinator ServerRole = "Coordinator" + ServerRoleWorker ServerRole = "Worker" +) + +func PossibleValuesForServerRole() []string { + return []string{ + string(ServerRoleCoordinator), + string(ServerRoleWorker), + } +} + +func parseServerRole(input string) (*ServerRole, error) { + vals := map[string]ServerRole{ + "coordinator": ServerRoleCoordinator, + "worker": ServerRoleWorker, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerRole(input) + return &out, nil +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/id_configuration.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_configuration.go new file mode 100644 index 00000000000..2da5436b77c --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_configuration.go @@ -0,0 +1,140 @@ +package configurations + +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 = ConfigurationId{} + +// ConfigurationId is a struct representing the Resource ID for a Configuration +type ConfigurationId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + ConfigurationName string +} + +// NewConfigurationID returns a new ConfigurationId struct +func NewConfigurationID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, configurationName string) ConfigurationId { + return ConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + ConfigurationName: configurationName, + } +} + +// ParseConfigurationID parses 'input' into a ConfigurationId +func ParseConfigurationID(input string) (*ConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(ConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ConfigurationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.ConfigurationName, ok = parsed.Parsed["configurationName"]; !ok { + return nil, fmt.Errorf("the segment 'configurationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseConfigurationIDInsensitively parses 'input' case-insensitively into a ConfigurationId +// note: this method should only be used for API response data and not user input +func ParseConfigurationIDInsensitively(input string) (*ConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(ConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ConfigurationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.ConfigurationName, ok = parsed.Parsed["configurationName"]; !ok { + return nil, fmt.Errorf("the segment 'configurationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateConfigurationID checks that 'input' can be parsed as a Configuration ID +func ValidateConfigurationID(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 := ParseConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Configuration ID +func (id ConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/configurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.ConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Configuration ID +func (id ConfigurationId) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticConfigurations", "configurations", "configurations"), + resourceids.UserSpecifiedSegment("configurationName", "configurationValue"), + } +} + +// String returns a human-readable description of this Configuration ID +func (id ConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Configuration Name: %q", id.ConfigurationName), + } + return fmt.Sprintf("Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/id_configuration_test.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_configuration_test.go new file mode 100644 index 00000000000..155c8e6a451 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_configuration_test.go @@ -0,0 +1,327 @@ +package configurations + +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 = ConfigurationId{} + +func TestNewConfigurationID(t *testing.T) { + id := NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "configurationValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.ConfigurationName != "configurationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ConfigurationName'", id.ConfigurationName, "configurationValue") + } +} + +func TestFormatConfigurationID(t *testing.T) { + actual := NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "configurationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/configurations/configurationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigurationId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/configurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/configurations/configurationValue", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + ConfigurationName: "configurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/configurations/configurationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigurationID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.ConfigurationName != v.Expected.ConfigurationName { + t.Fatalf("Expected %q but got %q for ConfigurationName", v.Expected.ConfigurationName, actual.ConfigurationName) + } + + } +} + +func TestParseConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigurationId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/configurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/cOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/configurations/configurationValue", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + ConfigurationName: "configurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/configurations/configurationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/cOnFiGuRaTiOnS/cOnFiGuRaTiOnVaLuE", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + ConfigurationName: "cOnFiGuRaTiOnVaLuE", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/cOnFiGuRaTiOnS/cOnFiGuRaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigurationIDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.ConfigurationName != v.Expected.ConfigurationName { + t.Fatalf("Expected %q but got %q for ConfigurationName", v.Expected.ConfigurationName, actual.ConfigurationName) + } + + } +} + +func TestSegmentsForConfigurationId(t *testing.T) { + segments := ConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConfigurationId 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/postgresqlhsc/2022-11-08/configurations/id_coordinatorconfiguration.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_coordinatorconfiguration.go new file mode 100644 index 00000000000..56d0f409022 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_coordinatorconfiguration.go @@ -0,0 +1,140 @@ +package configurations + +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 = CoordinatorConfigurationId{} + +// CoordinatorConfigurationId is a struct representing the Resource ID for a Coordinator Configuration +type CoordinatorConfigurationId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + CoordinatorConfigurationName string +} + +// NewCoordinatorConfigurationID returns a new CoordinatorConfigurationId struct +func NewCoordinatorConfigurationID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, coordinatorConfigurationName string) CoordinatorConfigurationId { + return CoordinatorConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + CoordinatorConfigurationName: coordinatorConfigurationName, + } +} + +// ParseCoordinatorConfigurationID parses 'input' into a CoordinatorConfigurationId +func ParseCoordinatorConfigurationID(input string) (*CoordinatorConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(CoordinatorConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CoordinatorConfigurationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.CoordinatorConfigurationName, ok = parsed.Parsed["coordinatorConfigurationName"]; !ok { + return nil, fmt.Errorf("the segment 'coordinatorConfigurationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCoordinatorConfigurationIDInsensitively parses 'input' case-insensitively into a CoordinatorConfigurationId +// note: this method should only be used for API response data and not user input +func ParseCoordinatorConfigurationIDInsensitively(input string) (*CoordinatorConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(CoordinatorConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CoordinatorConfigurationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.CoordinatorConfigurationName, ok = parsed.Parsed["coordinatorConfigurationName"]; !ok { + return nil, fmt.Errorf("the segment 'coordinatorConfigurationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCoordinatorConfigurationID checks that 'input' can be parsed as a Coordinator Configuration ID +func ValidateCoordinatorConfigurationID(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 := ParseCoordinatorConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Coordinator Configuration ID +func (id CoordinatorConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/coordinatorConfigurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.CoordinatorConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Coordinator Configuration ID +func (id CoordinatorConfigurationId) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticCoordinatorConfigurations", "coordinatorConfigurations", "coordinatorConfigurations"), + resourceids.UserSpecifiedSegment("coordinatorConfigurationName", "coordinatorConfigurationValue"), + } +} + +// String returns a human-readable description of this Coordinator Configuration ID +func (id CoordinatorConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Coordinator Configuration Name: %q", id.CoordinatorConfigurationName), + } + return fmt.Sprintf("Coordinator Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/id_coordinatorconfiguration_test.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_coordinatorconfiguration_test.go new file mode 100644 index 00000000000..94426c85cbe --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_coordinatorconfiguration_test.go @@ -0,0 +1,327 @@ +package configurations + +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 = CoordinatorConfigurationId{} + +func TestNewCoordinatorConfigurationID(t *testing.T) { + id := NewCoordinatorConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "coordinatorConfigurationValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.CoordinatorConfigurationName != "coordinatorConfigurationValue" { + t.Fatalf("Expected %q but got %q for Segment 'CoordinatorConfigurationName'", id.CoordinatorConfigurationName, "coordinatorConfigurationValue") + } +} + +func TestFormatCoordinatorConfigurationID(t *testing.T) { + actual := NewCoordinatorConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "coordinatorConfigurationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/coordinatorConfigurations/coordinatorConfigurationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCoordinatorConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CoordinatorConfigurationId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/coordinatorConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/coordinatorConfigurations/coordinatorConfigurationValue", + Expected: &CoordinatorConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + CoordinatorConfigurationName: "coordinatorConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/coordinatorConfigurations/coordinatorConfigurationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCoordinatorConfigurationID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.CoordinatorConfigurationName != v.Expected.CoordinatorConfigurationName { + t.Fatalf("Expected %q but got %q for CoordinatorConfigurationName", v.Expected.CoordinatorConfigurationName, actual.CoordinatorConfigurationName) + } + + } +} + +func TestParseCoordinatorConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CoordinatorConfigurationId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/coordinatorConfigurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/cOoRdInAtOrCoNfIgUrAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/coordinatorConfigurations/coordinatorConfigurationValue", + Expected: &CoordinatorConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + CoordinatorConfigurationName: "coordinatorConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/coordinatorConfigurations/coordinatorConfigurationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/cOoRdInAtOrCoNfIgUrAtIoNs/cOoRdInAtOrCoNfIgUrAtIoNvAlUe", + Expected: &CoordinatorConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + CoordinatorConfigurationName: "cOoRdInAtOrCoNfIgUrAtIoNvAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/cOoRdInAtOrCoNfIgUrAtIoNs/cOoRdInAtOrCoNfIgUrAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCoordinatorConfigurationIDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.CoordinatorConfigurationName != v.Expected.CoordinatorConfigurationName { + t.Fatalf("Expected %q but got %q for CoordinatorConfigurationName", v.Expected.CoordinatorConfigurationName, actual.CoordinatorConfigurationName) + } + + } +} + +func TestSegmentsForCoordinatorConfigurationId(t *testing.T) { + segments := CoordinatorConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CoordinatorConfigurationId 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/postgresqlhsc/2022-11-08/configurations/id_nodeconfiguration.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_nodeconfiguration.go new file mode 100644 index 00000000000..f4951dceb5a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_nodeconfiguration.go @@ -0,0 +1,140 @@ +package configurations + +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 = NodeConfigurationId{} + +// NodeConfigurationId is a struct representing the Resource ID for a Node Configuration +type NodeConfigurationId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + NodeConfigurationName string +} + +// NewNodeConfigurationID returns a new NodeConfigurationId struct +func NewNodeConfigurationID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, nodeConfigurationName string) NodeConfigurationId { + return NodeConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + NodeConfigurationName: nodeConfigurationName, + } +} + +// ParseNodeConfigurationID parses 'input' into a NodeConfigurationId +func ParseNodeConfigurationID(input string) (*NodeConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(NodeConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := NodeConfigurationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.NodeConfigurationName, ok = parsed.Parsed["nodeConfigurationName"]; !ok { + return nil, fmt.Errorf("the segment 'nodeConfigurationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseNodeConfigurationIDInsensitively parses 'input' case-insensitively into a NodeConfigurationId +// note: this method should only be used for API response data and not user input +func ParseNodeConfigurationIDInsensitively(input string) (*NodeConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(NodeConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := NodeConfigurationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.NodeConfigurationName, ok = parsed.Parsed["nodeConfigurationName"]; !ok { + return nil, fmt.Errorf("the segment 'nodeConfigurationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateNodeConfigurationID checks that 'input' can be parsed as a Node Configuration ID +func ValidateNodeConfigurationID(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 := ParseNodeConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Node Configuration ID +func (id NodeConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/nodeConfigurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.NodeConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Node Configuration ID +func (id NodeConfigurationId) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticNodeConfigurations", "nodeConfigurations", "nodeConfigurations"), + resourceids.UserSpecifiedSegment("nodeConfigurationName", "nodeConfigurationValue"), + } +} + +// String returns a human-readable description of this Node Configuration ID +func (id NodeConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Node Configuration Name: %q", id.NodeConfigurationName), + } + return fmt.Sprintf("Node Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/id_nodeconfiguration_test.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_nodeconfiguration_test.go new file mode 100644 index 00000000000..07ce57aa15c --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_nodeconfiguration_test.go @@ -0,0 +1,327 @@ +package configurations + +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 = NodeConfigurationId{} + +func TestNewNodeConfigurationID(t *testing.T) { + id := NewNodeConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "nodeConfigurationValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.NodeConfigurationName != "nodeConfigurationValue" { + t.Fatalf("Expected %q but got %q for Segment 'NodeConfigurationName'", id.NodeConfigurationName, "nodeConfigurationValue") + } +} + +func TestFormatNodeConfigurationID(t *testing.T) { + actual := NewNodeConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "nodeConfigurationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/nodeConfigurations/nodeConfigurationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNodeConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NodeConfigurationId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/nodeConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/nodeConfigurations/nodeConfigurationValue", + Expected: &NodeConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + NodeConfigurationName: "nodeConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/nodeConfigurations/nodeConfigurationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNodeConfigurationID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.NodeConfigurationName != v.Expected.NodeConfigurationName { + t.Fatalf("Expected %q but got %q for NodeConfigurationName", v.Expected.NodeConfigurationName, actual.NodeConfigurationName) + } + + } +} + +func TestParseNodeConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NodeConfigurationId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/nodeConfigurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/nOdEcOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/nodeConfigurations/nodeConfigurationValue", + Expected: &NodeConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + NodeConfigurationName: "nodeConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/nodeConfigurations/nodeConfigurationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/nOdEcOnFiGuRaTiOnS/nOdEcOnFiGuRaTiOnVaLuE", + Expected: &NodeConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + NodeConfigurationName: "nOdEcOnFiGuRaTiOnVaLuE", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/nOdEcOnFiGuRaTiOnS/nOdEcOnFiGuRaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNodeConfigurationIDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.NodeConfigurationName != v.Expected.NodeConfigurationName { + t.Fatalf("Expected %q but got %q for NodeConfigurationName", v.Expected.NodeConfigurationName, actual.NodeConfigurationName) + } + + } +} + +func TestSegmentsForNodeConfigurationId(t *testing.T) { + segments := NodeConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NodeConfigurationId 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/postgresqlhsc/2022-11-08/configurations/id_server.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_server.go new file mode 100644 index 00000000000..9041e9e79b6 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_server.go @@ -0,0 +1,140 @@ +package configurations + +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 = ServerId{} + +// ServerId is a struct representing the Resource ID for a Server +type ServerId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + ServerName string +} + +// NewServerID returns a new ServerId struct +func NewServerID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, serverName string) ServerId { + return ServerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + ServerName: serverName, + } +} + +// ParseServerID parses 'input' into a ServerId +func ParseServerID(input string) (*ServerId, error) { + parser := resourceids.NewParserFromResourceIdType(ServerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.ServerName, ok = parsed.Parsed["serverName"]; !ok { + return nil, fmt.Errorf("the segment 'serverName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerIDInsensitively parses 'input' case-insensitively into a ServerId +// note: this method should only be used for API response data and not user input +func ParseServerIDInsensitively(input string) (*ServerId, error) { + parser := resourceids.NewParserFromResourceIdType(ServerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.ServerName, ok = parsed.Parsed["serverName"]; !ok { + return nil, fmt.Errorf("the segment 'serverName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerID checks that 'input' can be parsed as a Server ID +func ValidateServerID(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 := ParseServerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server ID +func (id ServerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/servers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.ServerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server ID +func (id ServerId) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverValue"), + } +} + +// String returns a human-readable description of this Server ID +func (id ServerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Server Name: %q", id.ServerName), + } + return fmt.Sprintf("Server (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/id_server_test.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_server_test.go new file mode 100644 index 00000000000..ca8dfad5d03 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_server_test.go @@ -0,0 +1,327 @@ +package configurations + +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 = ServerId{} + +func TestNewServerID(t *testing.T) { + id := NewServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "serverValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.ServerName != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } +} + +func TestFormatServerID(t *testing.T) { + actual := NewServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "serverValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue", + Expected: &ServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + ServerName: "serverValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + } +} + +func TestParseServerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/sErVeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue", + Expected: &ServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + ServerName: "serverValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/sErVeRs/sErVeRvAlUe", + Expected: &ServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + ServerName: "sErVeRvAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/sErVeRs/sErVeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerIDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + } +} + +func TestSegmentsForServerId(t *testing.T) { + segments := ServerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerId 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/postgresqlhsc/2022-11-08/configurations/id_servergroupsv2.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_servergroupsv2.go new file mode 100644 index 00000000000..150021e99da --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_servergroupsv2.go @@ -0,0 +1,127 @@ +package configurations + +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 = ServerGroupsv2Id{} + +// ServerGroupsv2Id is a struct representing the Resource ID for a Server Groupsv 2 +type ServerGroupsv2Id struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string +} + +// NewServerGroupsv2ID returns a new ServerGroupsv2Id struct +func NewServerGroupsv2ID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string) ServerGroupsv2Id { + return ServerGroupsv2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + } +} + +// ParseServerGroupsv2ID parses 'input' into a ServerGroupsv2Id +func ParseServerGroupsv2ID(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerGroupsv2IDInsensitively parses 'input' case-insensitively into a ServerGroupsv2Id +// note: this method should only be used for API response data and not user input +func ParseServerGroupsv2IDInsensitively(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerGroupsv2ID checks that 'input' can be parsed as a Server Groupsv 2 ID +func ValidateServerGroupsv2ID(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 := ParseServerGroupsv2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Groupsv 2 ID +func (id ServerGroupsv2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Groupsv 2 ID +func (id ServerGroupsv2Id) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + } +} + +// String returns a human-readable description of this Server Groupsv 2 ID +func (id ServerGroupsv2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + } + return fmt.Sprintf("Server Groupsv 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/id_servergroupsv2_test.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_servergroupsv2_test.go new file mode 100644 index 00000000000..304c20e0fe4 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/id_servergroupsv2_test.go @@ -0,0 +1,282 @@ +package configurations + +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 = ServerGroupsv2Id{} + +func TestNewServerGroupsv2ID(t *testing.T) { + id := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } +} + +func TestFormatServerGroupsv2ID(t *testing.T) { + actual := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerGroupsv2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2ID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestParseServerGroupsv2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2IDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestSegmentsForServerGroupsv2Id(t *testing.T) { + segments := ServerGroupsv2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerGroupsv2Id 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/postgresqlhsc/2022-11-08/configurations/method_createorupdatecoordinator_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_createorupdatecoordinator_autorest.go new file mode 100644 index 00000000000..b7593c22d95 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_createorupdatecoordinator_autorest.go @@ -0,0 +1,79 @@ +package configurations + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateCoordinatorOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdateCoordinator ... +func (c ConfigurationsClient) CreateOrUpdateCoordinator(ctx context.Context, id CoordinatorConfigurationId, input ServerConfiguration) (result CreateOrUpdateCoordinatorOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdateCoordinator(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "CreateOrUpdateCoordinator", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdateCoordinator(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "CreateOrUpdateCoordinator", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateCoordinatorThenPoll performs CreateOrUpdateCoordinator then polls until it's completed +func (c ConfigurationsClient) CreateOrUpdateCoordinatorThenPoll(ctx context.Context, id CoordinatorConfigurationId, input ServerConfiguration) error { + result, err := c.CreateOrUpdateCoordinator(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateCoordinator: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdateCoordinator: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdateCoordinator prepares the CreateOrUpdateCoordinator request. +func (c ConfigurationsClient) preparerForCreateOrUpdateCoordinator(ctx context.Context, id CoordinatorConfigurationId, input ServerConfiguration) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdateCoordinator sends the CreateOrUpdateCoordinator request. The method will close the +// http.Response Body if it receives an error. +func (c ConfigurationsClient) senderForCreateOrUpdateCoordinator(ctx context.Context, req *http.Request) (future CreateOrUpdateCoordinatorOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/method_createorupdatenode_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_createorupdatenode_autorest.go new file mode 100644 index 00000000000..262beae8675 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_createorupdatenode_autorest.go @@ -0,0 +1,79 @@ +package configurations + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateNodeOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdateNode ... +func (c ConfigurationsClient) CreateOrUpdateNode(ctx context.Context, id NodeConfigurationId, input ServerConfiguration) (result CreateOrUpdateNodeOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdateNode(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "CreateOrUpdateNode", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdateNode(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "CreateOrUpdateNode", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateNodeThenPoll performs CreateOrUpdateNode then polls until it's completed +func (c ConfigurationsClient) CreateOrUpdateNodeThenPoll(ctx context.Context, id NodeConfigurationId, input ServerConfiguration) error { + result, err := c.CreateOrUpdateNode(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateNode: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdateNode: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdateNode prepares the CreateOrUpdateNode request. +func (c ConfigurationsClient) preparerForCreateOrUpdateNode(ctx context.Context, id NodeConfigurationId, input ServerConfiguration) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdateNode sends the CreateOrUpdateNode request. The method will close the +// http.Response Body if it receives an error. +func (c ConfigurationsClient) senderForCreateOrUpdateNode(ctx context.Context, req *http.Request) (future CreateOrUpdateNodeOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/method_get_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_get_autorest.go new file mode 100644 index 00000000000..2aeb488f91c --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_get_autorest.go @@ -0,0 +1,68 @@ +package configurations + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Configuration +} + +// Get ... +func (c ConfigurationsClient) Get(ctx context.Context, id ConfigurationId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ConfigurationsClient) preparerForGet(ctx context.Context, id ConfigurationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ConfigurationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/method_getcoordinator_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_getcoordinator_autorest.go new file mode 100644 index 00000000000..03ae58e454b --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_getcoordinator_autorest.go @@ -0,0 +1,68 @@ +package configurations + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetCoordinatorOperationResponse struct { + HttpResponse *http.Response + Model *ServerConfiguration +} + +// GetCoordinator ... +func (c ConfigurationsClient) GetCoordinator(ctx context.Context, id CoordinatorConfigurationId) (result GetCoordinatorOperationResponse, err error) { + req, err := c.preparerForGetCoordinator(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "GetCoordinator", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "GetCoordinator", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGetCoordinator(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "GetCoordinator", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGetCoordinator prepares the GetCoordinator request. +func (c ConfigurationsClient) preparerForGetCoordinator(ctx context.Context, id CoordinatorConfigurationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGetCoordinator handles the response to the GetCoordinator request. The method always +// closes the http.Response Body. +func (c ConfigurationsClient) responderForGetCoordinator(resp *http.Response) (result GetCoordinatorOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/method_getnode_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_getnode_autorest.go new file mode 100644 index 00000000000..ba72111f8ce --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_getnode_autorest.go @@ -0,0 +1,68 @@ +package configurations + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetNodeOperationResponse struct { + HttpResponse *http.Response + Model *ServerConfiguration +} + +// GetNode ... +func (c ConfigurationsClient) GetNode(ctx context.Context, id NodeConfigurationId) (result GetNodeOperationResponse, err error) { + req, err := c.preparerForGetNode(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "GetNode", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "GetNode", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGetNode(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "GetNode", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGetNode prepares the GetNode request. +func (c ConfigurationsClient) preparerForGetNode(ctx context.Context, id NodeConfigurationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGetNode handles the response to the GetNode request. The method always +// closes the http.Response Body. +func (c ConfigurationsClient) responderForGetNode(resp *http.Response) (result GetNodeOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/method_listbycluster_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_listbycluster_autorest.go new file mode 100644 index 00000000000..b0ef8b30d02 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_listbycluster_autorest.go @@ -0,0 +1,186 @@ +package configurations + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + Model *[]Configuration + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByClusterOperationResponse, error) +} + +type ListByClusterCompleteResult struct { + Items []Configuration +} + +func (r ListByClusterOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByClusterOperationResponse) LoadMore(ctx context.Context) (resp ListByClusterOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByCluster ... +func (c ConfigurationsClient) ListByCluster(ctx context.Context, id ServerGroupsv2Id) (resp ListByClusterOperationResponse, err error) { + req, err := c.preparerForListByCluster(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByCluster", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByCluster", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByCluster(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByCluster", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByCluster prepares the ListByCluster request. +func (c ConfigurationsClient) preparerForListByCluster(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/configurations", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByClusterWithNextLink prepares the ListByCluster request with the given nextLink token. +func (c ConfigurationsClient) preparerForListByClusterWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByCluster handles the response to the ListByCluster request. The method always +// closes the http.Response Body. +func (c ConfigurationsClient) responderForListByCluster(resp *http.Response) (result ListByClusterOperationResponse, err error) { + type page struct { + Values []Configuration `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByClusterOperationResponse, err error) { + req, err := c.preparerForListByClusterWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByCluster", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByCluster", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByCluster(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByCluster", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByClusterComplete retrieves all of the results into a single object +func (c ConfigurationsClient) ListByClusterComplete(ctx context.Context, id ServerGroupsv2Id) (ListByClusterCompleteResult, error) { + return c.ListByClusterCompleteMatchingPredicate(ctx, id, ConfigurationOperationPredicate{}) +} + +// ListByClusterCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ConfigurationsClient) ListByClusterCompleteMatchingPredicate(ctx context.Context, id ServerGroupsv2Id, predicate ConfigurationOperationPredicate) (resp ListByClusterCompleteResult, err error) { + items := make([]Configuration, 0) + + page, err := c.ListByCluster(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByClusterCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/method_listbyserver_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_listbyserver_autorest.go new file mode 100644 index 00000000000..9441d82ca1c --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/method_listbyserver_autorest.go @@ -0,0 +1,186 @@ +package configurations + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByServerOperationResponse struct { + HttpResponse *http.Response + Model *[]ServerConfiguration + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByServerOperationResponse, error) +} + +type ListByServerCompleteResult struct { + Items []ServerConfiguration +} + +func (r ListByServerOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByServerOperationResponse) LoadMore(ctx context.Context) (resp ListByServerOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByServer ... +func (c ConfigurationsClient) ListByServer(ctx context.Context, id ServerId) (resp ListByServerOperationResponse, err error) { + req, err := c.preparerForListByServer(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByServer", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByServer", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByServer(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByServer", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByServer prepares the ListByServer request. +func (c ConfigurationsClient) preparerForListByServer(ctx context.Context, id ServerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/configurations", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByServerWithNextLink prepares the ListByServer request with the given nextLink token. +func (c ConfigurationsClient) preparerForListByServerWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByServer handles the response to the ListByServer request. The method always +// closes the http.Response Body. +func (c ConfigurationsClient) responderForListByServer(resp *http.Response) (result ListByServerOperationResponse, err error) { + type page struct { + Values []ServerConfiguration `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByServerOperationResponse, err error) { + req, err := c.preparerForListByServerWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByServer", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByServer", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByServer(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "configurations.ConfigurationsClient", "ListByServer", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByServerComplete retrieves all of the results into a single object +func (c ConfigurationsClient) ListByServerComplete(ctx context.Context, id ServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerConfigurationOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ConfigurationsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id ServerId, predicate ServerConfigurationOperationPredicate) (resp ListByServerCompleteResult, err error) { + items := make([]ServerConfiguration, 0) + + page, err := c.ListByServer(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByServerCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/model_configuration.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_configuration.go new file mode 100644 index 00000000000..b541b4aa206 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_configuration.go @@ -0,0 +1,16 @@ +package configurations + +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 Configuration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ConfigurationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/model_configurationproperties.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_configurationproperties.go new file mode 100644 index 00000000000..5547c6c1708 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_configurationproperties.go @@ -0,0 +1,13 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationProperties struct { + AllowedValues *string `json:"allowedValues,omitempty"` + DataType *ConfigurationDataType `json:"dataType,omitempty"` + Description *string `json:"description,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RequiresRestart *bool `json:"requiresRestart,omitempty"` + ServerRoleGroupConfigurations []ServerRoleGroupConfiguration `json:"serverRoleGroupConfigurations"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverconfiguration.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverconfiguration.go new file mode 100644 index 00000000000..4090b20487a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverconfiguration.go @@ -0,0 +1,16 @@ +package configurations + +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 ServerConfiguration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerConfigurationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverconfigurationproperties.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverconfigurationproperties.go new file mode 100644 index 00000000000..f10b6e94587 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverconfigurationproperties.go @@ -0,0 +1,15 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerConfigurationProperties struct { + AllowedValues *string `json:"allowedValues,omitempty"` + DataType *ConfigurationDataType `json:"dataType,omitempty"` + DefaultValue *string `json:"defaultValue,omitempty"` + Description *string `json:"description,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RequiresRestart *bool `json:"requiresRestart,omitempty"` + Source *string `json:"source,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverrolegroupconfiguration.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverrolegroupconfiguration.go new file mode 100644 index 00000000000..e39a4e72d69 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/model_serverrolegroupconfiguration.go @@ -0,0 +1,11 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerRoleGroupConfiguration struct { + DefaultValue *string `json:"defaultValue,omitempty"` + Role ServerRole `json:"role"` + Source *string `json:"source,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/configurations/predicates.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/predicates.go new file mode 100644 index 00000000000..49a5c8012e1 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/predicates.go @@ -0,0 +1,50 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ConfigurationOperationPredicate) Matches(input Configuration) 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 ServerConfigurationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerConfigurationOperationPredicate) Matches(input ServerConfiguration) 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/postgresqlhsc/2022-11-08/configurations/version.go b/resource-manager/postgresqlhsc/2022-11-08/configurations/version.go new file mode 100644 index 00000000000..ff27e35293a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/configurations/version.go @@ -0,0 +1,12 @@ +package configurations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-08" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/configurations/%s", defaultApiVersion) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/README.md b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/README.md new file mode 100644 index 00000000000..a3be5ff782b --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/firewallrules` Documentation + +The `firewallrules` SDK allows for interaction with the Azure Resource Manager Service `postgresqlhsc` (API Version `2022-11-08`). + +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/postgresqlhsc/2022-11-08/firewallrules" +``` + + +### Client Initialization + +```go +client := firewallrules.NewFirewallRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FirewallRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "firewallRuleValue") + +payload := firewallrules.FirewallRule{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `FirewallRulesClient.Delete` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "firewallRuleValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FirewallRulesClient.Get` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "firewallRuleValue") + +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: `FirewallRulesClient.ListByCluster` + +```go +ctx := context.TODO() +id := firewallrules.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +read, err := client.ListByCluster(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/redis/2021-06-01/firewallrules/client.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/client.go similarity index 100% rename from resource-manager/redis/2021-06-01/firewallrules/client.go rename to resource-manager/postgresqlhsc/2022-11-08/firewallrules/client.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/constants.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/constants.go new file mode 100644 index 00000000000..fc2d986b287 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/constants.go @@ -0,0 +1,40 @@ +package firewallrules + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateSucceeded), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "succeeded": ProvisioningStateSucceeded, + } + 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/postgresqlhsc/2022-11-08/firewallrules/id_firewallrule.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_firewallrule.go new file mode 100644 index 00000000000..68487eae765 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_firewallrule.go @@ -0,0 +1,140 @@ +package firewallrules + +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 = FirewallRuleId{} + +// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule +type FirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + FirewallRuleName string +} + +// NewFirewallRuleID returns a new FirewallRuleId struct +func NewFirewallRuleID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, firewallRuleName string) FirewallRuleId { + return FirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + FirewallRuleName: firewallRuleName, + } +} + +// ParseFirewallRuleID parses 'input' into a FirewallRuleId +func ParseFirewallRuleID(input string) (*FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(FirewallRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := FirewallRuleId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.FirewallRuleName, ok = parsed.Parsed["firewallRuleName"]; !ok { + return nil, fmt.Errorf("the segment 'firewallRuleName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseFirewallRuleIDInsensitively parses 'input' case-insensitively into a FirewallRuleId +// note: this method should only be used for API response data and not user input +func ParseFirewallRuleIDInsensitively(input string) (*FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(FirewallRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := FirewallRuleId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.FirewallRuleName, ok = parsed.Parsed["firewallRuleName"]; !ok { + return nil, fmt.Errorf("the segment 'firewallRuleName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateFirewallRuleID checks that 'input' can be parsed as a Firewall Rule ID +func ValidateFirewallRuleID(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 := ParseFirewallRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Firewall Rule ID +func (id FirewallRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/firewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.FirewallRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Firewall Rule ID +func (id FirewallRuleId) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), + resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleValue"), + } +} + +// String returns a human-readable description of this Firewall Rule ID +func (id FirewallRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), + } + return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_firewallrule_test.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_firewallrule_test.go new file mode 100644 index 00000000000..886ebf17a77 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_firewallrule_test.go @@ -0,0 +1,327 @@ +package firewallrules + +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 = FirewallRuleId{} + +func TestNewFirewallRuleID(t *testing.T) { + id := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "firewallRuleValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.FirewallRuleName != "firewallRuleValue" { + t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleValue") + } +} + +func TestFormatFirewallRuleID(t *testing.T) { + actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "firewallRuleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/firewallRules/firewallRuleValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFirewallRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/firewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/firewallRules/firewallRuleValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.FirewallRuleName != v.Expected.FirewallRuleName { + t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) + } + + } +} + +func TestParseFirewallRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/firewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/firewallRules/firewallRuleValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + FirewallRuleName: "fIrEwAlLrUlEvAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleIDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.FirewallRuleName != v.Expected.FirewallRuleName { + t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) + } + + } +} + +func TestSegmentsForFirewallRuleId(t *testing.T) { + segments := FirewallRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("FirewallRuleId 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/postgresqlhsc/2022-11-08/firewallrules/id_servergroupsv2.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_servergroupsv2.go new file mode 100644 index 00000000000..18206e26797 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_servergroupsv2.go @@ -0,0 +1,127 @@ +package firewallrules + +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 = ServerGroupsv2Id{} + +// ServerGroupsv2Id is a struct representing the Resource ID for a Server Groupsv 2 +type ServerGroupsv2Id struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string +} + +// NewServerGroupsv2ID returns a new ServerGroupsv2Id struct +func NewServerGroupsv2ID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string) ServerGroupsv2Id { + return ServerGroupsv2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + } +} + +// ParseServerGroupsv2ID parses 'input' into a ServerGroupsv2Id +func ParseServerGroupsv2ID(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerGroupsv2IDInsensitively parses 'input' case-insensitively into a ServerGroupsv2Id +// note: this method should only be used for API response data and not user input +func ParseServerGroupsv2IDInsensitively(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerGroupsv2ID checks that 'input' can be parsed as a Server Groupsv 2 ID +func ValidateServerGroupsv2ID(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 := ParseServerGroupsv2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Groupsv 2 ID +func (id ServerGroupsv2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Groupsv 2 ID +func (id ServerGroupsv2Id) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + } +} + +// String returns a human-readable description of this Server Groupsv 2 ID +func (id ServerGroupsv2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + } + return fmt.Sprintf("Server Groupsv 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_servergroupsv2_test.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_servergroupsv2_test.go new file mode 100644 index 00000000000..5b8ebad7ead --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/id_servergroupsv2_test.go @@ -0,0 +1,282 @@ +package firewallrules + +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 = ServerGroupsv2Id{} + +func TestNewServerGroupsv2ID(t *testing.T) { + id := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } +} + +func TestFormatServerGroupsv2ID(t *testing.T) { + actual := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerGroupsv2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2ID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestParseServerGroupsv2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2IDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestSegmentsForServerGroupsv2Id(t *testing.T) { + segments := ServerGroupsv2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerGroupsv2Id 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/postgresqlhsc/2022-11-08/firewallrules/method_createorupdate_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_createorupdate_autorest.go new file mode 100644 index 00000000000..0dfa761f1a0 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package firewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c FirewallRulesClient) CreateOrUpdate(ctx context.Context, id FirewallRuleId, input FirewallRule) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c FirewallRulesClient) CreateOrUpdateThenPoll(ctx context.Context, id FirewallRuleId, input FirewallRule) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c FirewallRulesClient) preparerForCreateOrUpdate(ctx context.Context, id FirewallRuleId, input FirewallRule) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c FirewallRulesClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_delete_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_delete_autorest.go new file mode 100644 index 00000000000..ec4b290ecdd --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_delete_autorest.go @@ -0,0 +1,78 @@ +package firewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c FirewallRulesClient) Delete(ctx context.Context, id FirewallRuleId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c FirewallRulesClient) DeleteThenPoll(ctx context.Context, id FirewallRuleId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c FirewallRulesClient) preparerForDelete(ctx context.Context, id FirewallRuleId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c FirewallRulesClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_get_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_get_autorest.go new file mode 100644 index 00000000000..1391c01ba1a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_get_autorest.go @@ -0,0 +1,68 @@ +package firewallrules + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *FirewallRule +} + +// Get ... +func (c FirewallRulesClient) Get(ctx context.Context, id FirewallRuleId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c FirewallRulesClient) preparerForGet(ctx context.Context, id FirewallRuleId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c FirewallRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_listbycluster_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_listbycluster_autorest.go new file mode 100644 index 00000000000..83bcc8dadc2 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/method_listbycluster_autorest.go @@ -0,0 +1,69 @@ +package firewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + Model *FirewallRuleListResult +} + +// ListByCluster ... +func (c FirewallRulesClient) ListByCluster(ctx context.Context, id ServerGroupsv2Id) (result ListByClusterOperationResponse, err error) { + req, err := c.preparerForListByCluster(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "ListByCluster", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "ListByCluster", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByCluster(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "ListByCluster", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListByCluster prepares the ListByCluster request. +func (c FirewallRulesClient) preparerForListByCluster(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/firewallRules", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByCluster handles the response to the ListByCluster request. The method always +// closes the http.Response Body. +func (c FirewallRulesClient) responderForListByCluster(resp *http.Response) (result ListByClusterOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallrule.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallrule.go new file mode 100644 index 00000000000..e6c4db6725d --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallrule.go @@ -0,0 +1,16 @@ +package firewallrules + +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 FirewallRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties FirewallRuleProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallrulelistresult.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallrulelistresult.go new file mode 100644 index 00000000000..c01e91fae56 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallrulelistresult.go @@ -0,0 +1,8 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRuleListResult struct { + Value *[]FirewallRule `json:"value,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallruleproperties.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallruleproperties.go new file mode 100644 index 00000000000..ae5a1daae96 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/model_firewallruleproperties.go @@ -0,0 +1,10 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRuleProperties struct { + EndIPAddress string `json:"endIpAddress"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + StartIPAddress string `json:"startIpAddress"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/firewallrules/version.go b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/version.go new file mode 100644 index 00000000000..4cc96661cdf --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/firewallrules/version.go @@ -0,0 +1,12 @@ +package firewallrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-08" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/firewallrules/%s", defaultApiVersion) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/README.md b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/README.md new file mode 100644 index 00000000000..10374f0adf9 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `postgresqlhsc` (API Version `2022-11-08`). + +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/postgresqlhsc/2022-11-08/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateEndpointConnectionValue") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateEndpointConnectionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateEndpointConnectionValue") + +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: `PrivateEndpointConnectionsClient.ListByCluster` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +read, err := client.ListByCluster(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/redis/2021-06-01/privateendpointconnections/client.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/client.go similarity index 100% rename from resource-manager/redis/2021-06-01/privateendpointconnections/client.go rename to resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/client.go diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/constants.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/constants.go similarity index 100% rename from resource-manager/redis/2021-06-01/privateendpointconnections/constants.go rename to resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/constants.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..eb6e9a4353a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,140 @@ +package privateendpointconnections + +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 = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..ffe821b90f2 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +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 = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_servergroupsv2.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_servergroupsv2.go new file mode 100644 index 00000000000..d8c612397b6 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_servergroupsv2.go @@ -0,0 +1,127 @@ +package privateendpointconnections + +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 = ServerGroupsv2Id{} + +// ServerGroupsv2Id is a struct representing the Resource ID for a Server Groupsv 2 +type ServerGroupsv2Id struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string +} + +// NewServerGroupsv2ID returns a new ServerGroupsv2Id struct +func NewServerGroupsv2ID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string) ServerGroupsv2Id { + return ServerGroupsv2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + } +} + +// ParseServerGroupsv2ID parses 'input' into a ServerGroupsv2Id +func ParseServerGroupsv2ID(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerGroupsv2IDInsensitively parses 'input' case-insensitively into a ServerGroupsv2Id +// note: this method should only be used for API response data and not user input +func ParseServerGroupsv2IDInsensitively(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerGroupsv2ID checks that 'input' can be parsed as a Server Groupsv 2 ID +func ValidateServerGroupsv2ID(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 := ParseServerGroupsv2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Groupsv 2 ID +func (id ServerGroupsv2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Groupsv 2 ID +func (id ServerGroupsv2Id) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + } +} + +// String returns a human-readable description of this Server Groupsv 2 ID +func (id ServerGroupsv2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + } + return fmt.Sprintf("Server Groupsv 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_servergroupsv2_test.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_servergroupsv2_test.go new file mode 100644 index 00000000000..98b95c93527 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/id_servergroupsv2_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +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 = ServerGroupsv2Id{} + +func TestNewServerGroupsv2ID(t *testing.T) { + id := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } +} + +func TestFormatServerGroupsv2ID(t *testing.T) { + actual := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerGroupsv2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2ID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestParseServerGroupsv2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2IDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestSegmentsForServerGroupsv2Id(t *testing.T) { + segments := ServerGroupsv2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerGroupsv2Id 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/postgresqlhsc/2022-11-08/privateendpointconnections/method_createorupdate_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_createorupdate_autorest.go new file mode 100644 index 00000000000..08aac1fbfa7 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PrivateEndpointConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c PrivateEndpointConnectionsClient) preparerForCreateOrUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c PrivateEndpointConnectionsClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_delete_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_delete_autorest.go new file mode 100644 index 00000000000..ef4fd3d8e66 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_delete_autorest.go @@ -0,0 +1,78 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c PrivateEndpointConnectionsClient) preparerForDelete(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c PrivateEndpointConnectionsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/method_get_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_get_autorest.go similarity index 100% rename from resource-manager/redis/2021-06-01/privateendpointconnections/method_get_autorest.go rename to resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_get_autorest.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_listbycluster_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_listbycluster_autorest.go new file mode 100644 index 00000000000..f52f820d047 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/method_listbycluster_autorest.go @@ -0,0 +1,69 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionListResult +} + +// ListByCluster ... +func (c PrivateEndpointConnectionsClient) ListByCluster(ctx context.Context, id ServerGroupsv2Id) (result ListByClusterOperationResponse, err error) { + req, err := c.preparerForListByCluster(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "ListByCluster", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "ListByCluster", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByCluster(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "ListByCluster", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListByCluster prepares the ListByCluster request. +func (c PrivateEndpointConnectionsClient) preparerForListByCluster(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByCluster handles the response to the ListByCluster request. The method always +// closes the http.Response Body. +func (c PrivateEndpointConnectionsClient) responderForListByCluster(resp *http.Response) (result ListByClusterOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpoint.go similarity index 100% rename from resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpoint.go rename to resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpoint.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..977fe056fe3 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package privateendpointconnections + +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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnectionlistresult.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnectionlistresult.go similarity index 100% rename from resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnectionlistresult.go rename to resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnectionlistresult.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..fb540c904b6 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privatelinkserviceconnectionstate.go similarity index 100% rename from resource-manager/redis/2021-06-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go rename to resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/model_privatelinkserviceconnectionstate.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/version.go b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/version.go new file mode 100644 index 00000000000..49e6356527a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privateendpointconnections/version.go @@ -0,0 +1,12 @@ +package privateendpointconnections + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-08" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/README.md b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/README.md new file mode 100644 index 00000000000..e872213f66b --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `postgresqlhsc` (API Version `2022-11-08`). + +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/postgresqlhsc/2022-11-08/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.Get` + +```go +ctx := context.TODO() +id := privatelinkresources.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateLinkResourceValue") + +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: `PrivateLinkResourcesClient.ListByCluster` + +```go +ctx := context.TODO() +id := privatelinkresources.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +read, err := client.ListByCluster(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/redis/2021-06-01/privatelinkresources/client.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/client.go similarity index 100% rename from resource-manager/redis/2021-06-01/privatelinkresources/client.go rename to resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/client.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_privatelinkresource.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_privatelinkresource.go new file mode 100644 index 00000000000..475206e2262 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_privatelinkresource.go @@ -0,0 +1,140 @@ +package privatelinkresources + +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 = PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + PrivateLinkResourceName string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, privateLinkResourceName string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.PrivateLinkResourceName, ok = parsed.Parsed["privateLinkResourceName"]; !ok { + return nil, fmt.Errorf("the segment 'privateLinkResourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.PrivateLinkResourceName, ok = parsed.Parsed["privateLinkResourceName"]; !ok { + return nil, fmt.Errorf("the segment 'privateLinkResourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceValue"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_privatelinkresource_test.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_privatelinkresource_test.go new file mode 100644 index 00000000000..b2fa531a644 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_privatelinkresource_test.go @@ -0,0 +1,327 @@ +package privatelinkresources + +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 = PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateLinkResourceValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.PrivateLinkResourceName != "privateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceValue") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "privateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateLinkResources/privateLinkResourceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId 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/postgresqlhsc/2022-11-08/privatelinkresources/id_servergroupsv2.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_servergroupsv2.go new file mode 100644 index 00000000000..060f97e65c2 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_servergroupsv2.go @@ -0,0 +1,127 @@ +package privatelinkresources + +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 = ServerGroupsv2Id{} + +// ServerGroupsv2Id is a struct representing the Resource ID for a Server Groupsv 2 +type ServerGroupsv2Id struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string +} + +// NewServerGroupsv2ID returns a new ServerGroupsv2Id struct +func NewServerGroupsv2ID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string) ServerGroupsv2Id { + return ServerGroupsv2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + } +} + +// ParseServerGroupsv2ID parses 'input' into a ServerGroupsv2Id +func ParseServerGroupsv2ID(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerGroupsv2IDInsensitively parses 'input' case-insensitively into a ServerGroupsv2Id +// note: this method should only be used for API response data and not user input +func ParseServerGroupsv2IDInsensitively(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerGroupsv2ID checks that 'input' can be parsed as a Server Groupsv 2 ID +func ValidateServerGroupsv2ID(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 := ParseServerGroupsv2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Groupsv 2 ID +func (id ServerGroupsv2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Groupsv 2 ID +func (id ServerGroupsv2Id) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + } +} + +// String returns a human-readable description of this Server Groupsv 2 ID +func (id ServerGroupsv2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + } + return fmt.Sprintf("Server Groupsv 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_servergroupsv2_test.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_servergroupsv2_test.go new file mode 100644 index 00000000000..06851dd0533 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/id_servergroupsv2_test.go @@ -0,0 +1,282 @@ +package privatelinkresources + +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 = ServerGroupsv2Id{} + +func TestNewServerGroupsv2ID(t *testing.T) { + id := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } +} + +func TestFormatServerGroupsv2ID(t *testing.T) { + actual := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerGroupsv2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2ID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestParseServerGroupsv2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2IDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestSegmentsForServerGroupsv2Id(t *testing.T) { + segments := ServerGroupsv2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerGroupsv2Id 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/postgresqlhsc/2022-11-08/privatelinkresources/method_get_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/method_get_autorest.go new file mode 100644 index 00000000000..19925a8bf6c --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/method_get_autorest.go @@ -0,0 +1,68 @@ +package privatelinkresources + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *PrivateLinkResource +} + +// Get ... +func (c PrivateLinkResourcesClient) Get(ctx context.Context, id PrivateLinkResourceId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c PrivateLinkResourcesClient) preparerForGet(ctx context.Context, id PrivateLinkResourceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c PrivateLinkResourcesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/method_listbycluster_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/method_listbycluster_autorest.go new file mode 100644 index 00000000000..f6af2b2fe43 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/method_listbycluster_autorest.go @@ -0,0 +1,69 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + Model *PrivateLinkResourceListResult +} + +// ListByCluster ... +func (c PrivateLinkResourcesClient) ListByCluster(ctx context.Context, id ServerGroupsv2Id) (result ListByClusterOperationResponse, err error) { + req, err := c.preparerForListByCluster(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "ListByCluster", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "ListByCluster", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByCluster(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "ListByCluster", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListByCluster prepares the ListByCluster request. +func (c PrivateLinkResourcesClient) preparerForListByCluster(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByCluster handles the response to the ListByCluster request. The method always +// closes the http.Response Body. +func (c PrivateLinkResourcesClient) responderForListByCluster(resp *http.Response) (result ListByClusterOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/model_privatelinkresource.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..6e8c3d8148b --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,16 @@ +package privatelinkresources + +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 PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2021-06-01/privatelinkresources/model_privatelinkresourcelistresult.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/model_privatelinkresourcelistresult.go similarity index 100% rename from resource-manager/redis/2021-06-01/privatelinkresources/model_privatelinkresourcelistresult.go rename to resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/model_privatelinkresourcelistresult.go diff --git a/resource-manager/redis/2021-06-01/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/model_privatelinkresourceproperties.go similarity index 100% rename from resource-manager/redis/2021-06-01/privatelinkresources/model_privatelinkresourceproperties.go rename to resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/model_privatelinkresourceproperties.go diff --git a/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/version.go b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/version.go new file mode 100644 index 00000000000..fb43a4dc945 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/privatelinkresources/version.go @@ -0,0 +1,12 @@ +package privatelinkresources + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-08" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkresources/%s", defaultApiVersion) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/README.md b/resource-manager/postgresqlhsc/2022-11-08/roles/README.md new file mode 100644 index 00000000000..6006de0f316 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/roles` Documentation + +The `roles` SDK allows for interaction with the Azure Resource Manager Service `postgresqlhsc` (API Version `2022-11-08`). + +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/postgresqlhsc/2022-11-08/roles" +``` + + +### Client Initialization + +```go +client := roles.NewRolesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RolesClient.Create` + +```go +ctx := context.TODO() +id := roles.NewRoleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "roleValue") + +payload := roles.Role{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RolesClient.Delete` + +```go +ctx := context.TODO() +id := roles.NewRoleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "roleValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RolesClient.Get` + +```go +ctx := context.TODO() +id := roles.NewRoleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "roleValue") + +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: `RolesClient.ListByCluster` + +```go +ctx := context.TODO() +id := roles.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +read, err := client.ListByCluster(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/postgresqlhsc/2022-11-08/roles/client.go b/resource-manager/postgresqlhsc/2022-11-08/roles/client.go new file mode 100644 index 00000000000..4e0dc21bb86 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/client.go @@ -0,0 +1,18 @@ +package roles + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RolesClient struct { + Client autorest.Client + baseUri string +} + +func NewRolesClientWithBaseURI(endpoint string) RolesClient { + return RolesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/constants.go b/resource-manager/postgresqlhsc/2022-11-08/roles/constants.go new file mode 100644 index 00000000000..d5e615055e4 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/constants.go @@ -0,0 +1,40 @@ +package roles + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateSucceeded), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "succeeded": ProvisioningStateSucceeded, + } + 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/postgresqlhsc/2022-11-08/roles/id_role.go b/resource-manager/postgresqlhsc/2022-11-08/roles/id_role.go new file mode 100644 index 00000000000..001bd758803 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/id_role.go @@ -0,0 +1,140 @@ +package roles + +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 = RoleId{} + +// RoleId is a struct representing the Resource ID for a Role +type RoleId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + RoleName string +} + +// NewRoleID returns a new RoleId struct +func NewRoleID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, roleName string) RoleId { + return RoleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + RoleName: roleName, + } +} + +// ParseRoleID parses 'input' into a RoleId +func ParseRoleID(input string) (*RoleId, error) { + parser := resourceids.NewParserFromResourceIdType(RoleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := RoleId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.RoleName, ok = parsed.Parsed["roleName"]; !ok { + return nil, fmt.Errorf("the segment 'roleName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseRoleIDInsensitively parses 'input' case-insensitively into a RoleId +// note: this method should only be used for API response data and not user input +func ParseRoleIDInsensitively(input string) (*RoleId, error) { + parser := resourceids.NewParserFromResourceIdType(RoleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := RoleId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.RoleName, ok = parsed.Parsed["roleName"]; !ok { + return nil, fmt.Errorf("the segment 'roleName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateRoleID checks that 'input' can be parsed as a Role ID +func ValidateRoleID(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 := ParseRoleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Role ID +func (id RoleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/roles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.RoleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Role ID +func (id RoleId) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticRoles", "roles", "roles"), + resourceids.UserSpecifiedSegment("roleName", "roleValue"), + } +} + +// String returns a human-readable description of this Role ID +func (id RoleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Role Name: %q", id.RoleName), + } + return fmt.Sprintf("Role (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/id_role_test.go b/resource-manager/postgresqlhsc/2022-11-08/roles/id_role_test.go new file mode 100644 index 00000000000..18f59e6d12e --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/id_role_test.go @@ -0,0 +1,327 @@ +package roles + +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 = RoleId{} + +func TestNewRoleID(t *testing.T) { + id := NewRoleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "roleValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.RoleName != "roleValue" { + t.Fatalf("Expected %q but got %q for Segment 'RoleName'", id.RoleName, "roleValue") + } +} + +func TestFormatRoleID(t *testing.T) { + actual := NewRoleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "roleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/roles/roleValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRoleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RoleId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/roles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/roles/roleValue", + Expected: &RoleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + RoleName: "roleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/roles/roleValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRoleID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.RoleName != v.Expected.RoleName { + t.Fatalf("Expected %q but got %q for RoleName", v.Expected.RoleName, actual.RoleName) + } + + } +} + +func TestParseRoleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RoleId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/roles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/rOlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/roles/roleValue", + Expected: &RoleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + RoleName: "roleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/roles/roleValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/rOlEs/rOlEvAlUe", + Expected: &RoleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + RoleName: "rOlEvAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/rOlEs/rOlEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRoleIDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.RoleName != v.Expected.RoleName { + t.Fatalf("Expected %q but got %q for RoleName", v.Expected.RoleName, actual.RoleName) + } + + } +} + +func TestSegmentsForRoleId(t *testing.T) { + segments := RoleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RoleId 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/postgresqlhsc/2022-11-08/roles/id_servergroupsv2.go b/resource-manager/postgresqlhsc/2022-11-08/roles/id_servergroupsv2.go new file mode 100644 index 00000000000..c50fc6709a8 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/id_servergroupsv2.go @@ -0,0 +1,127 @@ +package roles + +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 = ServerGroupsv2Id{} + +// ServerGroupsv2Id is a struct representing the Resource ID for a Server Groupsv 2 +type ServerGroupsv2Id struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string +} + +// NewServerGroupsv2ID returns a new ServerGroupsv2Id struct +func NewServerGroupsv2ID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string) ServerGroupsv2Id { + return ServerGroupsv2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + } +} + +// ParseServerGroupsv2ID parses 'input' into a ServerGroupsv2Id +func ParseServerGroupsv2ID(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerGroupsv2IDInsensitively parses 'input' case-insensitively into a ServerGroupsv2Id +// note: this method should only be used for API response data and not user input +func ParseServerGroupsv2IDInsensitively(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerGroupsv2ID checks that 'input' can be parsed as a Server Groupsv 2 ID +func ValidateServerGroupsv2ID(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 := ParseServerGroupsv2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Groupsv 2 ID +func (id ServerGroupsv2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Groupsv 2 ID +func (id ServerGroupsv2Id) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + } +} + +// String returns a human-readable description of this Server Groupsv 2 ID +func (id ServerGroupsv2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + } + return fmt.Sprintf("Server Groupsv 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/id_servergroupsv2_test.go b/resource-manager/postgresqlhsc/2022-11-08/roles/id_servergroupsv2_test.go new file mode 100644 index 00000000000..96fe271e311 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/id_servergroupsv2_test.go @@ -0,0 +1,282 @@ +package roles + +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 = ServerGroupsv2Id{} + +func TestNewServerGroupsv2ID(t *testing.T) { + id := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } +} + +func TestFormatServerGroupsv2ID(t *testing.T) { + actual := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerGroupsv2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2ID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestParseServerGroupsv2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2IDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestSegmentsForServerGroupsv2Id(t *testing.T) { + segments := ServerGroupsv2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerGroupsv2Id 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/postgresqlhsc/2022-11-08/roles/method_create_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/roles/method_create_autorest.go new file mode 100644 index 00000000000..62b8728ec27 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/method_create_autorest.go @@ -0,0 +1,79 @@ +package roles + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c RolesClient) Create(ctx context.Context, id RoleId, input Role) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c RolesClient) CreateThenPoll(ctx context.Context, id RoleId, input Role) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c RolesClient) preparerForCreate(ctx context.Context, id RoleId, input Role) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c RolesClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/method_delete_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/roles/method_delete_autorest.go new file mode 100644 index 00000000000..0dda341d5e5 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/method_delete_autorest.go @@ -0,0 +1,78 @@ +package roles + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c RolesClient) Delete(ctx context.Context, id RoleId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c RolesClient) DeleteThenPoll(ctx context.Context, id RoleId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c RolesClient) preparerForDelete(ctx context.Context, id RoleId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c RolesClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/method_get_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/roles/method_get_autorest.go new file mode 100644 index 00000000000..046265fae85 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/method_get_autorest.go @@ -0,0 +1,68 @@ +package roles + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Role +} + +// Get ... +func (c RolesClient) Get(ctx context.Context, id RoleId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c RolesClient) preparerForGet(ctx context.Context, id RoleId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c RolesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/method_listbycluster_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/roles/method_listbycluster_autorest.go new file mode 100644 index 00000000000..c7022411f53 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/method_listbycluster_autorest.go @@ -0,0 +1,69 @@ +package roles + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + Model *RoleListResult +} + +// ListByCluster ... +func (c RolesClient) ListByCluster(ctx context.Context, id ServerGroupsv2Id) (result ListByClusterOperationResponse, err error) { + req, err := c.preparerForListByCluster(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "ListByCluster", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "ListByCluster", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByCluster(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "roles.RolesClient", "ListByCluster", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListByCluster prepares the ListByCluster request. +func (c RolesClient) preparerForListByCluster(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/roles", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByCluster handles the response to the ListByCluster request. The method always +// closes the http.Response Body. +func (c RolesClient) responderForListByCluster(resp *http.Response) (result ListByClusterOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/model_role.go b/resource-manager/postgresqlhsc/2022-11-08/roles/model_role.go new file mode 100644 index 00000000000..2113e5c82e8 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/model_role.go @@ -0,0 +1,16 @@ +package roles + +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 Role struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties RoleProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/model_rolelistresult.go b/resource-manager/postgresqlhsc/2022-11-08/roles/model_rolelistresult.go new file mode 100644 index 00000000000..e65f2ca256a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/model_rolelistresult.go @@ -0,0 +1,8 @@ +package roles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RoleListResult struct { + Value *[]Role `json:"value,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/model_roleproperties.go b/resource-manager/postgresqlhsc/2022-11-08/roles/model_roleproperties.go new file mode 100644 index 00000000000..8e8f181c632 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/model_roleproperties.go @@ -0,0 +1,9 @@ +package roles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RoleProperties struct { + Password string `json:"password"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/roles/version.go b/resource-manager/postgresqlhsc/2022-11-08/roles/version.go new file mode 100644 index 00000000000..5a806411a6a --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/roles/version.go @@ -0,0 +1,12 @@ +package roles + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-08" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/roles/%s", defaultApiVersion) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/README.md b/resource-manager/postgresqlhsc/2022-11-08/servers/README.md new file mode 100644 index 00000000000..cd951c30aa0 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/postgresqlhsc/2022-11-08/servers` Documentation + +The `servers` SDK allows for interaction with the Azure Resource Manager Service `postgresqlhsc` (API Version `2022-11-08`). + +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/postgresqlhsc/2022-11-08/servers" +``` + + +### Client Initialization + +```go +client := servers.NewServersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServersClient.Get` + +```go +ctx := context.TODO() +id := servers.NewServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "serverValue") + +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: `ServersClient.ListByCluster` + +```go +ctx := context.TODO() +id := servers.NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + +read, err := client.ListByCluster(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/postgresqlhsc/2022-11-08/servers/client.go b/resource-manager/postgresqlhsc/2022-11-08/servers/client.go new file mode 100644 index 00000000000..fd9e02ba599 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/client.go @@ -0,0 +1,18 @@ +package servers + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServersClient struct { + Client autorest.Client + baseUri string +} + +func NewServersClientWithBaseURI(endpoint string) ServersClient { + return ServersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/constants.go b/resource-manager/postgresqlhsc/2022-11-08/servers/constants.go new file mode 100644 index 00000000000..4684c886be3 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/constants.go @@ -0,0 +1,34 @@ +package servers + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerRole string + +const ( + ServerRoleCoordinator ServerRole = "Coordinator" + ServerRoleWorker ServerRole = "Worker" +) + +func PossibleValuesForServerRole() []string { + return []string{ + string(ServerRoleCoordinator), + string(ServerRoleWorker), + } +} + +func parseServerRole(input string) (*ServerRole, error) { + vals := map[string]ServerRole{ + "coordinator": ServerRoleCoordinator, + "worker": ServerRoleWorker, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerRole(input) + return &out, nil +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/id_server.go b/resource-manager/postgresqlhsc/2022-11-08/servers/id_server.go new file mode 100644 index 00000000000..9112384749d --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/id_server.go @@ -0,0 +1,140 @@ +package servers + +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 = ServerId{} + +// ServerId is a struct representing the Resource ID for a Server +type ServerId struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string + ServerName string +} + +// NewServerID returns a new ServerId struct +func NewServerID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string, serverName string) ServerId { + return ServerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + ServerName: serverName, + } +} + +// ParseServerID parses 'input' into a ServerId +func ParseServerID(input string) (*ServerId, error) { + parser := resourceids.NewParserFromResourceIdType(ServerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.ServerName, ok = parsed.Parsed["serverName"]; !ok { + return nil, fmt.Errorf("the segment 'serverName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerIDInsensitively parses 'input' case-insensitively into a ServerId +// note: this method should only be used for API response data and not user input +func ParseServerIDInsensitively(input string) (*ServerId, error) { + parser := resourceids.NewParserFromResourceIdType(ServerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + if id.ServerName, ok = parsed.Parsed["serverName"]; !ok { + return nil, fmt.Errorf("the segment 'serverName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerID checks that 'input' can be parsed as a Server ID +func ValidateServerID(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 := ParseServerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server ID +func (id ServerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s/servers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name, id.ServerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server ID +func (id ServerId) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverValue"), + } +} + +// String returns a human-readable description of this Server ID +func (id ServerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + fmt.Sprintf("Server Name: %q", id.ServerName), + } + return fmt.Sprintf("Server (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/id_server_test.go b/resource-manager/postgresqlhsc/2022-11-08/servers/id_server_test.go new file mode 100644 index 00000000000..7b2c41f8bea --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/id_server_test.go @@ -0,0 +1,327 @@ +package servers + +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 = ServerId{} + +func TestNewServerID(t *testing.T) { + id := NewServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "serverValue") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } + + if id.ServerName != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } +} + +func TestFormatServerID(t *testing.T) { + actual := NewServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value", "serverValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue", + Expected: &ServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + ServerName: "serverValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + } +} + +func TestParseServerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerId + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/sErVeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue", + Expected: &ServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + ServerName: "serverValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/servers/serverValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/sErVeRs/sErVeRvAlUe", + Expected: &ServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + ServerName: "sErVeRvAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/sErVeRs/sErVeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerIDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + } +} + +func TestSegmentsForServerId(t *testing.T) { + segments := ServerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerId 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/postgresqlhsc/2022-11-08/servers/id_servergroupsv2.go b/resource-manager/postgresqlhsc/2022-11-08/servers/id_servergroupsv2.go new file mode 100644 index 00000000000..b9d0e5610d0 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/id_servergroupsv2.go @@ -0,0 +1,127 @@ +package servers + +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 = ServerGroupsv2Id{} + +// ServerGroupsv2Id is a struct representing the Resource ID for a Server Groupsv 2 +type ServerGroupsv2Id struct { + SubscriptionId string + ResourceGroupName string + ServerGroupsv2Name string +} + +// NewServerGroupsv2ID returns a new ServerGroupsv2Id struct +func NewServerGroupsv2ID(subscriptionId string, resourceGroupName string, serverGroupsv2Name string) ServerGroupsv2Id { + return ServerGroupsv2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerGroupsv2Name: serverGroupsv2Name, + } +} + +// ParseServerGroupsv2ID parses 'input' into a ServerGroupsv2Id +func ParseServerGroupsv2ID(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServerGroupsv2IDInsensitively parses 'input' case-insensitively into a ServerGroupsv2Id +// note: this method should only be used for API response data and not user input +func ParseServerGroupsv2IDInsensitively(input string) (*ServerGroupsv2Id, error) { + parser := resourceids.NewParserFromResourceIdType(ServerGroupsv2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServerGroupsv2Id{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServerGroupsv2Name, ok = parsed.Parsed["serverGroupsv2Name"]; !ok { + return nil, fmt.Errorf("the segment 'serverGroupsv2Name' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServerGroupsv2ID checks that 'input' can be parsed as a Server Groupsv 2 ID +func ValidateServerGroupsv2ID(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 := ParseServerGroupsv2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Groupsv 2 ID +func (id ServerGroupsv2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerGroupsv2Name) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Groupsv 2 ID +func (id ServerGroupsv2Id) 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("staticMicrosoftDBforPostgreSQL", "Microsoft.DBforPostgreSQL", "Microsoft.DBforPostgreSQL"), + resourceids.StaticSegment("staticServerGroupsv2", "serverGroupsv2", "serverGroupsv2"), + resourceids.UserSpecifiedSegment("serverGroupsv2Name", "serverGroupsv2Value"), + } +} + +// String returns a human-readable description of this Server Groupsv 2 ID +func (id ServerGroupsv2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Groupsv 2 Name: %q", id.ServerGroupsv2Name), + } + return fmt.Sprintf("Server Groupsv 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/id_servergroupsv2_test.go b/resource-manager/postgresqlhsc/2022-11-08/servers/id_servergroupsv2_test.go new file mode 100644 index 00000000000..92abc4341ca --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/id_servergroupsv2_test.go @@ -0,0 +1,282 @@ +package servers + +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 = ServerGroupsv2Id{} + +func TestNewServerGroupsv2ID(t *testing.T) { + id := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value") + + 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.ServerGroupsv2Name != "serverGroupsv2Value" { + t.Fatalf("Expected %q but got %q for Segment 'ServerGroupsv2Name'", id.ServerGroupsv2Name, "serverGroupsv2Value") + } +} + +func TestFormatServerGroupsv2ID(t *testing.T) { + actual := NewServerGroupsv2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverGroupsv2Value").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerGroupsv2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2ID(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestParseServerGroupsv2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerGroupsv2Id + }{ + { + // 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.DBforPostgreSQL", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerGroupsv2Name: "serverGroupsv2Value", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/serverGroupsv2Value/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe", + Expected: &ServerGroupsv2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerGroupsv2Name: "sErVeRgRoUpSv2vAlUe", + }, + }, + { + // 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.dBfOrPoStGrEsQl/sErVeRgRoUpSv2/sErVeRgRoUpSv2vAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerGroupsv2IDInsensitively(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.ServerGroupsv2Name != v.Expected.ServerGroupsv2Name { + t.Fatalf("Expected %q but got %q for ServerGroupsv2Name", v.Expected.ServerGroupsv2Name, actual.ServerGroupsv2Name) + } + + } +} + +func TestSegmentsForServerGroupsv2Id(t *testing.T) { + segments := ServerGroupsv2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerGroupsv2Id 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/postgresqlhsc/2022-11-08/servers/method_get_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/servers/method_get_autorest.go new file mode 100644 index 00000000000..cdb3fd74c79 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/method_get_autorest.go @@ -0,0 +1,68 @@ +package servers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ClusterServer +} + +// Get ... +func (c ServersClient) Get(ctx context.Context, id ServerId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "servers.ServersClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "servers.ServersClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "servers.ServersClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ServersClient) preparerForGet(ctx context.Context, id ServerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ServersClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/method_listbycluster_autorest.go b/resource-manager/postgresqlhsc/2022-11-08/servers/method_listbycluster_autorest.go new file mode 100644 index 00000000000..61dd8882335 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/method_listbycluster_autorest.go @@ -0,0 +1,69 @@ +package servers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + Model *ClusterServerListResult +} + +// ListByCluster ... +func (c ServersClient) ListByCluster(ctx context.Context, id ServerGroupsv2Id) (result ListByClusterOperationResponse, err error) { + req, err := c.preparerForListByCluster(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "servers.ServersClient", "ListByCluster", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "servers.ServersClient", "ListByCluster", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByCluster(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "servers.ServersClient", "ListByCluster", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListByCluster prepares the ListByCluster request. +func (c ServersClient) preparerForListByCluster(ctx context.Context, id ServerGroupsv2Id) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/servers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByCluster handles the response to the ListByCluster request. The method always +// closes the http.Response Body. +func (c ServersClient) responderForListByCluster(resp *http.Response) (result ListByClusterOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserver.go b/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserver.go new file mode 100644 index 00000000000..c85e28ff5cc --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserver.go @@ -0,0 +1,16 @@ +package servers + +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 ClusterServer struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ClusterServerProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserverlistresult.go b/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserverlistresult.go new file mode 100644 index 00000000000..b4a71f230a1 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserverlistresult.go @@ -0,0 +1,8 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterServerListResult struct { + Value *[]ClusterServer `json:"value,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserverproperties.go b/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserverproperties.go new file mode 100644 index 00000000000..352f09491fa --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/model_clusterserverproperties.go @@ -0,0 +1,21 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterServerProperties struct { + AdministratorLogin *string `json:"administratorLogin,omitempty"` + AvailabilityZone *string `json:"availabilityZone,omitempty"` + CitusVersion *string `json:"citusVersion,omitempty"` + EnableHa *bool `json:"enableHa,omitempty"` + EnablePublicIPAccess *bool `json:"enablePublicIpAccess,omitempty"` + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty"` + HaState *string `json:"haState,omitempty"` + IsReadOnly *bool `json:"isReadOnly,omitempty"` + PostgresqlVersion *string `json:"postgresqlVersion,omitempty"` + Role *ServerRole `json:"role,omitempty"` + ServerEdition *string `json:"serverEdition,omitempty"` + State *string `json:"state,omitempty"` + StorageQuotaInMb *int64 `json:"storageQuotaInMb,omitempty"` + VCores *int64 `json:"vCores,omitempty"` +} diff --git a/resource-manager/postgresqlhsc/2022-11-08/servers/version.go b/resource-manager/postgresqlhsc/2022-11-08/servers/version.go new file mode 100644 index 00000000000..88ad7d6a803 --- /dev/null +++ b/resource-manager/postgresqlhsc/2022-11-08/servers/version.go @@ -0,0 +1,12 @@ +package servers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-11-08" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/servers/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/README.md new file mode 100644 index 00000000000..f165170d844 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupengines` Documentation + +The `backupengines` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupengines" +``` + + +### Client Initialization + +```go +client := backupengines.NewBackupEnginesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupEnginesClient.Get` + +```go +ctx := context.TODO() +id := backupengines.NewBackupEngineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupEngineValue") + +read, err := client.Get(ctx, id, backupengines.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupEnginesClient.List` + +```go +ctx := context.TODO() +id := backupengines.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, backupengines.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backupengines.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/client.go new file mode 100644 index 00000000000..3f415af9d81 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/client.go @@ -0,0 +1,18 @@ +package backupengines + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupEnginesClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupEnginesClientWithBaseURI(endpoint string) BackupEnginesClient { + return BackupEnginesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/constants.go new file mode 100644 index 00000000000..0b1ec0205b3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/constants.go @@ -0,0 +1,86 @@ +package backupengines + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupEngineType string + +const ( + BackupEngineTypeAzureBackupServerEngine BackupEngineType = "AzureBackupServerEngine" + BackupEngineTypeDpmBackupEngine BackupEngineType = "DpmBackupEngine" + BackupEngineTypeInvalid BackupEngineType = "Invalid" +) + +func PossibleValuesForBackupEngineType() []string { + return []string{ + string(BackupEngineTypeAzureBackupServerEngine), + string(BackupEngineTypeDpmBackupEngine), + string(BackupEngineTypeInvalid), + } +} + +func parseBackupEngineType(input string) (*BackupEngineType, error) { + vals := map[string]BackupEngineType{ + "azurebackupserverengine": BackupEngineTypeAzureBackupServerEngine, + "dpmbackupengine": BackupEngineTypeDpmBackupEngine, + "invalid": BackupEngineTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupEngineType(input) + return &out, nil +} + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_backupengine.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_backupengine.go new file mode 100644 index 00000000000..cabea8694af --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_backupengine.go @@ -0,0 +1,140 @@ +package backupengines + +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 = BackupEngineId{} + +// BackupEngineId is a struct representing the Resource ID for a Backup Engine +type BackupEngineId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupEngineName string +} + +// NewBackupEngineID returns a new BackupEngineId struct +func NewBackupEngineID(subscriptionId string, resourceGroupName string, vaultName string, backupEngineName string) BackupEngineId { + return BackupEngineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupEngineName: backupEngineName, + } +} + +// ParseBackupEngineID parses 'input' into a BackupEngineId +func ParseBackupEngineID(input string) (*BackupEngineId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupEngineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupEngineId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupEngineName, ok = parsed.Parsed["backupEngineName"]; !ok { + return nil, fmt.Errorf("the segment 'backupEngineName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseBackupEngineIDInsensitively parses 'input' case-insensitively into a BackupEngineId +// note: this method should only be used for API response data and not user input +func ParseBackupEngineIDInsensitively(input string) (*BackupEngineId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupEngineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupEngineId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupEngineName, ok = parsed.Parsed["backupEngineName"]; !ok { + return nil, fmt.Errorf("the segment 'backupEngineName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateBackupEngineID checks that 'input' can be parsed as a Backup Engine ID +func ValidateBackupEngineID(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 := ParseBackupEngineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Engine ID +func (id BackupEngineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupEngines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupEngineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Engine ID +func (id BackupEngineId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupEngines", "backupEngines", "backupEngines"), + resourceids.UserSpecifiedSegment("backupEngineName", "backupEngineValue"), + } +} + +// String returns a human-readable description of this Backup Engine ID +func (id BackupEngineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Engine Name: %q", id.BackupEngineName), + } + return fmt.Sprintf("Backup Engine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_backupengine_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_backupengine_test.go new file mode 100644 index 00000000000..f2abdc96185 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_backupengine_test.go @@ -0,0 +1,327 @@ +package backupengines + +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 = BackupEngineId{} + +func TestNewBackupEngineID(t *testing.T) { + id := NewBackupEngineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupEngineValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupEngineName != "backupEngineValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupEngineName'", id.BackupEngineName, "backupEngineValue") + } +} + +func TestFormatBackupEngineID(t *testing.T) { + actual := NewBackupEngineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupEngineValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupEngines/backupEngineValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupEngineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupEngineId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupEngines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupEngines/backupEngineValue", + Expected: &BackupEngineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupEngineName: "backupEngineValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupEngines/backupEngineValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupEngineID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupEngineName != v.Expected.BackupEngineName { + t.Fatalf("Expected %q but got %q for BackupEngineName", v.Expected.BackupEngineName, actual.BackupEngineName) + } + + } +} + +func TestParseBackupEngineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupEngineId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupEngines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPeNgInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupEngines/backupEngineValue", + Expected: &BackupEngineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupEngineName: "backupEngineValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupEngines/backupEngineValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPeNgInEs/bAcKuPeNgInEvAlUe", + Expected: &BackupEngineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupEngineName: "bAcKuPeNgInEvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPeNgInEs/bAcKuPeNgInEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupEngineIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupEngineName != v.Expected.BackupEngineName { + t.Fatalf("Expected %q but got %q for BackupEngineName", v.Expected.BackupEngineName, actual.BackupEngineName) + } + + } +} + +func TestSegmentsForBackupEngineId(t *testing.T) { + segments := BackupEngineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupEngineId 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/recoveryservicesbackup/2023-02-01/backupengines/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_vault.go new file mode 100644 index 00000000000..6b5a042f47b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_vault.go @@ -0,0 +1,127 @@ +package backupengines + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_vault_test.go new file mode 100644 index 00000000000..f334b75572c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/id_vault_test.go @@ -0,0 +1,282 @@ +package backupengines + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupengines/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/method_get_autorest.go new file mode 100644 index 00000000000..e4493845ef2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/method_get_autorest.go @@ -0,0 +1,97 @@ +package backupengines + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *BackupEngineBaseResource +} + +type GetOperationOptions struct { + Filter *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o GetOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// Get ... +func (c BackupEnginesClient) Get(ctx context.Context, id BackupEngineId, options GetOperationOptions) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c BackupEnginesClient) preparerForGet(ctx context.Context, id BackupEngineId, options GetOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c BackupEnginesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/method_list_autorest.go new file mode 100644 index 00000000000..bfc2eb661b3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/method_list_autorest.go @@ -0,0 +1,215 @@ +package backupengines + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]BackupEngineBaseResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []BackupEngineBaseResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupEnginesClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupEnginesClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupEngines", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupEnginesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupEnginesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []BackupEngineBaseResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupengines.BackupEnginesClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupEnginesClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, BackupEngineBaseResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupEnginesClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate BackupEngineBaseResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]BackupEngineBaseResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_azurebackupserverengine.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_azurebackupserverengine.go new file mode 100644 index 00000000000..af20b6e3719 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_azurebackupserverengine.go @@ -0,0 +1,52 @@ +package backupengines + +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 _ BackupEngineBase = AzureBackupServerEngine{} + +type AzureBackupServerEngine struct { + + // Fields inherited from BackupEngineBase + AzureBackupAgentVersion *string `json:"azureBackupAgentVersion,omitempty"` + BackupEngineId *string `json:"backupEngineId,omitempty"` + BackupEngineState *string `json:"backupEngineState,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + CanReRegister *bool `json:"canReRegister,omitempty"` + DpmVersion *string `json:"dpmVersion,omitempty"` + ExtendedInfo *BackupEngineExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + IsAzureBackupAgentUpgradeAvailable *bool `json:"isAzureBackupAgentUpgradeAvailable,omitempty"` + IsDpmUpgradeAvailable *bool `json:"isDpmUpgradeAvailable,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureBackupServerEngine{} + +func (s AzureBackupServerEngine) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupServerEngine + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupServerEngine: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupServerEngine: %+v", err) + } + decoded["backupEngineType"] = "AzureBackupServerEngine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupServerEngine: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupenginebase.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupenginebase.go new file mode 100644 index 00000000000..5dd5ae0c534 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupenginebase.go @@ -0,0 +1,56 @@ +package backupengines + +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 BackupEngineBase interface { +} + +func unmarshalBackupEngineBaseImplementation(input []byte) (BackupEngineBase, 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 BackupEngineBase into map[string]interface: %+v", err) + } + + value, ok := temp["backupEngineType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupServerEngine") { + var out AzureBackupServerEngine + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupServerEngine: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DpmBackupEngine") { + var out DpmBackupEngine + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DpmBackupEngine: %+v", err) + } + return out, nil + } + + type RawBackupEngineBaseImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawBackupEngineBaseImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupenginebaseresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupenginebaseresource.go new file mode 100644 index 00000000000..d7eac2e8d35 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupenginebaseresource.go @@ -0,0 +1,50 @@ +package backupengines + +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 BackupEngineBaseResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties BackupEngineBase `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &BackupEngineBaseResource{} + +func (s *BackupEngineBaseResource) UnmarshalJSON(bytes []byte) error { + type alias BackupEngineBaseResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into BackupEngineBaseResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BackupEngineBaseResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalBackupEngineBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'BackupEngineBaseResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupengineextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupengineextendedinfo.go new file mode 100644 index 00000000000..cf19ed8a259 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_backupengineextendedinfo.go @@ -0,0 +1,33 @@ +package backupengines + +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 BackupEngineExtendedInfo struct { + AvailableDiskSpace *float64 `json:"availableDiskSpace,omitempty"` + AzureProtectedInstances *int64 `json:"azureProtectedInstances,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + DiskCount *int64 `json:"diskCount,omitempty"` + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ProtectedServersCount *int64 `json:"protectedServersCount,omitempty"` + RefreshedAt *string `json:"refreshedAt,omitempty"` + UsedDiskSpace *float64 `json:"usedDiskSpace,omitempty"` +} + +func (o *BackupEngineExtendedInfo) GetRefreshedAtAsTime() (*time.Time, error) { + if o.RefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *BackupEngineExtendedInfo) SetRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RefreshedAt = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_dpmbackupengine.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_dpmbackupengine.go new file mode 100644 index 00000000000..5d5df373244 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/model_dpmbackupengine.go @@ -0,0 +1,52 @@ +package backupengines + +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 _ BackupEngineBase = DpmBackupEngine{} + +type DpmBackupEngine struct { + + // Fields inherited from BackupEngineBase + AzureBackupAgentVersion *string `json:"azureBackupAgentVersion,omitempty"` + BackupEngineId *string `json:"backupEngineId,omitempty"` + BackupEngineState *string `json:"backupEngineState,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + CanReRegister *bool `json:"canReRegister,omitempty"` + DpmVersion *string `json:"dpmVersion,omitempty"` + ExtendedInfo *BackupEngineExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + IsAzureBackupAgentUpgradeAvailable *bool `json:"isAzureBackupAgentUpgradeAvailable,omitempty"` + IsDpmUpgradeAvailable *bool `json:"isDpmUpgradeAvailable,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = DpmBackupEngine{} + +func (s DpmBackupEngine) MarshalJSON() ([]byte, error) { + type wrapper DpmBackupEngine + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DpmBackupEngine: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DpmBackupEngine: %+v", err) + } + decoded["backupEngineType"] = "DpmBackupEngine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DpmBackupEngine: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/predicates.go new file mode 100644 index 00000000000..05d5e184fb4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/predicates.go @@ -0,0 +1,37 @@ +package backupengines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupEngineBaseResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p BackupEngineBaseResourceOperationPredicate) Matches(input BackupEngineBaseResource) 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/recoveryservicesbackup/2023-02-01/backupengines/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/version.go new file mode 100644 index 00000000000..6f049e527a1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupengines/version.go @@ -0,0 +1,12 @@ +package backupengines + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupengines/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/README.md new file mode 100644 index 00000000000..bfdb2925697 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs` Documentation + +The `backupjobs` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupjobs" +``` + + +### Client Initialization + +```go +client := backupjobs.NewBackupJobsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupJobsClient.List` + +```go +ctx := context.TODO() +id := backupjobs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, backupjobs.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backupjobs.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/client.go new file mode 100644 index 00000000000..79d95da7560 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/client.go @@ -0,0 +1,18 @@ +package backupjobs + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupJobsClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupJobsClientWithBaseURI(endpoint string) BackupJobsClient { + return BackupJobsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/constants.go new file mode 100644 index 00000000000..15209b39988 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/constants.go @@ -0,0 +1,223 @@ +package backupjobs + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type JobSupportedAction string + +const ( + JobSupportedActionCancellable JobSupportedAction = "Cancellable" + JobSupportedActionInvalid JobSupportedAction = "Invalid" + JobSupportedActionRetriable JobSupportedAction = "Retriable" +) + +func PossibleValuesForJobSupportedAction() []string { + return []string{ + string(JobSupportedActionCancellable), + string(JobSupportedActionInvalid), + string(JobSupportedActionRetriable), + } +} + +func parseJobSupportedAction(input string) (*JobSupportedAction, error) { + vals := map[string]JobSupportedAction{ + "cancellable": JobSupportedActionCancellable, + "invalid": JobSupportedActionInvalid, + "retriable": JobSupportedActionRetriable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobSupportedAction(input) + return &out, nil +} + +type MabServerType string + +const ( + MabServerTypeAzureBackupServerContainer MabServerType = "AzureBackupServerContainer" + MabServerTypeAzureSqlContainer MabServerType = "AzureSqlContainer" + MabServerTypeCluster MabServerType = "Cluster" + MabServerTypeDPMContainer MabServerType = "DPMContainer" + MabServerTypeGenericContainer MabServerType = "GenericContainer" + MabServerTypeIaasVMContainer MabServerType = "IaasVMContainer" + MabServerTypeIaasVMServiceContainer MabServerType = "IaasVMServiceContainer" + MabServerTypeInvalid MabServerType = "Invalid" + MabServerTypeMABContainer MabServerType = "MABContainer" + MabServerTypeSQLAGWorkLoadContainer MabServerType = "SQLAGWorkLoadContainer" + MabServerTypeStorageContainer MabServerType = "StorageContainer" + MabServerTypeUnknown MabServerType = "Unknown" + MabServerTypeVCenter MabServerType = "VCenter" + MabServerTypeVMAppContainer MabServerType = "VMAppContainer" + MabServerTypeWindows MabServerType = "Windows" +) + +func PossibleValuesForMabServerType() []string { + return []string{ + string(MabServerTypeAzureBackupServerContainer), + string(MabServerTypeAzureSqlContainer), + string(MabServerTypeCluster), + string(MabServerTypeDPMContainer), + string(MabServerTypeGenericContainer), + string(MabServerTypeIaasVMContainer), + string(MabServerTypeIaasVMServiceContainer), + string(MabServerTypeInvalid), + string(MabServerTypeMABContainer), + string(MabServerTypeSQLAGWorkLoadContainer), + string(MabServerTypeStorageContainer), + string(MabServerTypeUnknown), + string(MabServerTypeVCenter), + string(MabServerTypeVMAppContainer), + string(MabServerTypeWindows), + } +} + +func parseMabServerType(input string) (*MabServerType, error) { + vals := map[string]MabServerType{ + "azurebackupservercontainer": MabServerTypeAzureBackupServerContainer, + "azuresqlcontainer": MabServerTypeAzureSqlContainer, + "cluster": MabServerTypeCluster, + "dpmcontainer": MabServerTypeDPMContainer, + "genericcontainer": MabServerTypeGenericContainer, + "iaasvmcontainer": MabServerTypeIaasVMContainer, + "iaasvmservicecontainer": MabServerTypeIaasVMServiceContainer, + "invalid": MabServerTypeInvalid, + "mabcontainer": MabServerTypeMABContainer, + "sqlagworkloadcontainer": MabServerTypeSQLAGWorkLoadContainer, + "storagecontainer": MabServerTypeStorageContainer, + "unknown": MabServerTypeUnknown, + "vcenter": MabServerTypeVCenter, + "vmappcontainer": MabServerTypeVMAppContainer, + "windows": MabServerTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MabServerType(input) + return &out, nil +} + +type WorkloadType string + +const ( + WorkloadTypeAzureFileShare WorkloadType = "AzureFileShare" + WorkloadTypeAzureSqlDb WorkloadType = "AzureSqlDb" + WorkloadTypeClient WorkloadType = "Client" + WorkloadTypeExchange WorkloadType = "Exchange" + WorkloadTypeFileFolder WorkloadType = "FileFolder" + WorkloadTypeGenericDataSource WorkloadType = "GenericDataSource" + WorkloadTypeInvalid WorkloadType = "Invalid" + WorkloadTypeSAPAseDatabase WorkloadType = "SAPAseDatabase" + WorkloadTypeSAPHanaDBInstance WorkloadType = "SAPHanaDBInstance" + WorkloadTypeSAPHanaDatabase WorkloadType = "SAPHanaDatabase" + WorkloadTypeSQLDB WorkloadType = "SQLDB" + WorkloadTypeSQLDataBase WorkloadType = "SQLDataBase" + WorkloadTypeSharepoint WorkloadType = "Sharepoint" + WorkloadTypeSystemState WorkloadType = "SystemState" + WorkloadTypeVM WorkloadType = "VM" + WorkloadTypeVMwareVM WorkloadType = "VMwareVM" +) + +func PossibleValuesForWorkloadType() []string { + return []string{ + string(WorkloadTypeAzureFileShare), + string(WorkloadTypeAzureSqlDb), + string(WorkloadTypeClient), + string(WorkloadTypeExchange), + string(WorkloadTypeFileFolder), + string(WorkloadTypeGenericDataSource), + string(WorkloadTypeInvalid), + string(WorkloadTypeSAPAseDatabase), + string(WorkloadTypeSAPHanaDBInstance), + string(WorkloadTypeSAPHanaDatabase), + string(WorkloadTypeSQLDB), + string(WorkloadTypeSQLDataBase), + string(WorkloadTypeSharepoint), + string(WorkloadTypeSystemState), + string(WorkloadTypeVM), + string(WorkloadTypeVMwareVM), + } +} + +func parseWorkloadType(input string) (*WorkloadType, error) { + vals := map[string]WorkloadType{ + "azurefileshare": WorkloadTypeAzureFileShare, + "azuresqldb": WorkloadTypeAzureSqlDb, + "client": WorkloadTypeClient, + "exchange": WorkloadTypeExchange, + "filefolder": WorkloadTypeFileFolder, + "genericdatasource": WorkloadTypeGenericDataSource, + "invalid": WorkloadTypeInvalid, + "sapasedatabase": WorkloadTypeSAPAseDatabase, + "saphanadbinstance": WorkloadTypeSAPHanaDBInstance, + "saphanadatabase": WorkloadTypeSAPHanaDatabase, + "sqldb": WorkloadTypeSQLDB, + "sqldatabase": WorkloadTypeSQLDataBase, + "sharepoint": WorkloadTypeSharepoint, + "systemstate": WorkloadTypeSystemState, + "vm": WorkloadTypeVM, + "vmwarevm": WorkloadTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkloadType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/id_vault.go new file mode 100644 index 00000000000..a53d093d5d0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/id_vault.go @@ -0,0 +1,127 @@ +package backupjobs + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/id_vault_test.go new file mode 100644 index 00000000000..4b9b1c86ee8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/id_vault_test.go @@ -0,0 +1,282 @@ +package backupjobs + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupjobs/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/method_list_autorest.go new file mode 100644 index 00000000000..81e1c19dc60 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/method_list_autorest.go @@ -0,0 +1,215 @@ +package backupjobs + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]JobResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []JobResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupJobsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupjobs.BackupJobsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupjobs.BackupJobsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupjobs.BackupJobsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupJobsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupJobs", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupJobsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupJobsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []JobResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backupjobs.BackupJobsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupjobs.BackupJobsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupjobs.BackupJobsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupJobsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, JobResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupJobsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate JobResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]JobResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmerrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmerrorinfo.go new file mode 100644 index 00000000000..d9fe5b31814 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmerrorinfo.go @@ -0,0 +1,11 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureIaaSVMErrorInfo struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + ErrorTitle *string `json:"errorTitle,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjob.go new file mode 100644 index 00000000000..7bf1b7e0e61 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjob.go @@ -0,0 +1,81 @@ +package backupjobs + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureIaaSVMJob{} + +type AzureIaaSVMJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureIaaSVMErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureIaaSVMJobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered *bool `json:"isUserTriggered,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureIaaSVMJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureIaaSVMJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureIaaSVMJob{} + +func (s AzureIaaSVMJob) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMJob: %+v", err) + } + decoded["jobType"] = "AzureIaaSVMJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobextendedinfo.go new file mode 100644 index 00000000000..8fd0ef0f439 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobextendedinfo.go @@ -0,0 +1,13 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureIaaSVMJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + EstimatedRemainingDuration *string `json:"estimatedRemainingDuration,omitempty"` + InternalPropertyBag *map[string]string `json:"internalPropertyBag,omitempty"` + ProgressPercentage *float64 `json:"progressPercentage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]AzureIaaSVMJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobtaskdetails.go new file mode 100644 index 00000000000..dad4a07a3ba --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobtaskdetails.go @@ -0,0 +1,45 @@ +package backupjobs + +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 AzureIaaSVMJobTaskDetails struct { + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + InstanceId *string `json:"instanceId,omitempty"` + ProgressPercentage *float64 `json:"progressPercentage,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + TaskExecutionDetails *string `json:"taskExecutionDetails,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} + +func (o *AzureIaaSVMJobTaskDetails) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobTaskDetails) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureIaaSVMJobTaskDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobTaskDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobv2.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobv2.go new file mode 100644 index 00000000000..8512e3d4550 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureiaasvmjobv2.go @@ -0,0 +1,80 @@ +package backupjobs + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureIaaSVMJobV2{} + +type AzureIaaSVMJobV2 struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureIaaSVMErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureIaaSVMJobExtendedInfo `json:"extendedInfo,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureIaaSVMJobV2) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobV2) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureIaaSVMJobV2) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobV2) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureIaaSVMJobV2{} + +func (s AzureIaaSVMJobV2) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMJobV2 + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMJobV2: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMJobV2: %+v", err) + } + decoded["jobType"] = "AzureIaaSVMJobV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMJobV2: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestorageerrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestorageerrorinfo.go new file mode 100644 index 00000000000..9a52a41965c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestorageerrorinfo.go @@ -0,0 +1,10 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStorageErrorInfo struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejob.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejob.go new file mode 100644 index 00000000000..d0ea1e45479 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejob.go @@ -0,0 +1,81 @@ +package backupjobs + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureStorageJob{} + +type AzureStorageJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureStorageErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureStorageJobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered *bool `json:"isUserTriggered,omitempty"` + StorageAccountName *string `json:"storageAccountName,omitempty"` + StorageAccountVersion *string `json:"storageAccountVersion,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureStorageJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureStorageJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureStorageJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureStorageJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureStorageJob{} + +func (s AzureStorageJob) MarshalJSON() ([]byte, error) { + type wrapper AzureStorageJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureStorageJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureStorageJob: %+v", err) + } + decoded["jobType"] = "AzureStorageJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureStorageJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejobextendedinfo.go new file mode 100644 index 00000000000..22b7d4107d7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejobextendedinfo.go @@ -0,0 +1,10 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStorageJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]AzureStorageJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejobtaskdetails.go new file mode 100644 index 00000000000..9b9bb298d99 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azurestoragejobtaskdetails.go @@ -0,0 +1,9 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStorageJobTaskDetails struct { + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloaderrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloaderrorinfo.go new file mode 100644 index 00000000000..edc953a540c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloaderrorinfo.go @@ -0,0 +1,12 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadErrorInfo struct { + AdditionalDetails *string `json:"additionalDetails,omitempty"` + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + ErrorTitle *string `json:"errorTitle,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjob.go new file mode 100644 index 00000000000..5432c48ce4f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjob.go @@ -0,0 +1,79 @@ +package backupjobs + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureWorkloadJob{} + +type AzureWorkloadJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureWorkloadErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureWorkloadJobExtendedInfo `json:"extendedInfo,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureWorkloadJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureWorkloadJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureWorkloadJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureWorkloadJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureWorkloadJob{} + +func (s AzureWorkloadJob) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadJob: %+v", err) + } + decoded["jobType"] = "AzureWorkloadJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjobextendedinfo.go new file mode 100644 index 00000000000..160a414f7f3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjobextendedinfo.go @@ -0,0 +1,10 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]AzureWorkloadJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjobtaskdetails.go new file mode 100644 index 00000000000..0757ffec0fb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_azureworkloadjobtaskdetails.go @@ -0,0 +1,9 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadJobTaskDetails struct { + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmerrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmerrorinfo.go new file mode 100644 index 00000000000..091cf8f3157 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmerrorinfo.go @@ -0,0 +1,9 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpmErrorInfo struct { + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjob.go new file mode 100644 index 00000000000..ceabc044801 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjob.go @@ -0,0 +1,82 @@ +package backupjobs + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = DpmJob{} + +type DpmJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + ContainerType *string `json:"containerType,omitempty"` + DpmServerName *string `json:"dpmServerName,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]DpmErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *DpmJobExtendedInfo `json:"extendedInfo,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *DpmJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *DpmJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = DpmJob{} + +func (s DpmJob) MarshalJSON() ([]byte, error) { + type wrapper DpmJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DpmJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DpmJob: %+v", err) + } + decoded["jobType"] = "DpmJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DpmJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjobextendedinfo.go new file mode 100644 index 00000000000..6d4f63a2296 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjobextendedinfo.go @@ -0,0 +1,10 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpmJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]DpmJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjobtaskdetails.go new file mode 100644 index 00000000000..ebf8a7cd691 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_dpmjobtaskdetails.go @@ -0,0 +1,42 @@ +package backupjobs + +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 DpmJobTaskDetails struct { + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} + +func (o *DpmJobTaskDetails) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJobTaskDetails) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *DpmJobTaskDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJobTaskDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_job.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_job.go new file mode 100644 index 00000000000..7724a031beb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_job.go @@ -0,0 +1,96 @@ +package backupjobs + +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 Job interface { +} + +func unmarshalJobImplementation(input []byte) (Job, 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 Job into map[string]interface: %+v", err) + } + + value, ok := temp["jobType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureIaaSVMJob") { + var out AzureIaaSVMJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureIaaSVMJobV2") { + var out AzureIaaSVMJobV2 + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMJobV2: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureStorageJob") { + var out AzureStorageJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureStorageJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadJob") { + var out AzureWorkloadJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DpmJob") { + var out DpmJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DpmJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MabJob") { + var out MabJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VaultJob") { + var out VaultJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VaultJob: %+v", err) + } + return out, nil + } + + type RawJobImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawJobImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_jobresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_jobresource.go new file mode 100644 index 00000000000..cb6a61ab28c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_jobresource.go @@ -0,0 +1,50 @@ +package backupjobs + +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 JobResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties Job `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &JobResource{} + +func (s *JobResource) UnmarshalJSON(bytes []byte) error { + type alias JobResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalJobImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'JobResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_maberrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_maberrorinfo.go new file mode 100644 index 00000000000..9c3668d2bd5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_maberrorinfo.go @@ -0,0 +1,9 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MabErrorInfo struct { + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjob.go new file mode 100644 index 00000000000..d1e4eda593c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjob.go @@ -0,0 +1,81 @@ +package backupjobs + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = MabJob{} + +type MabJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]MabErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *MabJobExtendedInfo `json:"extendedInfo,omitempty"` + MabServerName *string `json:"mabServerName,omitempty"` + MabServerType *MabServerType `json:"mabServerType,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *MabJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *MabJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = MabJob{} + +func (s MabJob) MarshalJSON() ([]byte, error) { + type wrapper MabJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabJob: %+v", err) + } + decoded["jobType"] = "MabJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjobextendedinfo.go new file mode 100644 index 00000000000..eb61f914ed9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjobextendedinfo.go @@ -0,0 +1,10 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MabJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]MabJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjobtaskdetails.go new file mode 100644 index 00000000000..15efde49be8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_mabjobtaskdetails.go @@ -0,0 +1,42 @@ +package backupjobs + +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 MabJobTaskDetails struct { + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} + +func (o *MabJobTaskDetails) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJobTaskDetails) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *MabJobTaskDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJobTaskDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjob.go new file mode 100644 index 00000000000..ac59fa1e242 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjob.go @@ -0,0 +1,78 @@ +package backupjobs + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = VaultJob{} + +type VaultJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]VaultJobErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *VaultJobExtendedInfo `json:"extendedInfo,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *VaultJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VaultJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *VaultJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VaultJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = VaultJob{} + +func (s VaultJob) MarshalJSON() ([]byte, error) { + type wrapper VaultJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VaultJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VaultJob: %+v", err) + } + decoded["jobType"] = "VaultJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VaultJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjoberrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjoberrorinfo.go new file mode 100644 index 00000000000..cca822b6d80 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjoberrorinfo.go @@ -0,0 +1,10 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultJobErrorInfo struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjobextendedinfo.go new file mode 100644 index 00000000000..ad9c628fcf1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/model_vaultjobextendedinfo.go @@ -0,0 +1,8 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultJobExtendedInfo struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/predicates.go new file mode 100644 index 00000000000..00ced650b3e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/predicates.go @@ -0,0 +1,37 @@ +package backupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p JobResourceOperationPredicate) Matches(input JobResource) 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/recoveryservicesbackup/2023-02-01/backupjobs/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/version.go new file mode 100644 index 00000000000..7cbbb41af37 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs/version.go @@ -0,0 +1,12 @@ +package backupjobs + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupjobs/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/README.md new file mode 100644 index 00000000000..ae2dba1bb95 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies` Documentation + +The `backuppolicies` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backuppolicies" +``` + + +### Client Initialization + +```go +client := backuppolicies.NewBackupPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupPoliciesClient.List` + +```go +ctx := context.TODO() +id := backuppolicies.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, backuppolicies.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backuppolicies.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/client.go new file mode 100644 index 00000000000..c8b3aad1674 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/client.go @@ -0,0 +1,18 @@ +package backuppolicies + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupPoliciesClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupPoliciesClientWithBaseURI(endpoint string) BackupPoliciesClient { + return BackupPoliciesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/constants.go new file mode 100644 index 00000000000..16145295003 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/constants.go @@ -0,0 +1,433 @@ +package backuppolicies + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} + +type IAASVMPolicyType string + +const ( + IAASVMPolicyTypeInvalid IAASVMPolicyType = "Invalid" + IAASVMPolicyTypeVOne IAASVMPolicyType = "V1" + IAASVMPolicyTypeVTwo IAASVMPolicyType = "V2" +) + +func PossibleValuesForIAASVMPolicyType() []string { + return []string{ + string(IAASVMPolicyTypeInvalid), + string(IAASVMPolicyTypeVOne), + string(IAASVMPolicyTypeVTwo), + } +} + +func parseIAASVMPolicyType(input string) (*IAASVMPolicyType, error) { + vals := map[string]IAASVMPolicyType{ + "invalid": IAASVMPolicyTypeInvalid, + "v1": IAASVMPolicyTypeVOne, + "v2": IAASVMPolicyTypeVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IAASVMPolicyType(input) + return &out, nil +} + +type MonthOfYear string + +const ( + MonthOfYearApril MonthOfYear = "April" + MonthOfYearAugust MonthOfYear = "August" + MonthOfYearDecember MonthOfYear = "December" + MonthOfYearFebruary MonthOfYear = "February" + MonthOfYearInvalid MonthOfYear = "Invalid" + MonthOfYearJanuary MonthOfYear = "January" + MonthOfYearJuly MonthOfYear = "July" + MonthOfYearJune MonthOfYear = "June" + MonthOfYearMarch MonthOfYear = "March" + MonthOfYearMay MonthOfYear = "May" + MonthOfYearNovember MonthOfYear = "November" + MonthOfYearOctober MonthOfYear = "October" + MonthOfYearSeptember MonthOfYear = "September" +) + +func PossibleValuesForMonthOfYear() []string { + return []string{ + string(MonthOfYearApril), + string(MonthOfYearAugust), + string(MonthOfYearDecember), + string(MonthOfYearFebruary), + string(MonthOfYearInvalid), + string(MonthOfYearJanuary), + string(MonthOfYearJuly), + string(MonthOfYearJune), + string(MonthOfYearMarch), + string(MonthOfYearMay), + string(MonthOfYearNovember), + string(MonthOfYearOctober), + string(MonthOfYearSeptember), + } +} + +func parseMonthOfYear(input string) (*MonthOfYear, error) { + vals := map[string]MonthOfYear{ + "april": MonthOfYearApril, + "august": MonthOfYearAugust, + "december": MonthOfYearDecember, + "february": MonthOfYearFebruary, + "invalid": MonthOfYearInvalid, + "january": MonthOfYearJanuary, + "july": MonthOfYearJuly, + "june": MonthOfYearJune, + "march": MonthOfYearMarch, + "may": MonthOfYearMay, + "november": MonthOfYearNovember, + "october": MonthOfYearOctober, + "september": MonthOfYearSeptember, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MonthOfYear(input) + return &out, nil +} + +type PolicyType string + +const ( + PolicyTypeCopyOnlyFull PolicyType = "CopyOnlyFull" + PolicyTypeDifferential PolicyType = "Differential" + PolicyTypeFull PolicyType = "Full" + PolicyTypeIncremental PolicyType = "Incremental" + PolicyTypeInvalid PolicyType = "Invalid" + PolicyTypeLog PolicyType = "Log" + PolicyTypeSnapshotCopyOnlyFull PolicyType = "SnapshotCopyOnlyFull" + PolicyTypeSnapshotFull PolicyType = "SnapshotFull" +) + +func PossibleValuesForPolicyType() []string { + return []string{ + string(PolicyTypeCopyOnlyFull), + string(PolicyTypeDifferential), + string(PolicyTypeFull), + string(PolicyTypeIncremental), + string(PolicyTypeInvalid), + string(PolicyTypeLog), + string(PolicyTypeSnapshotCopyOnlyFull), + string(PolicyTypeSnapshotFull), + } +} + +func parsePolicyType(input string) (*PolicyType, error) { + vals := map[string]PolicyType{ + "copyonlyfull": PolicyTypeCopyOnlyFull, + "differential": PolicyTypeDifferential, + "full": PolicyTypeFull, + "incremental": PolicyTypeIncremental, + "invalid": PolicyTypeInvalid, + "log": PolicyTypeLog, + "snapshotcopyonlyfull": PolicyTypeSnapshotCopyOnlyFull, + "snapshotfull": PolicyTypeSnapshotFull, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyType(input) + return &out, nil +} + +type RetentionDurationType string + +const ( + RetentionDurationTypeDays RetentionDurationType = "Days" + RetentionDurationTypeInvalid RetentionDurationType = "Invalid" + RetentionDurationTypeMonths RetentionDurationType = "Months" + RetentionDurationTypeWeeks RetentionDurationType = "Weeks" + RetentionDurationTypeYears RetentionDurationType = "Years" +) + +func PossibleValuesForRetentionDurationType() []string { + return []string{ + string(RetentionDurationTypeDays), + string(RetentionDurationTypeInvalid), + string(RetentionDurationTypeMonths), + string(RetentionDurationTypeWeeks), + string(RetentionDurationTypeYears), + } +} + +func parseRetentionDurationType(input string) (*RetentionDurationType, error) { + vals := map[string]RetentionDurationType{ + "days": RetentionDurationTypeDays, + "invalid": RetentionDurationTypeInvalid, + "months": RetentionDurationTypeMonths, + "weeks": RetentionDurationTypeWeeks, + "years": RetentionDurationTypeYears, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RetentionDurationType(input) + return &out, nil +} + +type RetentionScheduleFormat string + +const ( + RetentionScheduleFormatDaily RetentionScheduleFormat = "Daily" + RetentionScheduleFormatInvalid RetentionScheduleFormat = "Invalid" + RetentionScheduleFormatWeekly RetentionScheduleFormat = "Weekly" +) + +func PossibleValuesForRetentionScheduleFormat() []string { + return []string{ + string(RetentionScheduleFormatDaily), + string(RetentionScheduleFormatInvalid), + string(RetentionScheduleFormatWeekly), + } +} + +func parseRetentionScheduleFormat(input string) (*RetentionScheduleFormat, error) { + vals := map[string]RetentionScheduleFormat{ + "daily": RetentionScheduleFormatDaily, + "invalid": RetentionScheduleFormatInvalid, + "weekly": RetentionScheduleFormatWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RetentionScheduleFormat(input) + return &out, nil +} + +type ScheduleRunType string + +const ( + ScheduleRunTypeDaily ScheduleRunType = "Daily" + ScheduleRunTypeHourly ScheduleRunType = "Hourly" + ScheduleRunTypeInvalid ScheduleRunType = "Invalid" + ScheduleRunTypeWeekly ScheduleRunType = "Weekly" +) + +func PossibleValuesForScheduleRunType() []string { + return []string{ + string(ScheduleRunTypeDaily), + string(ScheduleRunTypeHourly), + string(ScheduleRunTypeInvalid), + string(ScheduleRunTypeWeekly), + } +} + +func parseScheduleRunType(input string) (*ScheduleRunType, error) { + vals := map[string]ScheduleRunType{ + "daily": ScheduleRunTypeDaily, + "hourly": ScheduleRunTypeHourly, + "invalid": ScheduleRunTypeInvalid, + "weekly": ScheduleRunTypeWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduleRunType(input) + return &out, nil +} + +type TieringMode string + +const ( + TieringModeDoNotTier TieringMode = "DoNotTier" + TieringModeInvalid TieringMode = "Invalid" + TieringModeTierAfter TieringMode = "TierAfter" + TieringModeTierRecommended TieringMode = "TierRecommended" +) + +func PossibleValuesForTieringMode() []string { + return []string{ + string(TieringModeDoNotTier), + string(TieringModeInvalid), + string(TieringModeTierAfter), + string(TieringModeTierRecommended), + } +} + +func parseTieringMode(input string) (*TieringMode, error) { + vals := map[string]TieringMode{ + "donottier": TieringModeDoNotTier, + "invalid": TieringModeInvalid, + "tierafter": TieringModeTierAfter, + "tierrecommended": TieringModeTierRecommended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TieringMode(input) + return &out, nil +} + +type WeekOfMonth string + +const ( + WeekOfMonthFirst WeekOfMonth = "First" + WeekOfMonthFourth WeekOfMonth = "Fourth" + WeekOfMonthInvalid WeekOfMonth = "Invalid" + WeekOfMonthLast WeekOfMonth = "Last" + WeekOfMonthSecond WeekOfMonth = "Second" + WeekOfMonthThird WeekOfMonth = "Third" +) + +func PossibleValuesForWeekOfMonth() []string { + return []string{ + string(WeekOfMonthFirst), + string(WeekOfMonthFourth), + string(WeekOfMonthInvalid), + string(WeekOfMonthLast), + string(WeekOfMonthSecond), + string(WeekOfMonthThird), + } +} + +func parseWeekOfMonth(input string) (*WeekOfMonth, error) { + vals := map[string]WeekOfMonth{ + "first": WeekOfMonthFirst, + "fourth": WeekOfMonthFourth, + "invalid": WeekOfMonthInvalid, + "last": WeekOfMonthLast, + "second": WeekOfMonthSecond, + "third": WeekOfMonthThird, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WeekOfMonth(input) + return &out, nil +} + +type WorkloadType string + +const ( + WorkloadTypeAzureFileShare WorkloadType = "AzureFileShare" + WorkloadTypeAzureSqlDb WorkloadType = "AzureSqlDb" + WorkloadTypeClient WorkloadType = "Client" + WorkloadTypeExchange WorkloadType = "Exchange" + WorkloadTypeFileFolder WorkloadType = "FileFolder" + WorkloadTypeGenericDataSource WorkloadType = "GenericDataSource" + WorkloadTypeInvalid WorkloadType = "Invalid" + WorkloadTypeSAPAseDatabase WorkloadType = "SAPAseDatabase" + WorkloadTypeSAPHanaDBInstance WorkloadType = "SAPHanaDBInstance" + WorkloadTypeSAPHanaDatabase WorkloadType = "SAPHanaDatabase" + WorkloadTypeSQLDB WorkloadType = "SQLDB" + WorkloadTypeSQLDataBase WorkloadType = "SQLDataBase" + WorkloadTypeSharepoint WorkloadType = "Sharepoint" + WorkloadTypeSystemState WorkloadType = "SystemState" + WorkloadTypeVM WorkloadType = "VM" + WorkloadTypeVMwareVM WorkloadType = "VMwareVM" +) + +func PossibleValuesForWorkloadType() []string { + return []string{ + string(WorkloadTypeAzureFileShare), + string(WorkloadTypeAzureSqlDb), + string(WorkloadTypeClient), + string(WorkloadTypeExchange), + string(WorkloadTypeFileFolder), + string(WorkloadTypeGenericDataSource), + string(WorkloadTypeInvalid), + string(WorkloadTypeSAPAseDatabase), + string(WorkloadTypeSAPHanaDBInstance), + string(WorkloadTypeSAPHanaDatabase), + string(WorkloadTypeSQLDB), + string(WorkloadTypeSQLDataBase), + string(WorkloadTypeSharepoint), + string(WorkloadTypeSystemState), + string(WorkloadTypeVM), + string(WorkloadTypeVMwareVM), + } +} + +func parseWorkloadType(input string) (*WorkloadType, error) { + vals := map[string]WorkloadType{ + "azurefileshare": WorkloadTypeAzureFileShare, + "azuresqldb": WorkloadTypeAzureSqlDb, + "client": WorkloadTypeClient, + "exchange": WorkloadTypeExchange, + "filefolder": WorkloadTypeFileFolder, + "genericdatasource": WorkloadTypeGenericDataSource, + "invalid": WorkloadTypeInvalid, + "sapasedatabase": WorkloadTypeSAPAseDatabase, + "saphanadbinstance": WorkloadTypeSAPHanaDBInstance, + "saphanadatabase": WorkloadTypeSAPHanaDatabase, + "sqldb": WorkloadTypeSQLDB, + "sqldatabase": WorkloadTypeSQLDataBase, + "sharepoint": WorkloadTypeSharepoint, + "systemstate": WorkloadTypeSystemState, + "vm": WorkloadTypeVM, + "vmwarevm": WorkloadTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkloadType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/id_vault.go new file mode 100644 index 00000000000..016a82e5666 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/id_vault.go @@ -0,0 +1,127 @@ +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/id_vault_test.go new file mode 100644 index 00000000000..47c90af07c2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/id_vault_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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backuppolicies/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/method_list_autorest.go new file mode 100644 index 00000000000..094b05fed04 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/method_list_autorest.go @@ -0,0 +1,215 @@ +package backuppolicies + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionPolicyResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ProtectionPolicyResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupPoliciesClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backuppolicies.BackupPoliciesClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backuppolicies.BackupPoliciesClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backuppolicies.BackupPoliciesClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupPoliciesClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupPolicies", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupPoliciesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupPoliciesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ProtectionPolicyResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backuppolicies.BackupPoliciesClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backuppolicies.BackupPoliciesClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backuppolicies.BackupPoliciesClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupPoliciesClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ProtectionPolicyResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupPoliciesClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate ProtectionPolicyResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ProtectionPolicyResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azurefileshareprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azurefileshareprotectionpolicy.go new file mode 100644 index 00000000000..c0c6e9f2f0b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azurefileshareprotectionpolicy.go @@ -0,0 +1,83 @@ +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 _ ProtectionPolicy = AzureFileShareProtectionPolicy{} + +type AzureFileShareProtectionPolicy struct { + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + TimeZone *string `json:"timeZone,omitempty"` + WorkLoadType *WorkloadType `json:"workLoadType,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureFileShareProtectionPolicy{} + +func (s AzureFileShareProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureStorage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureFileShareProtectionPolicy{} + +func (s *AzureFileShareProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias AzureFileShareProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureFileShareProtectionPolicy: %+v", err) + } + + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.TimeZone = decoded.TimeZone + s.WorkLoadType = decoded.WorkLoadType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureFileShareProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'AzureFileShareProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'AzureFileShareProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azureiaasvmprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azureiaasvmprotectionpolicy.go new file mode 100644 index 00000000000..b120c1a48b9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azureiaasvmprotectionpolicy.go @@ -0,0 +1,89 @@ +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 _ ProtectionPolicy = AzureIaaSVMProtectionPolicy{} + +type AzureIaaSVMProtectionPolicy struct { + InstantRPDetails *InstantRPAdditionalDetails `json:"instantRPDetails,omitempty"` + InstantRpRetentionRangeInDays *int64 `json:"instantRpRetentionRangeInDays,omitempty"` + PolicyType *IAASVMPolicyType `json:"policyType,omitempty"` + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + TieringPolicy *map[string]TieringPolicy `json:"tieringPolicy,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureIaaSVMProtectionPolicy{} + +func (s AzureIaaSVMProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureIaasVM" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureIaaSVMProtectionPolicy{} + +func (s *AzureIaaSVMProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias AzureIaaSVMProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureIaaSVMProtectionPolicy: %+v", err) + } + + s.InstantRPDetails = decoded.InstantRPDetails + s.InstantRpRetentionRangeInDays = decoded.InstantRpRetentionRangeInDays + s.PolicyType = decoded.PolicyType + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.TieringPolicy = decoded.TieringPolicy + s.TimeZone = decoded.TimeZone + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureIaaSVMProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'AzureIaaSVMProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'AzureIaaSVMProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azuresqlprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azuresqlprotectionpolicy.go new file mode 100644 index 00000000000..81c80d157da --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azuresqlprotectionpolicy.go @@ -0,0 +1,70 @@ +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 _ ProtectionPolicy = AzureSqlProtectionPolicy{} + +type AzureSqlProtectionPolicy struct { + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureSqlProtectionPolicy{} + +func (s AzureSqlProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureSqlProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSqlProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSqlProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureSql" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSqlProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureSqlProtectionPolicy{} + +func (s *AzureSqlProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias AzureSqlProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureSqlProtectionPolicy: %+v", err) + } + + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureSqlProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'AzureSqlProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azurevmworkloadprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azurevmworkloadprotectionpolicy.go new file mode 100644 index 00000000000..0e318d65945 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_azurevmworkloadprotectionpolicy.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 _ ProtectionPolicy = AzureVMWorkloadProtectionPolicy{} + +type AzureVMWorkloadProtectionPolicy struct { + MakePolicyConsistent *bool `json:"makePolicyConsistent,omitempty"` + Settings *Settings `json:"settings,omitempty"` + SubProtectionPolicy *[]SubProtectionPolicy `json:"subProtectionPolicy,omitempty"` + WorkLoadType *WorkloadType `json:"workLoadType,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadProtectionPolicy{} + +func (s AzureVMWorkloadProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureWorkload" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadProtectionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyretentionformat.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyretentionformat.go new file mode 100644 index 00000000000..1c5f0a22c9b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyretentionformat.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 DailyRetentionFormat struct { + DaysOfTheMonth *[]Day `json:"daysOfTheMonth,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyretentionschedule.go new file mode 100644 index 00000000000..581a2b22ed5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyretentionschedule.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 DailyRetentionSchedule struct { + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyschedule.go new file mode 100644 index 00000000000..34b307b9262 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_dailyschedule.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 DailySchedule struct { + ScheduleRunTimes *[]string `json:"scheduleRunTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_day.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_day.go new file mode 100644 index 00000000000..c46c7f57129 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-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/recoveryservicesbackup/2023-02-01/backuppolicies/model_genericprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_genericprotectionpolicy.go new file mode 100644 index 00000000000..16227cb1edd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_genericprotectionpolicy.go @@ -0,0 +1,45 @@ +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 _ ProtectionPolicy = GenericProtectionPolicy{} + +type GenericProtectionPolicy struct { + FabricName *string `json:"fabricName,omitempty"` + SubProtectionPolicy *[]SubProtectionPolicy `json:"subProtectionPolicy,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = GenericProtectionPolicy{} + +func (s GenericProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper GenericProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "GenericProtectionPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericProtectionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_hourlyschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_hourlyschedule.go new file mode 100644 index 00000000000..f9f1a5a1d3c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_hourlyschedule.go @@ -0,0 +1,28 @@ +package backuppolicies + +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 HourlySchedule struct { + Interval *int64 `json:"interval,omitempty"` + ScheduleWindowDuration *int64 `json:"scheduleWindowDuration,omitempty"` + ScheduleWindowStartTime *string `json:"scheduleWindowStartTime,omitempty"` +} + +func (o *HourlySchedule) GetScheduleWindowStartTimeAsTime() (*time.Time, error) { + if o.ScheduleWindowStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ScheduleWindowStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HourlySchedule) SetScheduleWindowStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ScheduleWindowStartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_instantrpadditionaldetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_instantrpadditionaldetails.go new file mode 100644 index 00000000000..f70f265dc45 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_instantrpadditionaldetails.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 InstantRPAdditionalDetails struct { + AzureBackupRGNamePrefix *string `json:"azureBackupRGNamePrefix,omitempty"` + AzureBackupRGNameSuffix *string `json:"azureBackupRGNameSuffix,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_logschedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_logschedulepolicy.go new file mode 100644 index 00000000000..b4c2dd2d4f8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_logschedulepolicy.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 _ SchedulePolicy = LogSchedulePolicy{} + +type LogSchedulePolicy struct { + ScheduleFrequencyInMins *int64 `json:"scheduleFrequencyInMins,omitempty"` + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = LogSchedulePolicy{} + +func (s LogSchedulePolicy) MarshalJSON() ([]byte, error) { + type wrapper LogSchedulePolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LogSchedulePolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LogSchedulePolicy: %+v", err) + } + decoded["schedulePolicyType"] = "LogSchedulePolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LogSchedulePolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_longtermretentionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_longtermretentionpolicy.go new file mode 100644 index 00000000000..4f27496b945 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_longtermretentionpolicy.go @@ -0,0 +1,44 @@ +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 _ RetentionPolicy = LongTermRetentionPolicy{} + +type LongTermRetentionPolicy struct { + DailySchedule *DailyRetentionSchedule `json:"dailySchedule,omitempty"` + MonthlySchedule *MonthlyRetentionSchedule `json:"monthlySchedule,omitempty"` + WeeklySchedule *WeeklyRetentionSchedule `json:"weeklySchedule,omitempty"` + YearlySchedule *YearlyRetentionSchedule `json:"yearlySchedule,omitempty"` + + // Fields inherited from RetentionPolicy +} + +var _ json.Marshaler = LongTermRetentionPolicy{} + +func (s LongTermRetentionPolicy) MarshalJSON() ([]byte, error) { + type wrapper LongTermRetentionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LongTermRetentionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LongTermRetentionPolicy: %+v", err) + } + decoded["retentionPolicyType"] = "LongTermRetentionPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LongTermRetentionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_longtermschedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_longtermschedulepolicy.go new file mode 100644 index 00000000000..00b2bec7ab3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_longtermschedulepolicy.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 _ SchedulePolicy = LongTermSchedulePolicy{} + +type LongTermSchedulePolicy struct { + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = LongTermSchedulePolicy{} + +func (s LongTermSchedulePolicy) MarshalJSON() ([]byte, error) { + type wrapper LongTermSchedulePolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LongTermSchedulePolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LongTermSchedulePolicy: %+v", err) + } + decoded["schedulePolicyType"] = "LongTermSchedulePolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LongTermSchedulePolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_mabprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_mabprotectionpolicy.go new file mode 100644 index 00000000000..066b0138a5c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_mabprotectionpolicy.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 _ ProtectionPolicy = MabProtectionPolicy{} + +type MabProtectionPolicy struct { + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = MabProtectionPolicy{} + +func (s MabProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper MabProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "MAB" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &MabProtectionPolicy{} + +func (s *MabProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias MabProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into MabProtectionPolicy: %+v", err) + } + + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling MabProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'MabProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'MabProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_monthlyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_monthlyretentionschedule.go new file mode 100644 index 00000000000..8b8118cc9ee --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_monthlyretentionschedule.go @@ -0,0 +1,12 @@ +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 MonthlyRetentionSchedule struct { + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionScheduleDaily *DailyRetentionFormat `json:"retentionScheduleDaily,omitempty"` + RetentionScheduleFormatType *RetentionScheduleFormat `json:"retentionScheduleFormatType,omitempty"` + RetentionScheduleWeekly *WeeklyRetentionFormat `json:"retentionScheduleWeekly,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_protectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_protectionpolicy.go new file mode 100644 index 00000000000..e8e4932e273 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_protectionpolicy.go @@ -0,0 +1,88 @@ +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 ProtectionPolicy interface { +} + +func unmarshalProtectionPolicyImplementation(input []byte) (ProtectionPolicy, 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 ProtectionPolicy into map[string]interface: %+v", err) + } + + value, ok := temp["backupManagementType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureStorage") { + var out AzureFileShareProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureIaasVM") { + var out AzureIaaSVMProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureSql") { + var out AzureSqlProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSqlProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkload") { + var out AzureVMWorkloadProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericProtectionPolicy") { + var out GenericProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MAB") { + var out MabProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabProtectionPolicy: %+v", err) + } + return out, nil + } + + type RawProtectionPolicyImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionPolicyImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_protectionpolicyresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_protectionpolicyresource.go new file mode 100644 index 00000000000..6af342ec8f9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_protectionpolicyresource.go @@ -0,0 +1,50 @@ +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 ProtectionPolicyResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectionPolicy `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionPolicyResource{} + +func (s *ProtectionPolicyResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectionPolicyResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionPolicyResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionPolicyResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectionPolicyResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_retentionduration.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_retentionduration.go new file mode 100644 index 00000000000..60ecd1bea07 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_retentionduration.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 RetentionDuration struct { + Count *int64 `json:"count,omitempty"` + DurationType *RetentionDurationType `json:"durationType,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_retentionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_retentionpolicy.go new file mode 100644 index 00000000000..fc122ad6ad9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_retentionpolicy.go @@ -0,0 +1,56 @@ +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 RetentionPolicy interface { +} + +func unmarshalRetentionPolicyImplementation(input []byte) (RetentionPolicy, 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 RetentionPolicy into map[string]interface: %+v", err) + } + + value, ok := temp["retentionPolicyType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "LongTermRetentionPolicy") { + var out LongTermRetentionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LongTermRetentionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SimpleRetentionPolicy") { + var out SimpleRetentionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SimpleRetentionPolicy: %+v", err) + } + return out, nil + } + + type RawRetentionPolicyImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRetentionPolicyImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_schedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_schedulepolicy.go new file mode 100644 index 00000000000..6ab1b19f162 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_schedulepolicy.go @@ -0,0 +1,72 @@ +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 SchedulePolicy interface { +} + +func unmarshalSchedulePolicyImplementation(input []byte) (SchedulePolicy, 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 SchedulePolicy into map[string]interface: %+v", err) + } + + value, ok := temp["schedulePolicyType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "LogSchedulePolicy") { + var out LogSchedulePolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LogSchedulePolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "LongTermSchedulePolicy") { + var out LongTermSchedulePolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LongTermSchedulePolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SimpleSchedulePolicy") { + var out SimpleSchedulePolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SimpleSchedulePolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SimpleSchedulePolicyV2") { + var out SimpleSchedulePolicyV2 + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SimpleSchedulePolicyV2: %+v", err) + } + return out, nil + } + + type RawSchedulePolicyImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawSchedulePolicyImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_settings.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_settings.go new file mode 100644 index 00000000000..c59cc13bdbe --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_settings.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 Settings struct { + IsCompression *bool `json:"isCompression,omitempty"` + Issqlcompression *bool `json:"issqlcompression,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleretentionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleretentionpolicy.go new file mode 100644 index 00000000000..6355b65c8af --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleretentionpolicy.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 _ RetentionPolicy = SimpleRetentionPolicy{} + +type SimpleRetentionPolicy struct { + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + + // Fields inherited from RetentionPolicy +} + +var _ json.Marshaler = SimpleRetentionPolicy{} + +func (s SimpleRetentionPolicy) MarshalJSON() ([]byte, error) { + type wrapper SimpleRetentionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SimpleRetentionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SimpleRetentionPolicy: %+v", err) + } + decoded["retentionPolicyType"] = "SimpleRetentionPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SimpleRetentionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleschedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleschedulepolicy.go new file mode 100644 index 00000000000..cf047b354c2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleschedulepolicy.go @@ -0,0 +1,45 @@ +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 _ SchedulePolicy = SimpleSchedulePolicy{} + +type SimpleSchedulePolicy struct { + HourlySchedule *HourlySchedule `json:"hourlySchedule,omitempty"` + ScheduleRunDays *[]DayOfWeek `json:"scheduleRunDays,omitempty"` + ScheduleRunFrequency *ScheduleRunType `json:"scheduleRunFrequency,omitempty"` + ScheduleRunTimes *[]string `json:"scheduleRunTimes,omitempty"` + ScheduleWeeklyFrequency *int64 `json:"scheduleWeeklyFrequency,omitempty"` + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = SimpleSchedulePolicy{} + +func (s SimpleSchedulePolicy) MarshalJSON() ([]byte, error) { + type wrapper SimpleSchedulePolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SimpleSchedulePolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SimpleSchedulePolicy: %+v", err) + } + decoded["schedulePolicyType"] = "SimpleSchedulePolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SimpleSchedulePolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleschedulepolicyv2.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleschedulepolicyv2.go new file mode 100644 index 00000000000..f8324d396c2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_simpleschedulepolicyv2.go @@ -0,0 +1,44 @@ +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 _ SchedulePolicy = SimpleSchedulePolicyV2{} + +type SimpleSchedulePolicyV2 struct { + DailySchedule *DailySchedule `json:"dailySchedule,omitempty"` + HourlySchedule *HourlySchedule `json:"hourlySchedule,omitempty"` + ScheduleRunFrequency *ScheduleRunType `json:"scheduleRunFrequency,omitempty"` + WeeklySchedule *WeeklySchedule `json:"weeklySchedule,omitempty"` + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = SimpleSchedulePolicyV2{} + +func (s SimpleSchedulePolicyV2) MarshalJSON() ([]byte, error) { + type wrapper SimpleSchedulePolicyV2 + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SimpleSchedulePolicyV2: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SimpleSchedulePolicyV2: %+v", err) + } + decoded["schedulePolicyType"] = "SimpleSchedulePolicyV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SimpleSchedulePolicyV2: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_subprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_subprotectionpolicy.go new file mode 100644 index 00000000000..057aa3243f7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_subprotectionpolicy.go @@ -0,0 +1,51 @@ +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 SubProtectionPolicy struct { + PolicyType *PolicyType `json:"policyType,omitempty"` + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + TieringPolicy *map[string]TieringPolicy `json:"tieringPolicy,omitempty"` +} + +var _ json.Unmarshaler = &SubProtectionPolicy{} + +func (s *SubProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias SubProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SubProtectionPolicy: %+v", err) + } + + s.PolicyType = decoded.PolicyType + s.TieringPolicy = decoded.TieringPolicy + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SubProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'SubProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'SubProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_tieringpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_tieringpolicy.go new file mode 100644 index 00000000000..6075f6ce494 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_tieringpolicy.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 TieringPolicy struct { + Duration *int64 `json:"duration,omitempty"` + DurationType *RetentionDurationType `json:"durationType,omitempty"` + TieringMode *TieringMode `json:"tieringMode,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyretentionformat.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyretentionformat.go new file mode 100644 index 00000000000..33dbf7e202c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyretentionformat.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 WeeklyRetentionFormat struct { + DaysOfTheWeek *[]DayOfWeek `json:"daysOfTheWeek,omitempty"` + WeeksOfTheMonth *[]WeekOfMonth `json:"weeksOfTheMonth,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyretentionschedule.go new file mode 100644 index 00000000000..edfa118dffc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyretentionschedule.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 WeeklyRetentionSchedule struct { + DaysOfTheWeek *[]DayOfWeek `json:"daysOfTheWeek,omitempty"` + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyschedule.go new file mode 100644 index 00000000000..93dcb41a53c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_weeklyschedule.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 WeeklySchedule struct { + ScheduleRunDays *[]DayOfWeek `json:"scheduleRunDays,omitempty"` + ScheduleRunTimes *[]string `json:"scheduleRunTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_yearlyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_yearlyretentionschedule.go new file mode 100644 index 00000000000..f2c784a79d6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/model_yearlyretentionschedule.go @@ -0,0 +1,13 @@ +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 YearlyRetentionSchedule struct { + MonthsOfYear *[]MonthOfYear `json:"monthsOfYear,omitempty"` + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionScheduleDaily *DailyRetentionFormat `json:"retentionScheduleDaily,omitempty"` + RetentionScheduleFormatType *RetentionScheduleFormat `json:"retentionScheduleFormatType,omitempty"` + RetentionScheduleWeekly *WeeklyRetentionFormat `json:"retentionScheduleWeekly,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/predicates.go new file mode 100644 index 00000000000..96fc03d34ad --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/predicates.go @@ -0,0 +1,37 @@ +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 ProtectionPolicyResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectionPolicyResourceOperationPredicate) Matches(input ProtectionPolicyResource) 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/recoveryservicesbackup/2023-02-01/backuppolicies/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies/version.go new file mode 100644 index 00000000000..6221289bd18 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backuppolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/README.md new file mode 100644 index 00000000000..3e9bea0a90d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems` Documentation + +The `backupprotectableitems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupprotectableitems" +``` + + +### Client Initialization + +```go +client := backupprotectableitems.NewBackupProtectableItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupProtectableItemsClient.List` + +```go +ctx := context.TODO() +id := backupprotectableitems.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, backupprotectableitems.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backupprotectableitems.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/client.go new file mode 100644 index 00000000000..a30b2396b90 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/client.go @@ -0,0 +1,18 @@ +package backupprotectableitems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupProtectableItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupProtectableItemsClientWithBaseURI(endpoint string) BackupProtectableItemsClient { + return BackupProtectableItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/constants.go new file mode 100644 index 00000000000..4707e9072d4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/constants.go @@ -0,0 +1,105 @@ +package backupprotectableitems + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureFileShareType string + +const ( + AzureFileShareTypeInvalid AzureFileShareType = "Invalid" + AzureFileShareTypeXSMB AzureFileShareType = "XSMB" + AzureFileShareTypeXSync AzureFileShareType = "XSync" +) + +func PossibleValuesForAzureFileShareType() []string { + return []string{ + string(AzureFileShareTypeInvalid), + string(AzureFileShareTypeXSMB), + string(AzureFileShareTypeXSync), + } +} + +func parseAzureFileShareType(input string) (*AzureFileShareType, error) { + vals := map[string]AzureFileShareType{ + "invalid": AzureFileShareTypeInvalid, + "xsmb": AzureFileShareTypeXSMB, + "xsync": AzureFileShareTypeXSync, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AzureFileShareType(input) + return &out, nil +} + +type InquiryStatus string + +const ( + InquiryStatusFailed InquiryStatus = "Failed" + InquiryStatusInvalid InquiryStatus = "Invalid" + InquiryStatusSuccess InquiryStatus = "Success" +) + +func PossibleValuesForInquiryStatus() []string { + return []string{ + string(InquiryStatusFailed), + string(InquiryStatusInvalid), + string(InquiryStatusSuccess), + } +} + +func parseInquiryStatus(input string) (*InquiryStatus, error) { + vals := map[string]InquiryStatus{ + "failed": InquiryStatusFailed, + "invalid": InquiryStatusInvalid, + "success": InquiryStatusSuccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InquiryStatus(input) + return &out, nil +} + +type ProtectionStatus string + +const ( + ProtectionStatusInvalid ProtectionStatus = "Invalid" + ProtectionStatusNotProtected ProtectionStatus = "NotProtected" + ProtectionStatusProtected ProtectionStatus = "Protected" + ProtectionStatusProtecting ProtectionStatus = "Protecting" + ProtectionStatusProtectionFailed ProtectionStatus = "ProtectionFailed" +) + +func PossibleValuesForProtectionStatus() []string { + return []string{ + string(ProtectionStatusInvalid), + string(ProtectionStatusNotProtected), + string(ProtectionStatusProtected), + string(ProtectionStatusProtecting), + string(ProtectionStatusProtectionFailed), + } +} + +func parseProtectionStatus(input string) (*ProtectionStatus, error) { + vals := map[string]ProtectionStatus{ + "invalid": ProtectionStatusInvalid, + "notprotected": ProtectionStatusNotProtected, + "protected": ProtectionStatusProtected, + "protecting": ProtectionStatusProtecting, + "protectionfailed": ProtectionStatusProtectionFailed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/id_vault.go new file mode 100644 index 00000000000..8b72edd8ba1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/id_vault.go @@ -0,0 +1,127 @@ +package backupprotectableitems + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/id_vault_test.go new file mode 100644 index 00000000000..fc72e962211 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/id_vault_test.go @@ -0,0 +1,282 @@ +package backupprotectableitems + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupprotectableitems/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/method_list_autorest.go new file mode 100644 index 00000000000..7e33743e477 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/method_list_autorest.go @@ -0,0 +1,215 @@ +package backupprotectableitems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]WorkloadProtectableItemResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []WorkloadProtectableItemResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupProtectableItemsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectableitems.BackupProtectableItemsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectableitems.BackupProtectableItemsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectableitems.BackupProtectableItemsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupProtectableItemsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupProtectableItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupProtectableItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupProtectableItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []WorkloadProtectableItemResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectableitems.BackupProtectableItemsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectableitems.BackupProtectableItemsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectableitems.BackupProtectableItemsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupProtectableItemsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, WorkloadProtectableItemResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupProtectableItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate WorkloadProtectableItemResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]WorkloadProtectableItemResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurefileshareprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurefileshareprotectableitem.go new file mode 100644 index 00000000000..609db8fe641 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurefileshareprotectableitem.go @@ -0,0 +1,47 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureFileShareProtectableItem{} + +type AzureFileShareProtectableItem struct { + AzureFileShareType *AzureFileShareType `json:"azureFileShareType,omitempty"` + ParentContainerFabricId *string `json:"parentContainerFabricId,omitempty"` + ParentContainerFriendlyName *string `json:"parentContainerFriendlyName,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureFileShareProtectableItem{} + +func (s AzureFileShareProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "AzureFileShare" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azureiaasclassiccomputevmprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azureiaasclassiccomputevmprotectableitem.go new file mode 100644 index 00000000000..14d4cde39da --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azureiaasclassiccomputevmprotectableitem.go @@ -0,0 +1,47 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureIaaSClassicComputeVMProtectableItem{} + +type AzureIaaSClassicComputeVMProtectableItem struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureIaaSClassicComputeVMProtectableItem{} + +func (s AzureIaaSClassicComputeVMProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSClassicComputeVMProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSClassicComputeVMProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSClassicComputeVMProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "Microsoft.ClassicCompute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSClassicComputeVMProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azureiaascomputevmprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azureiaascomputevmprotectableitem.go new file mode 100644 index 00000000000..13c811a243b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azureiaascomputevmprotectableitem.go @@ -0,0 +1,47 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureIaaSComputeVMProtectableItem{} + +type AzureIaaSComputeVMProtectableItem struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureIaaSComputeVMProtectableItem{} + +func (s AzureIaaSComputeVMProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSComputeVMProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSComputeVMProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSComputeVMProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "Microsoft.Compute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSComputeVMProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadprotectableitem.go new file mode 100644 index 00000000000..57722018c7d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadprotectableitem.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadProtectableItem{} + +type AzureVMWorkloadProtectableItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadProtectableItem{} + +func (s AzureVMWorkloadProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "AzureVmWorkloadProtectableItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsapasesystemprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsapasesystemprotectableitem.go new file mode 100644 index 00000000000..5b7fcf0cf9a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsapasesystemprotectableitem.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSAPAseSystemProtectableItem{} + +type AzureVMWorkloadSAPAseSystemProtectableItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPAseSystemProtectableItem{} + +func (s AzureVMWorkloadSAPAseSystemProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPAseSystemProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPAseSystemProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPAseSystemProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "SAPAseSystem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPAseSystemProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanadatabaseprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanadatabaseprotectableitem.go new file mode 100644 index 00000000000..07bea2135c3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanadatabaseprotectableitem.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSAPHanaDatabaseProtectableItem{} + +type AzureVMWorkloadSAPHanaDatabaseProtectableItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaDatabaseProtectableItem{} + +func (s AzureVMWorkloadSAPHanaDatabaseProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaDatabaseProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaDatabaseProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaDatabaseProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "SAPHanaDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaDatabaseProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanadbinstance.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanadbinstance.go new file mode 100644 index 00000000000..1925bcec415 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanadbinstance.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSAPHanaDBInstance{} + +type AzureVMWorkloadSAPHanaDBInstance struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaDBInstance{} + +func (s AzureVMWorkloadSAPHanaDBInstance) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaDBInstance + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaDBInstance: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaDBInstance: %+v", err) + } + decoded["protectableItemType"] = "SAPHanaDBInstance" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaDBInstance: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanahsr.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanahsr.go new file mode 100644 index 00000000000..87c8d829d81 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanahsr.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSAPHanaHSR{} + +type AzureVMWorkloadSAPHanaHSR struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaHSR{} + +func (s AzureVMWorkloadSAPHanaHSR) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaHSR + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaHSR: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaHSR: %+v", err) + } + decoded["protectableItemType"] = "SAPHanaHSR" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaHSR: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanasystemprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanasystemprotectableitem.go new file mode 100644 index 00000000000..7f69e4e091d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsaphanasystemprotectableitem.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSAPHanaSystemProtectableItem{} + +type AzureVMWorkloadSAPHanaSystemProtectableItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaSystemProtectableItem{} + +func (s AzureVMWorkloadSAPHanaSystemProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaSystemProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaSystemProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaSystemProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "SAPHanaSystem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaSystemProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqlavailabilitygroupprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqlavailabilitygroupprotectableitem.go new file mode 100644 index 00000000000..c7ed4780435 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqlavailabilitygroupprotectableitem.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSQLAvailabilityGroupProtectableItem{} + +type AzureVMWorkloadSQLAvailabilityGroupProtectableItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSQLAvailabilityGroupProtectableItem{} + +func (s AzureVMWorkloadSQLAvailabilityGroupProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSQLAvailabilityGroupProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSQLAvailabilityGroupProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSQLAvailabilityGroupProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "SQLAvailabilityGroupContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSQLAvailabilityGroupProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqldatabaseprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqldatabaseprotectableitem.go new file mode 100644 index 00000000000..9f094b48509 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqldatabaseprotectableitem.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSQLDatabaseProtectableItem{} + +type AzureVMWorkloadSQLDatabaseProtectableItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSQLDatabaseProtectableItem{} + +func (s AzureVMWorkloadSQLDatabaseProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSQLDatabaseProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSQLDatabaseProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSQLDatabaseProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "SQLDataBase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSQLDatabaseProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqlinstanceprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqlinstanceprotectableitem.go new file mode 100644 index 00000000000..e5818660449 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_azurevmworkloadsqlinstanceprotectableitem.go @@ -0,0 +1,52 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = AzureVMWorkloadSQLInstanceProtectableItem{} + +type AzureVMWorkloadSQLInstanceProtectableItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + IsAutoProtected *bool `json:"isAutoProtected,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentUniqueName *string `json:"parentUniqueName,omitempty"` + Prebackupvalidation *PreBackupValidation `json:"prebackupvalidation,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + Subprotectableitemcount *int64 `json:"subprotectableitemcount,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSQLInstanceProtectableItem{} + +func (s AzureVMWorkloadSQLInstanceProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSQLInstanceProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSQLInstanceProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSQLInstanceProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "SQLInstance" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSQLInstanceProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_iaasvmprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_iaasvmprotectableitem.go new file mode 100644 index 00000000000..c05ab27225f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_iaasvmprotectableitem.go @@ -0,0 +1,47 @@ +package backupprotectableitems + +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 _ WorkloadProtectableItem = IaaSVMProtectableItem{} + +type IaaSVMProtectableItem struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from WorkloadProtectableItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = IaaSVMProtectableItem{} + +func (s IaaSVMProtectableItem) MarshalJSON() ([]byte, error) { + type wrapper IaaSVMProtectableItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaaSVMProtectableItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaaSVMProtectableItem: %+v", err) + } + decoded["protectableItemType"] = "IaaSVMProtectableItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaaSVMProtectableItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_prebackupvalidation.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_prebackupvalidation.go new file mode 100644 index 00000000000..955dd612808 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_prebackupvalidation.go @@ -0,0 +1,10 @@ +package backupprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PreBackupValidation struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Status *InquiryStatus `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_workloadprotectableitem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_workloadprotectableitem.go new file mode 100644 index 00000000000..6f92a5668d4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_workloadprotectableitem.go @@ -0,0 +1,144 @@ +package backupprotectableitems + +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 WorkloadProtectableItem interface { +} + +func unmarshalWorkloadProtectableItemImplementation(input []byte) (WorkloadProtectableItem, 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 WorkloadProtectableItem into map[string]interface: %+v", err) + } + + value, ok := temp["protectableItemType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShare") { + var out AzureFileShareProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.ClassicCompute/virtualMachines") { + var out AzureIaaSClassicComputeVMProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSClassicComputeVMProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Compute/virtualMachines") { + var out AzureIaaSComputeVMProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSComputeVMProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadProtectableItem") { + var out AzureVMWorkloadProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPAseSystem") { + var out AzureVMWorkloadSAPAseSystemProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPAseSystemProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPHanaDBInstance") { + var out AzureVMWorkloadSAPHanaDBInstance + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaDBInstance: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPHanaDatabase") { + var out AzureVMWorkloadSAPHanaDatabaseProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaDatabaseProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPHanaHSR") { + var out AzureVMWorkloadSAPHanaHSR + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaHSR: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPHanaSystem") { + var out AzureVMWorkloadSAPHanaSystemProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaSystemProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLAvailabilityGroupContainer") { + var out AzureVMWorkloadSQLAvailabilityGroupProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSQLAvailabilityGroupProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLDataBase") { + var out AzureVMWorkloadSQLDatabaseProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSQLDatabaseProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLInstance") { + var out AzureVMWorkloadSQLInstanceProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSQLInstanceProtectableItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaaSVMProtectableItem") { + var out IaaSVMProtectableItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaaSVMProtectableItem: %+v", err) + } + return out, nil + } + + type RawWorkloadProtectableItemImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawWorkloadProtectableItemImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_workloadprotectableitemresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_workloadprotectableitemresource.go new file mode 100644 index 00000000000..3f03589ca2d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/model_workloadprotectableitemresource.go @@ -0,0 +1,50 @@ +package backupprotectableitems + +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 WorkloadProtectableItemResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties WorkloadProtectableItem `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &WorkloadProtectableItemResource{} + +func (s *WorkloadProtectableItemResource) UnmarshalJSON(bytes []byte) error { + type alias WorkloadProtectableItemResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into WorkloadProtectableItemResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling WorkloadProtectableItemResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalWorkloadProtectableItemImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'WorkloadProtectableItemResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/predicates.go new file mode 100644 index 00000000000..bb90f9edb61 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/predicates.go @@ -0,0 +1,37 @@ +package backupprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadProtectableItemResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p WorkloadProtectableItemResourceOperationPredicate) Matches(input WorkloadProtectableItemResource) 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/recoveryservicesbackup/2023-02-01/backupprotectableitems/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/version.go new file mode 100644 index 00000000000..d77c2e84da2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems/version.go @@ -0,0 +1,12 @@ +package backupprotectableitems + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupprotectableitems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/README.md new file mode 100644 index 00000000000..559f1c8c8f3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems` Documentation + +The `backupprotecteditems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupprotecteditems" +``` + + +### Client Initialization + +```go +client := backupprotecteditems.NewBackupProtectedItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupProtectedItemsClient.List` + +```go +ctx := context.TODO() +id := backupprotecteditems.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, backupprotecteditems.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backupprotecteditems.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/client.go new file mode 100644 index 00000000000..7bb37dd5d36 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/client.go @@ -0,0 +1,18 @@ +package backupprotecteditems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupProtectedItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupProtectedItemsClientWithBaseURI(endpoint string) BackupProtectedItemsClient { + return BackupProtectedItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/constants.go new file mode 100644 index 00000000000..a0cadc76937 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/constants.go @@ -0,0 +1,387 @@ +package backupprotecteditems + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type CreateMode string + +const ( + CreateModeDefault CreateMode = "Default" + CreateModeInvalid CreateMode = "Invalid" + CreateModeRecover CreateMode = "Recover" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeDefault), + string(CreateModeInvalid), + string(CreateModeRecover), + } +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "default": CreateModeDefault, + "invalid": CreateModeInvalid, + "recover": CreateModeRecover, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreateMode(input) + return &out, nil +} + +type DataSourceType string + +const ( + DataSourceTypeAzureFileShare DataSourceType = "AzureFileShare" + DataSourceTypeAzureSqlDb DataSourceType = "AzureSqlDb" + DataSourceTypeClient DataSourceType = "Client" + DataSourceTypeExchange DataSourceType = "Exchange" + DataSourceTypeFileFolder DataSourceType = "FileFolder" + DataSourceTypeGenericDataSource DataSourceType = "GenericDataSource" + DataSourceTypeInvalid DataSourceType = "Invalid" + DataSourceTypeSAPAseDatabase DataSourceType = "SAPAseDatabase" + DataSourceTypeSAPHanaDBInstance DataSourceType = "SAPHanaDBInstance" + DataSourceTypeSAPHanaDatabase DataSourceType = "SAPHanaDatabase" + DataSourceTypeSQLDB DataSourceType = "SQLDB" + DataSourceTypeSQLDataBase DataSourceType = "SQLDataBase" + DataSourceTypeSharepoint DataSourceType = "Sharepoint" + DataSourceTypeSystemState DataSourceType = "SystemState" + DataSourceTypeVM DataSourceType = "VM" + DataSourceTypeVMwareVM DataSourceType = "VMwareVM" +) + +func PossibleValuesForDataSourceType() []string { + return []string{ + string(DataSourceTypeAzureFileShare), + string(DataSourceTypeAzureSqlDb), + string(DataSourceTypeClient), + string(DataSourceTypeExchange), + string(DataSourceTypeFileFolder), + string(DataSourceTypeGenericDataSource), + string(DataSourceTypeInvalid), + string(DataSourceTypeSAPAseDatabase), + string(DataSourceTypeSAPHanaDBInstance), + string(DataSourceTypeSAPHanaDatabase), + string(DataSourceTypeSQLDB), + string(DataSourceTypeSQLDataBase), + string(DataSourceTypeSharepoint), + string(DataSourceTypeSystemState), + string(DataSourceTypeVM), + string(DataSourceTypeVMwareVM), + } +} + +func parseDataSourceType(input string) (*DataSourceType, error) { + vals := map[string]DataSourceType{ + "azurefileshare": DataSourceTypeAzureFileShare, + "azuresqldb": DataSourceTypeAzureSqlDb, + "client": DataSourceTypeClient, + "exchange": DataSourceTypeExchange, + "filefolder": DataSourceTypeFileFolder, + "genericdatasource": DataSourceTypeGenericDataSource, + "invalid": DataSourceTypeInvalid, + "sapasedatabase": DataSourceTypeSAPAseDatabase, + "saphanadbinstance": DataSourceTypeSAPHanaDBInstance, + "saphanadatabase": DataSourceTypeSAPHanaDatabase, + "sqldb": DataSourceTypeSQLDB, + "sqldatabase": DataSourceTypeSQLDataBase, + "sharepoint": DataSourceTypeSharepoint, + "systemstate": DataSourceTypeSystemState, + "vm": DataSourceTypeVM, + "vmwarevm": DataSourceTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataSourceType(input) + return &out, nil +} + +type HealthStatus string + +const ( + HealthStatusActionRequired HealthStatus = "ActionRequired" + HealthStatusActionSuggested HealthStatus = "ActionSuggested" + HealthStatusInvalid HealthStatus = "Invalid" + HealthStatusPassed HealthStatus = "Passed" +) + +func PossibleValuesForHealthStatus() []string { + return []string{ + string(HealthStatusActionRequired), + string(HealthStatusActionSuggested), + string(HealthStatusInvalid), + string(HealthStatusPassed), + } +} + +func parseHealthStatus(input string) (*HealthStatus, error) { + vals := map[string]HealthStatus{ + "actionrequired": HealthStatusActionRequired, + "actionsuggested": HealthStatusActionSuggested, + "invalid": HealthStatusInvalid, + "passed": HealthStatusPassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthStatus(input) + return &out, nil +} + +type LastBackupStatus string + +const ( + LastBackupStatusHealthy LastBackupStatus = "Healthy" + LastBackupStatusIRPending LastBackupStatus = "IRPending" + LastBackupStatusInvalid LastBackupStatus = "Invalid" + LastBackupStatusUnhealthy LastBackupStatus = "Unhealthy" +) + +func PossibleValuesForLastBackupStatus() []string { + return []string{ + string(LastBackupStatusHealthy), + string(LastBackupStatusIRPending), + string(LastBackupStatusInvalid), + string(LastBackupStatusUnhealthy), + } +} + +func parseLastBackupStatus(input string) (*LastBackupStatus, error) { + vals := map[string]LastBackupStatus{ + "healthy": LastBackupStatusHealthy, + "irpending": LastBackupStatusIRPending, + "invalid": LastBackupStatusInvalid, + "unhealthy": LastBackupStatusUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LastBackupStatus(input) + return &out, nil +} + +type ProtectedItemHealthStatus string + +const ( + ProtectedItemHealthStatusHealthy ProtectedItemHealthStatus = "Healthy" + ProtectedItemHealthStatusIRPending ProtectedItemHealthStatus = "IRPending" + ProtectedItemHealthStatusInvalid ProtectedItemHealthStatus = "Invalid" + ProtectedItemHealthStatusNotReachable ProtectedItemHealthStatus = "NotReachable" + ProtectedItemHealthStatusUnhealthy ProtectedItemHealthStatus = "Unhealthy" +) + +func PossibleValuesForProtectedItemHealthStatus() []string { + return []string{ + string(ProtectedItemHealthStatusHealthy), + string(ProtectedItemHealthStatusIRPending), + string(ProtectedItemHealthStatusInvalid), + string(ProtectedItemHealthStatusNotReachable), + string(ProtectedItemHealthStatusUnhealthy), + } +} + +func parseProtectedItemHealthStatus(input string) (*ProtectedItemHealthStatus, error) { + vals := map[string]ProtectedItemHealthStatus{ + "healthy": ProtectedItemHealthStatusHealthy, + "irpending": ProtectedItemHealthStatusIRPending, + "invalid": ProtectedItemHealthStatusInvalid, + "notreachable": ProtectedItemHealthStatusNotReachable, + "unhealthy": ProtectedItemHealthStatusUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectedItemHealthStatus(input) + return &out, nil +} + +type ProtectedItemState string + +const ( + ProtectedItemStateBackupsSuspended ProtectedItemState = "BackupsSuspended" + ProtectedItemStateIRPending ProtectedItemState = "IRPending" + ProtectedItemStateInvalid ProtectedItemState = "Invalid" + ProtectedItemStateProtected ProtectedItemState = "Protected" + ProtectedItemStateProtectionError ProtectedItemState = "ProtectionError" + ProtectedItemStateProtectionPaused ProtectedItemState = "ProtectionPaused" + ProtectedItemStateProtectionStopped ProtectedItemState = "ProtectionStopped" +) + +func PossibleValuesForProtectedItemState() []string { + return []string{ + string(ProtectedItemStateBackupsSuspended), + string(ProtectedItemStateIRPending), + string(ProtectedItemStateInvalid), + string(ProtectedItemStateProtected), + string(ProtectedItemStateProtectionError), + string(ProtectedItemStateProtectionPaused), + string(ProtectedItemStateProtectionStopped), + } +} + +func parseProtectedItemState(input string) (*ProtectedItemState, error) { + vals := map[string]ProtectedItemState{ + "backupssuspended": ProtectedItemStateBackupsSuspended, + "irpending": ProtectedItemStateIRPending, + "invalid": ProtectedItemStateInvalid, + "protected": ProtectedItemStateProtected, + "protectionerror": ProtectedItemStateProtectionError, + "protectionpaused": ProtectedItemStateProtectionPaused, + "protectionstopped": ProtectedItemStateProtectionStopped, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectedItemState(input) + return &out, nil +} + +type ProtectionState string + +const ( + ProtectionStateBackupsSuspended ProtectionState = "BackupsSuspended" + ProtectionStateIRPending ProtectionState = "IRPending" + ProtectionStateInvalid ProtectionState = "Invalid" + ProtectionStateProtected ProtectionState = "Protected" + ProtectionStateProtectionError ProtectionState = "ProtectionError" + ProtectionStateProtectionPaused ProtectionState = "ProtectionPaused" + ProtectionStateProtectionStopped ProtectionState = "ProtectionStopped" +) + +func PossibleValuesForProtectionState() []string { + return []string{ + string(ProtectionStateBackupsSuspended), + string(ProtectionStateIRPending), + string(ProtectionStateInvalid), + string(ProtectionStateProtected), + string(ProtectionStateProtectionError), + string(ProtectionStateProtectionPaused), + string(ProtectionStateProtectionStopped), + } +} + +func parseProtectionState(input string) (*ProtectionState, error) { + vals := map[string]ProtectionState{ + "backupssuspended": ProtectionStateBackupsSuspended, + "irpending": ProtectionStateIRPending, + "invalid": ProtectionStateInvalid, + "protected": ProtectionStateProtected, + "protectionerror": ProtectionStateProtectionError, + "protectionpaused": ProtectionStateProtectionPaused, + "protectionstopped": ProtectionStateProtectionStopped, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionState(input) + return &out, nil +} + +type ResourceHealthStatus string + +const ( + ResourceHealthStatusHealthy ResourceHealthStatus = "Healthy" + ResourceHealthStatusInvalid ResourceHealthStatus = "Invalid" + ResourceHealthStatusPersistentDegraded ResourceHealthStatus = "PersistentDegraded" + ResourceHealthStatusPersistentUnhealthy ResourceHealthStatus = "PersistentUnhealthy" + ResourceHealthStatusTransientDegraded ResourceHealthStatus = "TransientDegraded" + ResourceHealthStatusTransientUnhealthy ResourceHealthStatus = "TransientUnhealthy" +) + +func PossibleValuesForResourceHealthStatus() []string { + return []string{ + string(ResourceHealthStatusHealthy), + string(ResourceHealthStatusInvalid), + string(ResourceHealthStatusPersistentDegraded), + string(ResourceHealthStatusPersistentUnhealthy), + string(ResourceHealthStatusTransientDegraded), + string(ResourceHealthStatusTransientUnhealthy), + } +} + +func parseResourceHealthStatus(input string) (*ResourceHealthStatus, error) { + vals := map[string]ResourceHealthStatus{ + "healthy": ResourceHealthStatusHealthy, + "invalid": ResourceHealthStatusInvalid, + "persistentdegraded": ResourceHealthStatusPersistentDegraded, + "persistentunhealthy": ResourceHealthStatusPersistentUnhealthy, + "transientdegraded": ResourceHealthStatusTransientDegraded, + "transientunhealthy": ResourceHealthStatusTransientUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceHealthStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/id_vault.go new file mode 100644 index 00000000000..f8fbd5332a7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/id_vault.go @@ -0,0 +1,127 @@ +package backupprotecteditems + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/id_vault_test.go new file mode 100644 index 00000000000..1f44d4ba1c8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/id_vault_test.go @@ -0,0 +1,282 @@ +package backupprotecteditems + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupprotecteditems/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/method_list_autorest.go new file mode 100644 index 00000000000..5b5c8cd79c1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/method_list_autorest.go @@ -0,0 +1,215 @@ +package backupprotecteditems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectedItemResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ProtectedItemResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupProtectedItemsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotecteditems.BackupProtectedItemsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotecteditems.BackupProtectedItemsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotecteditems.BackupProtectedItemsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupProtectedItemsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupProtectedItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupProtectedItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupProtectedItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ProtectedItemResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotecteditems.BackupProtectedItemsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotecteditems.BackupProtectedItemsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotecteditems.BackupProtectedItemsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupProtectedItemsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ProtectedItemResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupProtectedItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate ProtectedItemResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ProtectedItemResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurefileshareprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurefileshareprotecteditem.go new file mode 100644 index 00000000000..36a661b1fd7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurefileshareprotecteditem.go @@ -0,0 +1,91 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureFileshareProtectedItem{} + +type AzureFileshareProtectedItem struct { + ExtendedInfo *AzureFileshareProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureFileshareProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureFileshareProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureFileshareProtectedItem{} + +func (s AzureFileshareProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureFileshareProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileshareProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileshareProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureFileShareProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileshareProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurefileshareprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurefileshareprotecteditemextendedinfo.go new file mode 100644 index 00000000000..784dbda1d5d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurefileshareprotecteditemextendedinfo.go @@ -0,0 +1,42 @@ +package backupprotecteditems + +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 AzureFileshareProtectedItemExtendedInfo struct { + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` + ResourceState *string `json:"resourceState,omitempty"` + ResourceStateSyncTime *string `json:"resourceStateSyncTime,omitempty"` +} + +func (o *AzureFileshareProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *AzureFileshareProtectedItemExtendedInfo) GetResourceStateSyncTimeAsTime() (*time.Time, error) { + if o.ResourceStateSyncTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResourceStateSyncTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItemExtendedInfo) SetResourceStateSyncTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResourceStateSyncTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasclassiccomputevmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasclassiccomputevmprotecteditem.go new file mode 100644 index 00000000000..551a174a2c8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasclassiccomputevmprotecteditem.go @@ -0,0 +1,96 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureIaaSClassicComputeVMProtectedItem{} + +type AzureIaaSClassicComputeVMProtectedItem struct { + ExtendedInfo *AzureIaaSVMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ExtendedProperties *ExtendedProperties `json:"extendedProperties,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthDetails *[]ResourceHealthDetails `json:"healthDetails,omitempty"` + HealthStatus *HealthStatus `json:"healthStatus,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureIaaSClassicComputeVMProtectedItem{} + +func (s AzureIaaSClassicComputeVMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSClassicComputeVMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "Microsoft.ClassicCompute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaascomputevmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaascomputevmprotecteditem.go new file mode 100644 index 00000000000..3d114bb5e15 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaascomputevmprotecteditem.go @@ -0,0 +1,96 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureIaaSComputeVMProtectedItem{} + +type AzureIaaSComputeVMProtectedItem struct { + ExtendedInfo *AzureIaaSVMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ExtendedProperties *ExtendedProperties `json:"extendedProperties,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthDetails *[]ResourceHealthDetails `json:"healthDetails,omitempty"` + HealthStatus *HealthStatus `json:"healthStatus,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureIaaSComputeVMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSComputeVMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureIaaSComputeVMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSComputeVMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureIaaSComputeVMProtectedItem{} + +func (s AzureIaaSComputeVMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSComputeVMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSComputeVMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSComputeVMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "Microsoft.Compute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSComputeVMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasvmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasvmprotecteditem.go new file mode 100644 index 00000000000..24849286f4d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasvmprotecteditem.go @@ -0,0 +1,96 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureIaaSVMProtectedItem{} + +type AzureIaaSVMProtectedItem struct { + ExtendedInfo *AzureIaaSVMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ExtendedProperties *ExtendedProperties `json:"extendedProperties,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthDetails *[]ResourceHealthDetails `json:"healthDetails,omitempty"` + HealthStatus *HealthStatus `json:"healthStatus,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureIaaSVMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureIaaSVMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureIaaSVMProtectedItem{} + +func (s AzureIaaSVMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureIaaSVMProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasvmprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasvmprotecteditemextendedinfo.go new file mode 100644 index 00000000000..f9bd89ad856 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azureiaasvmprotecteditemextendedinfo.go @@ -0,0 +1,67 @@ +package backupprotecteditems + +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 AzureIaaSVMProtectedItemExtendedInfo struct { + NewestRecoveryPointInArchive *string `json:"newestRecoveryPointInArchive,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + OldestRecoveryPointInArchive *string `json:"oldestRecoveryPointInArchive,omitempty"` + OldestRecoveryPointInVault *string `json:"oldestRecoveryPointInVault,omitempty"` + PolicyInconsistent *bool `json:"policyInconsistent,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetNewestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.NewestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NewestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetNewestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NewestRecoveryPointInArchive = &formatted +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetOldestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetOldestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInArchive = &formatted +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetOldestRecoveryPointInVaultAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInVault == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInVault, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetOldestRecoveryPointInVaultAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInVault = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azuresqlprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azuresqlprotecteditem.go new file mode 100644 index 00000000000..94e3b679407 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azuresqlprotecteditem.go @@ -0,0 +1,87 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureSqlProtectedItem{} + +type AzureSqlProtectedItem struct { + ExtendedInfo *AzureSqlProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectedItemState `json:"protectionState,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureSqlProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureSqlProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureSqlProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureSqlProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureSqlProtectedItem{} + +func (s AzureSqlProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureSqlProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSqlProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSqlProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "Microsoft.Sql/servers/databases" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSqlProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azuresqlprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azuresqlprotecteditemextendedinfo.go new file mode 100644 index 00000000000..1f95cebc98c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azuresqlprotecteditemextendedinfo.go @@ -0,0 +1,28 @@ +package backupprotecteditems + +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 AzureSqlProtectedItemExtendedInfo struct { + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *AzureSqlProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureSqlProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadprotecteditem.go new file mode 100644 index 00000000000..8e141ac07b1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadprotecteditem.go @@ -0,0 +1,97 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadProtectedItem{} + +type AzureVMWorkloadProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadProtectedItem{} + +func (s AzureVMWorkloadProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadprotecteditemextendedinfo.go new file mode 100644 index 00000000000..4ad1e158847 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadprotecteditemextendedinfo.go @@ -0,0 +1,68 @@ +package backupprotecteditems + +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 AzureVMWorkloadProtectedItemExtendedInfo struct { + NewestRecoveryPointInArchive *string `json:"newestRecoveryPointInArchive,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + OldestRecoveryPointInArchive *string `json:"oldestRecoveryPointInArchive,omitempty"` + OldestRecoveryPointInVault *string `json:"oldestRecoveryPointInVault,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + RecoveryModel *string `json:"recoveryModel,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetNewestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.NewestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NewestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetNewestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NewestRecoveryPointInArchive = &formatted +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetOldestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetOldestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInArchive = &formatted +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetOldestRecoveryPointInVaultAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInVault == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInVault, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetOldestRecoveryPointInVaultAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInVault = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsapasedatabaseprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsapasedatabaseprotecteditem.go new file mode 100644 index 00000000000..9e70f759edc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsapasedatabaseprotecteditem.go @@ -0,0 +1,97 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSAPAseDatabaseProtectedItem{} + +type AzureVMWorkloadSAPAseDatabaseProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSAPAseDatabaseProtectedItem{} + +func (s AzureVMWorkloadSAPAseDatabaseProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPAseDatabaseProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSAPAseDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsaphanadatabaseprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsaphanadatabaseprotecteditem.go new file mode 100644 index 00000000000..80b8fbc4114 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsaphanadatabaseprotecteditem.go @@ -0,0 +1,97 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSAPHanaDatabaseProtectedItem{} + +type AzureVMWorkloadSAPHanaDatabaseProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaDatabaseProtectedItem{} + +func (s AzureVMWorkloadSAPHanaDatabaseProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaDatabaseProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSAPHanaDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsaphanadbinstanceprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsaphanadbinstanceprotecteditem.go new file mode 100644 index 00000000000..36453be2f03 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsaphanadbinstanceprotecteditem.go @@ -0,0 +1,97 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSAPHanaDBInstanceProtectedItem{} + +type AzureVMWorkloadSAPHanaDBInstanceProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaDBInstanceProtectedItem{} + +func (s AzureVMWorkloadSAPHanaDBInstanceProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaDBInstanceProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSAPHanaDBInstance" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsqldatabaseprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsqldatabaseprotecteditem.go new file mode 100644 index 00000000000..3049ca21eaa --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_azurevmworkloadsqldatabaseprotecteditem.go @@ -0,0 +1,97 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSQLDatabaseProtectedItem{} + +type AzureVMWorkloadSQLDatabaseProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSQLDatabaseProtectedItem{} + +func (s AzureVMWorkloadSQLDatabaseProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSQLDatabaseProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSQLDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_diskexclusionproperties.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_diskexclusionproperties.go new file mode 100644 index 00000000000..f12fc0030e2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_diskexclusionproperties.go @@ -0,0 +1,9 @@ +package backupprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskExclusionProperties struct { + DiskLunList *[]int64 `json:"diskLunList,omitempty"` + IsInclusionList *bool `json:"isInclusionList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_dpmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_dpmprotecteditem.go new file mode 100644 index 00000000000..15b58fab88b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_dpmprotecteditem.go @@ -0,0 +1,88 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = DPMProtectedItem{} + +type DPMProtectedItem struct { + BackupEngineName *string `json:"backupEngineName,omitempty"` + ExtendedInfo *DPMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectedItemState `json:"protectionState,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *DPMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *DPMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = DPMProtectedItem{} + +func (s DPMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper DPMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DPMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DPMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "DPMProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DPMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_dpmprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_dpmprotecteditemextendedinfo.go new file mode 100644 index 00000000000..c28c138b06e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_dpmprotecteditemextendedinfo.go @@ -0,0 +1,75 @@ +package backupprotecteditems + +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 DPMProtectedItemExtendedInfo struct { + DiskStorageUsedInBytes *string `json:"diskStorageUsedInBytes,omitempty"` + IsCollocated *bool `json:"isCollocated,omitempty"` + IsPresentOnCloud *bool `json:"isPresentOnCloud,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + OnPremiseLatestRecoveryPoint *string `json:"onPremiseLatestRecoveryPoint,omitempty"` + OnPremiseOldestRecoveryPoint *string `json:"onPremiseOldestRecoveryPoint,omitempty"` + OnPremiseRecoveryPointCount *int64 `json:"onPremiseRecoveryPointCount,omitempty"` + ProtectableObjectLoadPath *map[string]string `json:"protectableObjectLoadPath,omitempty"` + Protected *bool `json:"protected,omitempty"` + ProtectionGroupName *string `json:"protectionGroupName,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` + TotalDiskStorageSizeInBytes *string `json:"totalDiskStorageSizeInBytes,omitempty"` +} + +func (o *DPMProtectedItemExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} + +func (o *DPMProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *DPMProtectedItemExtendedInfo) GetOnPremiseLatestRecoveryPointAsTime() (*time.Time, error) { + if o.OnPremiseLatestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OnPremiseLatestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetOnPremiseLatestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OnPremiseLatestRecoveryPoint = &formatted +} + +func (o *DPMProtectedItemExtendedInfo) GetOnPremiseOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OnPremiseOldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OnPremiseOldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetOnPremiseOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OnPremiseOldestRecoveryPoint = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_errordetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_errordetail.go new file mode 100644 index 00000000000..c55cc388bf9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_errordetail.go @@ -0,0 +1,10 @@ +package backupprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_extendedproperties.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_extendedproperties.go new file mode 100644 index 00000000000..bd52e28b60e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_extendedproperties.go @@ -0,0 +1,9 @@ +package backupprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedProperties struct { + DiskExclusionProperties *DiskExclusionProperties `json:"diskExclusionProperties,omitempty"` + LinuxVMApplicationName *string `json:"linuxVmApplicationName,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_genericprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_genericprotecteditem.go new file mode 100644 index 00000000000..1e647b0c514 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_genericprotecteditem.go @@ -0,0 +1,90 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = GenericProtectedItem{} + +type GenericProtectedItem struct { + FabricName *string `json:"fabricName,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + ProtectedItemId *int64 `json:"protectedItemId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + SourceAssociations *map[string]string `json:"sourceAssociations,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *GenericProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *GenericProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = GenericProtectedItem{} + +func (s GenericProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper GenericProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "GenericProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_kpiresourcehealthdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_kpiresourcehealthdetails.go new file mode 100644 index 00000000000..42a11e535b9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_kpiresourcehealthdetails.go @@ -0,0 +1,9 @@ +package backupprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KPIResourceHealthDetails struct { + ResourceHealthDetails *[]ResourceHealthDetails `json:"resourceHealthDetails,omitempty"` + ResourceHealthStatus *ResourceHealthStatus `json:"resourceHealthStatus,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_mabfilefolderprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_mabfilefolderprotecteditem.go new file mode 100644 index 00000000000..2caeac3abf6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_mabfilefolderprotecteditem.go @@ -0,0 +1,91 @@ +package backupprotecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = MabFileFolderProtectedItem{} + +type MabFileFolderProtectedItem struct { + ComputerName *string `json:"computerName,omitempty"` + DeferredDeleteSyncTimeInUTC *int64 `json:"deferredDeleteSyncTimeInUTC,omitempty"` + ExtendedInfo *MabFileFolderProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectionState *string `json:"protectionState,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *MabFileFolderProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *MabFileFolderProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = MabFileFolderProtectedItem{} + +func (s MabFileFolderProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper MabFileFolderProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabFileFolderProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabFileFolderProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "MabFileFolderProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabFileFolderProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_mabfilefolderprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_mabfilefolderprotecteditemextendedinfo.go new file mode 100644 index 00000000000..30f88b5c2ac --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_mabfilefolderprotecteditemextendedinfo.go @@ -0,0 +1,40 @@ +package backupprotecteditems + +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 MabFileFolderProtectedItemExtendedInfo struct { + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *MabFileFolderProtectedItemExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItemExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} + +func (o *MabFileFolderProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_protecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_protecteditem.go new file mode 100644 index 00000000000..111f8184eb4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_protecteditem.go @@ -0,0 +1,144 @@ +package backupprotecteditems + +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 ProtectedItem interface { +} + +func unmarshalProtectedItemImplementation(input []byte) (ProtectedItem, 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 ProtectedItem into map[string]interface: %+v", err) + } + + value, ok := temp["protectedItemType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareProtectedItem") { + var out AzureFileshareProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileshareProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.ClassicCompute/virtualMachines") { + var out AzureIaaSClassicComputeVMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Compute/virtualMachines") { + var out AzureIaaSComputeVMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSComputeVMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureIaaSVMProtectedItem") { + var out AzureIaaSVMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Sql/servers/databases") { + var out AzureSqlProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSqlProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadProtectedItem") { + var out AzureVMWorkloadProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSAPAseDatabase") { + var out AzureVMWorkloadSAPAseDatabaseProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSAPHanaDBInstance") { + var out AzureVMWorkloadSAPHanaDBInstanceProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSAPHanaDatabase") { + var out AzureVMWorkloadSAPHanaDatabaseProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSQLDatabase") { + var out AzureVMWorkloadSQLDatabaseProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DPMProtectedItem") { + var out DPMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DPMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericProtectedItem") { + var out GenericProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MabFileFolderProtectedItem") { + var out MabFileFolderProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabFileFolderProtectedItem: %+v", err) + } + return out, nil + } + + type RawProtectedItemImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectedItemImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_protecteditemresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_protecteditemresource.go new file mode 100644 index 00000000000..cf1da7db76f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_protecteditemresource.go @@ -0,0 +1,50 @@ +package backupprotecteditems + +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 ProtectedItemResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectedItem `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectedItemResource{} + +func (s *ProtectedItemResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectedItemResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectedItemResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectedItemResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectedItemImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectedItemResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_resourcehealthdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_resourcehealthdetails.go new file mode 100644 index 00000000000..34cb35fbf15 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/model_resourcehealthdetails.go @@ -0,0 +1,11 @@ +package backupprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceHealthDetails struct { + Code *int64 `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/predicates.go new file mode 100644 index 00000000000..5a0d1c82b79 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/predicates.go @@ -0,0 +1,37 @@ +package backupprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectedItemResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectedItemResourceOperationPredicate) Matches(input ProtectedItemResource) 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/recoveryservicesbackup/2023-02-01/backupprotecteditems/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/version.go new file mode 100644 index 00000000000..dad11b072f8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems/version.go @@ -0,0 +1,12 @@ +package backupprotecteditems + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupprotecteditems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/README.md new file mode 100644 index 00000000000..0f67e793fc6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers` Documentation + +The `backupprotectioncontainers` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupprotectioncontainers" +``` + + +### Client Initialization + +```go +client := backupprotectioncontainers.NewBackupProtectionContainersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupProtectionContainersClient.List` + +```go +ctx := context.TODO() +id := backupprotectioncontainers.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, backupprotectioncontainers.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backupprotectioncontainers.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/client.go new file mode 100644 index 00000000000..80d302c783e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/client.go @@ -0,0 +1,18 @@ +package backupprotectioncontainers + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupProtectionContainersClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupProtectionContainersClientWithBaseURI(endpoint string) BackupProtectionContainersClient { + return BackupProtectionContainersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/constants.go new file mode 100644 index 00000000000..80a7af4df07 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/constants.go @@ -0,0 +1,330 @@ +package backupprotectioncontainers + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AcquireStorageAccountLock string + +const ( + AcquireStorageAccountLockAcquire AcquireStorageAccountLock = "Acquire" + AcquireStorageAccountLockNotAcquire AcquireStorageAccountLock = "NotAcquire" +) + +func PossibleValuesForAcquireStorageAccountLock() []string { + return []string{ + string(AcquireStorageAccountLockAcquire), + string(AcquireStorageAccountLockNotAcquire), + } +} + +func parseAcquireStorageAccountLock(input string) (*AcquireStorageAccountLock, error) { + vals := map[string]AcquireStorageAccountLock{ + "acquire": AcquireStorageAccountLockAcquire, + "notacquire": AcquireStorageAccountLockNotAcquire, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AcquireStorageAccountLock(input) + return &out, nil +} + +type BackupItemType string + +const ( + BackupItemTypeAzureFileShare BackupItemType = "AzureFileShare" + BackupItemTypeAzureSqlDb BackupItemType = "AzureSqlDb" + BackupItemTypeClient BackupItemType = "Client" + BackupItemTypeExchange BackupItemType = "Exchange" + BackupItemTypeFileFolder BackupItemType = "FileFolder" + BackupItemTypeGenericDataSource BackupItemType = "GenericDataSource" + BackupItemTypeInvalid BackupItemType = "Invalid" + BackupItemTypeSAPAseDatabase BackupItemType = "SAPAseDatabase" + BackupItemTypeSAPHanaDBInstance BackupItemType = "SAPHanaDBInstance" + BackupItemTypeSAPHanaDatabase BackupItemType = "SAPHanaDatabase" + BackupItemTypeSQLDB BackupItemType = "SQLDB" + BackupItemTypeSQLDataBase BackupItemType = "SQLDataBase" + BackupItemTypeSharepoint BackupItemType = "Sharepoint" + BackupItemTypeSystemState BackupItemType = "SystemState" + BackupItemTypeVM BackupItemType = "VM" + BackupItemTypeVMwareVM BackupItemType = "VMwareVM" +) + +func PossibleValuesForBackupItemType() []string { + return []string{ + string(BackupItemTypeAzureFileShare), + string(BackupItemTypeAzureSqlDb), + string(BackupItemTypeClient), + string(BackupItemTypeExchange), + string(BackupItemTypeFileFolder), + string(BackupItemTypeGenericDataSource), + string(BackupItemTypeInvalid), + string(BackupItemTypeSAPAseDatabase), + string(BackupItemTypeSAPHanaDBInstance), + string(BackupItemTypeSAPHanaDatabase), + string(BackupItemTypeSQLDB), + string(BackupItemTypeSQLDataBase), + string(BackupItemTypeSharepoint), + string(BackupItemTypeSystemState), + string(BackupItemTypeVM), + string(BackupItemTypeVMwareVM), + } +} + +func parseBackupItemType(input string) (*BackupItemType, error) { + vals := map[string]BackupItemType{ + "azurefileshare": BackupItemTypeAzureFileShare, + "azuresqldb": BackupItemTypeAzureSqlDb, + "client": BackupItemTypeClient, + "exchange": BackupItemTypeExchange, + "filefolder": BackupItemTypeFileFolder, + "genericdatasource": BackupItemTypeGenericDataSource, + "invalid": BackupItemTypeInvalid, + "sapasedatabase": BackupItemTypeSAPAseDatabase, + "saphanadbinstance": BackupItemTypeSAPHanaDBInstance, + "saphanadatabase": BackupItemTypeSAPHanaDatabase, + "sqldb": BackupItemTypeSQLDB, + "sqldatabase": BackupItemTypeSQLDataBase, + "sharepoint": BackupItemTypeSharepoint, + "systemstate": BackupItemTypeSystemState, + "vm": BackupItemTypeVM, + "vmwarevm": BackupItemTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupItemType(input) + return &out, nil +} + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type OperationType string + +const ( + OperationTypeInvalid OperationType = "Invalid" + OperationTypeRegister OperationType = "Register" + OperationTypeReregister OperationType = "Reregister" +) + +func PossibleValuesForOperationType() []string { + return []string{ + string(OperationTypeInvalid), + string(OperationTypeRegister), + string(OperationTypeReregister), + } +} + +func parseOperationType(input string) (*OperationType, error) { + vals := map[string]OperationType{ + "invalid": OperationTypeInvalid, + "register": OperationTypeRegister, + "reregister": OperationTypeReregister, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationType(input) + return &out, nil +} + +type ProtectableContainerType string + +const ( + ProtectableContainerTypeAzureBackupServerContainer ProtectableContainerType = "AzureBackupServerContainer" + ProtectableContainerTypeAzureSqlContainer ProtectableContainerType = "AzureSqlContainer" + ProtectableContainerTypeAzureWorkloadContainer ProtectableContainerType = "AzureWorkloadContainer" + ProtectableContainerTypeCluster ProtectableContainerType = "Cluster" + ProtectableContainerTypeDPMContainer ProtectableContainerType = "DPMContainer" + ProtectableContainerTypeGenericContainer ProtectableContainerType = "GenericContainer" + ProtectableContainerTypeIaasVMContainer ProtectableContainerType = "IaasVMContainer" + ProtectableContainerTypeIaasVMServiceContainer ProtectableContainerType = "IaasVMServiceContainer" + ProtectableContainerTypeInvalid ProtectableContainerType = "Invalid" + ProtectableContainerTypeMABContainer ProtectableContainerType = "MABContainer" + ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines ProtectableContainerType = "Microsoft.ClassicCompute/virtualMachines" + ProtectableContainerTypeMicrosoftPointComputeVirtualMachines ProtectableContainerType = "Microsoft.Compute/virtualMachines" + ProtectableContainerTypeSQLAGWorkLoadContainer ProtectableContainerType = "SQLAGWorkLoadContainer" + ProtectableContainerTypeStorageContainer ProtectableContainerType = "StorageContainer" + ProtectableContainerTypeUnknown ProtectableContainerType = "Unknown" + ProtectableContainerTypeVCenter ProtectableContainerType = "VCenter" + ProtectableContainerTypeVMAppContainer ProtectableContainerType = "VMAppContainer" + ProtectableContainerTypeWindows ProtectableContainerType = "Windows" +) + +func PossibleValuesForProtectableContainerType() []string { + return []string{ + string(ProtectableContainerTypeAzureBackupServerContainer), + string(ProtectableContainerTypeAzureSqlContainer), + string(ProtectableContainerTypeAzureWorkloadContainer), + string(ProtectableContainerTypeCluster), + string(ProtectableContainerTypeDPMContainer), + string(ProtectableContainerTypeGenericContainer), + string(ProtectableContainerTypeIaasVMContainer), + string(ProtectableContainerTypeIaasVMServiceContainer), + string(ProtectableContainerTypeInvalid), + string(ProtectableContainerTypeMABContainer), + string(ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines), + string(ProtectableContainerTypeMicrosoftPointComputeVirtualMachines), + string(ProtectableContainerTypeSQLAGWorkLoadContainer), + string(ProtectableContainerTypeStorageContainer), + string(ProtectableContainerTypeUnknown), + string(ProtectableContainerTypeVCenter), + string(ProtectableContainerTypeVMAppContainer), + string(ProtectableContainerTypeWindows), + } +} + +func parseProtectableContainerType(input string) (*ProtectableContainerType, error) { + vals := map[string]ProtectableContainerType{ + "azurebackupservercontainer": ProtectableContainerTypeAzureBackupServerContainer, + "azuresqlcontainer": ProtectableContainerTypeAzureSqlContainer, + "azureworkloadcontainer": ProtectableContainerTypeAzureWorkloadContainer, + "cluster": ProtectableContainerTypeCluster, + "dpmcontainer": ProtectableContainerTypeDPMContainer, + "genericcontainer": ProtectableContainerTypeGenericContainer, + "iaasvmcontainer": ProtectableContainerTypeIaasVMContainer, + "iaasvmservicecontainer": ProtectableContainerTypeIaasVMServiceContainer, + "invalid": ProtectableContainerTypeInvalid, + "mabcontainer": ProtectableContainerTypeMABContainer, + "microsoft.classiccompute/virtualmachines": ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines, + "microsoft.compute/virtualmachines": ProtectableContainerTypeMicrosoftPointComputeVirtualMachines, + "sqlagworkloadcontainer": ProtectableContainerTypeSQLAGWorkLoadContainer, + "storagecontainer": ProtectableContainerTypeStorageContainer, + "unknown": ProtectableContainerTypeUnknown, + "vcenter": ProtectableContainerTypeVCenter, + "vmappcontainer": ProtectableContainerTypeVMAppContainer, + "windows": ProtectableContainerTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectableContainerType(input) + return &out, nil +} + +type WorkloadType string + +const ( + WorkloadTypeAzureFileShare WorkloadType = "AzureFileShare" + WorkloadTypeAzureSqlDb WorkloadType = "AzureSqlDb" + WorkloadTypeClient WorkloadType = "Client" + WorkloadTypeExchange WorkloadType = "Exchange" + WorkloadTypeFileFolder WorkloadType = "FileFolder" + WorkloadTypeGenericDataSource WorkloadType = "GenericDataSource" + WorkloadTypeInvalid WorkloadType = "Invalid" + WorkloadTypeSAPAseDatabase WorkloadType = "SAPAseDatabase" + WorkloadTypeSAPHanaDBInstance WorkloadType = "SAPHanaDBInstance" + WorkloadTypeSAPHanaDatabase WorkloadType = "SAPHanaDatabase" + WorkloadTypeSQLDB WorkloadType = "SQLDB" + WorkloadTypeSQLDataBase WorkloadType = "SQLDataBase" + WorkloadTypeSharepoint WorkloadType = "Sharepoint" + WorkloadTypeSystemState WorkloadType = "SystemState" + WorkloadTypeVM WorkloadType = "VM" + WorkloadTypeVMwareVM WorkloadType = "VMwareVM" +) + +func PossibleValuesForWorkloadType() []string { + return []string{ + string(WorkloadTypeAzureFileShare), + string(WorkloadTypeAzureSqlDb), + string(WorkloadTypeClient), + string(WorkloadTypeExchange), + string(WorkloadTypeFileFolder), + string(WorkloadTypeGenericDataSource), + string(WorkloadTypeInvalid), + string(WorkloadTypeSAPAseDatabase), + string(WorkloadTypeSAPHanaDBInstance), + string(WorkloadTypeSAPHanaDatabase), + string(WorkloadTypeSQLDB), + string(WorkloadTypeSQLDataBase), + string(WorkloadTypeSharepoint), + string(WorkloadTypeSystemState), + string(WorkloadTypeVM), + string(WorkloadTypeVMwareVM), + } +} + +func parseWorkloadType(input string) (*WorkloadType, error) { + vals := map[string]WorkloadType{ + "azurefileshare": WorkloadTypeAzureFileShare, + "azuresqldb": WorkloadTypeAzureSqlDb, + "client": WorkloadTypeClient, + "exchange": WorkloadTypeExchange, + "filefolder": WorkloadTypeFileFolder, + "genericdatasource": WorkloadTypeGenericDataSource, + "invalid": WorkloadTypeInvalid, + "sapasedatabase": WorkloadTypeSAPAseDatabase, + "saphanadbinstance": WorkloadTypeSAPHanaDBInstance, + "saphanadatabase": WorkloadTypeSAPHanaDatabase, + "sqldb": WorkloadTypeSQLDB, + "sqldatabase": WorkloadTypeSQLDataBase, + "sharepoint": WorkloadTypeSharepoint, + "systemstate": WorkloadTypeSystemState, + "vm": WorkloadTypeVM, + "vmwarevm": WorkloadTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkloadType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/id_vault.go new file mode 100644 index 00000000000..f68a68396d7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/id_vault.go @@ -0,0 +1,127 @@ +package backupprotectioncontainers + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/id_vault_test.go new file mode 100644 index 00000000000..ea8a2d85518 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/id_vault_test.go @@ -0,0 +1,282 @@ +package backupprotectioncontainers + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/method_list_autorest.go new file mode 100644 index 00000000000..2395d76d2f4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/method_list_autorest.go @@ -0,0 +1,215 @@ +package backupprotectioncontainers + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionContainerResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ProtectionContainerResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupProtectionContainersClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectioncontainers.BackupProtectionContainersClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectioncontainers.BackupProtectionContainersClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectioncontainers.BackupProtectionContainersClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupProtectionContainersClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupProtectionContainers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupProtectionContainersClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupProtectionContainersClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ProtectionContainerResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectioncontainers.BackupProtectionContainersClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectioncontainers.BackupProtectionContainersClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectioncontainers.BackupProtectionContainersClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupProtectionContainersClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ProtectionContainerResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupProtectionContainersClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate ProtectionContainerResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ProtectionContainerResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurebackupservercontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurebackupservercontainer.go new file mode 100644 index 00000000000..491a5d88bc7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurebackupservercontainer.go @@ -0,0 +1,53 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureBackupServerContainer{} + +type AzureBackupServerContainer struct { + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + DpmAgentVersion *string `json:"dpmAgentVersion,omitempty"` + DpmServers *[]string `json:"dpmServers,omitempty"` + ExtendedInfo *DPMContainerExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + UpgradeAvailable *bool `json:"upgradeAvailable,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureBackupServerContainer{} + +func (s AzureBackupServerContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupServerContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupServerContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupServerContainer: %+v", err) + } + decoded["containerType"] = "AzureBackupServerContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupServerContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureiaasclassiccomputevmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureiaasclassiccomputevmcontainer.go new file mode 100644 index 00000000000..65ce2a73e0e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureiaasclassiccomputevmcontainer.go @@ -0,0 +1,48 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureIaaSClassicComputeVMContainer{} + +type AzureIaaSClassicComputeVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureIaaSClassicComputeVMContainer{} + +func (s AzureIaaSClassicComputeVMContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSClassicComputeVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + decoded["containerType"] = "Microsoft.ClassicCompute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureiaascomputevmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureiaascomputevmcontainer.go new file mode 100644 index 00000000000..2cc11651a91 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureiaascomputevmcontainer.go @@ -0,0 +1,48 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureIaaSComputeVMContainer{} + +type AzureIaaSComputeVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureIaaSComputeVMContainer{} + +func (s AzureIaaSComputeVMContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSComputeVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSComputeVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSComputeVMContainer: %+v", err) + } + decoded["containerType"] = "Microsoft.Compute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSComputeVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go new file mode 100644 index 00000000000..0c3557434a7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go @@ -0,0 +1,50 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureSQLAGWorkloadContainerProtectionContainer{} + +type AzureSQLAGWorkloadContainerProtectionContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureSQLAGWorkloadContainerProtectionContainer{} + +func (s AzureSQLAGWorkloadContainerProtectionContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureSQLAGWorkloadContainerProtectionContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + decoded["containerType"] = "SQLAGWorkLoadContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azuresqlcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azuresqlcontainer.go new file mode 100644 index 00000000000..6a6ebd42209 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azuresqlcontainer.go @@ -0,0 +1,45 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureSqlContainer{} + +type AzureSqlContainer struct { + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureSqlContainer{} + +func (s AzureSqlContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureSqlContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSqlContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSqlContainer: %+v", err) + } + decoded["containerType"] = "AzureSqlContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSqlContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurestoragecontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurestoragecontainer.go new file mode 100644 index 00000000000..2517538ab11 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurestoragecontainer.go @@ -0,0 +1,50 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureStorageContainer{} + +type AzureStorageContainer struct { + AcquireStorageAccountLock *AcquireStorageAccountLock `json:"acquireStorageAccountLock,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ResourceGroup *string `json:"resourceGroup,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountVersion *string `json:"storageAccountVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureStorageContainer{} + +func (s AzureStorageContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureStorageContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureStorageContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureStorageContainer: %+v", err) + } + decoded["containerType"] = "StorageContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureStorageContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurevmappcontainerprotectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurevmappcontainerprotectioncontainer.go new file mode 100644 index 00000000000..791890dda6b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azurevmappcontainerprotectioncontainer.go @@ -0,0 +1,50 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureVMAppContainerProtectionContainer{} + +type AzureVMAppContainerProtectionContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureVMAppContainerProtectionContainer{} + +func (s AzureVMAppContainerProtectionContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureVMAppContainerProtectionContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + decoded["containerType"] = "VMAppContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureworkloadcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureworkloadcontainer.go new file mode 100644 index 00000000000..4bd85bb2f86 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureworkloadcontainer.go @@ -0,0 +1,50 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = AzureWorkloadContainer{} + +type AzureWorkloadContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureWorkloadContainer{} + +func (s AzureWorkloadContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadContainer: %+v", err) + } + decoded["containerType"] = "AzureWorkloadContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureworkloadcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureworkloadcontainerextendedinfo.go new file mode 100644 index 00000000000..4e6205329b2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_azureworkloadcontainerextendedinfo.go @@ -0,0 +1,10 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadContainerExtendedInfo struct { + HostServerName *string `json:"hostServerName,omitempty"` + InquiryInfo *InquiryInfo `json:"inquiryInfo,omitempty"` + NodesList *[]DistributedNodesInfo `json:"nodesList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_containeridentityinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_containeridentityinfo.go new file mode 100644 index 00000000000..8cff0e16315 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_containeridentityinfo.go @@ -0,0 +1,11 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerIdentityInfo struct { + AadTenantId *string `json:"aadTenantId,omitempty"` + Audience *string `json:"audience,omitempty"` + ServicePrincipalClientId *string `json:"servicePrincipalClientId,omitempty"` + UniqueName *string `json:"uniqueName,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_distributednodesinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_distributednodesinfo.go new file mode 100644 index 00000000000..bf82b04be6a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_distributednodesinfo.go @@ -0,0 +1,10 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedNodesInfo struct { + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + NodeName *string `json:"nodeName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_dpmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_dpmcontainer.go new file mode 100644 index 00000000000..d8f981a383a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_dpmcontainer.go @@ -0,0 +1,53 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = DpmContainer{} + +type DpmContainer struct { + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + DpmAgentVersion *string `json:"dpmAgentVersion,omitempty"` + DpmServers *[]string `json:"dpmServers,omitempty"` + ExtendedInfo *DPMContainerExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + UpgradeAvailable *bool `json:"upgradeAvailable,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = DpmContainer{} + +func (s DpmContainer) MarshalJSON() ([]byte, error) { + type wrapper DpmContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DpmContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DpmContainer: %+v", err) + } + decoded["containerType"] = "DPMContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DpmContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_dpmcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_dpmcontainerextendedinfo.go new file mode 100644 index 00000000000..62c9b305962 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_dpmcontainerextendedinfo.go @@ -0,0 +1,26 @@ +package backupprotectioncontainers + +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 DPMContainerExtendedInfo struct { + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` +} + +func (o *DPMContainerExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMContainerExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_errordetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_errordetail.go new file mode 100644 index 00000000000..86008b3edcb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_errordetail.go @@ -0,0 +1,10 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_genericcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_genericcontainer.go new file mode 100644 index 00000000000..1b4450ed88f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_genericcontainer.go @@ -0,0 +1,47 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = GenericContainer{} + +type GenericContainer struct { + ExtendedInformation *GenericContainerExtendedInfo `json:"extendedInformation,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = GenericContainer{} + +func (s GenericContainer) MarshalJSON() ([]byte, error) { + type wrapper GenericContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericContainer: %+v", err) + } + decoded["containerType"] = "GenericContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_genericcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_genericcontainerextendedinfo.go new file mode 100644 index 00000000000..82f18cd823f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_genericcontainerextendedinfo.go @@ -0,0 +1,10 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericContainerExtendedInfo struct { + ContainerIdentityInfo *ContainerIdentityInfo `json:"containerIdentityInfo,omitempty"` + RawCertData *string `json:"rawCertData,omitempty"` + ServiceEndpoints *map[string]string `json:"serviceEndpoints,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_iaasvmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_iaasvmcontainer.go new file mode 100644 index 00000000000..442fd35fe13 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_iaasvmcontainer.go @@ -0,0 +1,48 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = IaaSVMContainer{} + +type IaaSVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = IaaSVMContainer{} + +func (s IaaSVMContainer) MarshalJSON() ([]byte, error) { + type wrapper IaaSVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaaSVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaaSVMContainer: %+v", err) + } + decoded["containerType"] = "IaasVMContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaaSVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_inquiryinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_inquiryinfo.go new file mode 100644 index 00000000000..93ec19a6ba0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_inquiryinfo.go @@ -0,0 +1,10 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InquiryInfo struct { + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + InquiryDetails *[]WorkloadInquiryDetails `json:"inquiryDetails,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_inquiryvalidation.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_inquiryvalidation.go new file mode 100644 index 00000000000..403447f7e37 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_inquiryvalidation.go @@ -0,0 +1,10 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InquiryValidation struct { + AdditionalDetail *string `json:"additionalDetail,omitempty"` + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainer.go new file mode 100644 index 00000000000..d9cd5599d7e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainer.go @@ -0,0 +1,52 @@ +package backupprotectioncontainers + +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 _ ProtectionContainer = MabContainer{} + +type MabContainer struct { + AgentVersion *string `json:"agentVersion,omitempty"` + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerHealthState *string `json:"containerHealthState,omitempty"` + ContainerId *int64 `json:"containerId,omitempty"` + ExtendedInfo *MabContainerExtendedInfo `json:"extendedInfo,omitempty"` + MabContainerHealthDetails *[]MABContainerHealthDetails `json:"mabContainerHealthDetails,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = MabContainer{} + +func (s MabContainer) MarshalJSON() ([]byte, error) { + type wrapper MabContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabContainer: %+v", err) + } + decoded["containerType"] = "Windows" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainerextendedinfo.go new file mode 100644 index 00000000000..b23e3796a39 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainerextendedinfo.go @@ -0,0 +1,30 @@ +package backupprotectioncontainers + +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 MabContainerExtendedInfo struct { + BackupItemType *BackupItemType `json:"backupItemType,omitempty"` + BackupItems *[]string `json:"backupItems,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` + PolicyName *string `json:"policyName,omitempty"` +} + +func (o *MabContainerExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabContainerExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainerhealthdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainerhealthdetails.go new file mode 100644 index 00000000000..7c04be9060e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_mabcontainerhealthdetails.go @@ -0,0 +1,11 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MABContainerHealthDetails struct { + Code *int64 `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_protectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_protectioncontainer.go new file mode 100644 index 00000000000..908fc23c0ef --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_protectioncontainer.go @@ -0,0 +1,136 @@ +package backupprotectioncontainers + +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 ProtectionContainer interface { +} + +func unmarshalProtectionContainerImplementation(input []byte) (ProtectionContainer, 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 ProtectionContainer into map[string]interface: %+v", err) + } + + value, ok := temp["containerType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupServerContainer") { + var out AzureBackupServerContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupServerContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.ClassicCompute/virtualMachines") { + var out AzureIaaSClassicComputeVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSClassicComputeVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Compute/virtualMachines") { + var out AzureIaaSComputeVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSComputeVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLAGWorkLoadContainer") { + var out AzureSQLAGWorkloadContainerProtectionContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureSqlContainer") { + var out AzureSqlContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSqlContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StorageContainer") { + var out AzureStorageContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureStorageContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMAppContainer") { + var out AzureVMAppContainerProtectionContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMAppContainerProtectionContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadContainer") { + var out AzureWorkloadContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DPMContainer") { + var out DpmContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DpmContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericContainer") { + var out GenericContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMContainer") { + var out IaaSVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaaSVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Windows") { + var out MabContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabContainer: %+v", err) + } + return out, nil + } + + type RawProtectionContainerImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionContainerImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_protectioncontainerresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_protectioncontainerresource.go new file mode 100644 index 00000000000..c112fdde08b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_protectioncontainerresource.go @@ -0,0 +1,50 @@ +package backupprotectioncontainers + +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 ProtectionContainerResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectionContainer `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionContainerResource{} + +func (s *ProtectionContainerResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectionContainerResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionContainerResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionContainerResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectionContainerImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectionContainerResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_workloadinquirydetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_workloadinquirydetails.go new file mode 100644 index 00000000000..fd796f17a93 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/model_workloadinquirydetails.go @@ -0,0 +1,10 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadInquiryDetails struct { + InquiryValidation *InquiryValidation `json:"inquiryValidation,omitempty"` + ItemCount *int64 `json:"itemCount,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/predicates.go new file mode 100644 index 00000000000..1d3cc2e90ae --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/predicates.go @@ -0,0 +1,37 @@ +package backupprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainerResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectionContainerResourceOperationPredicate) Matches(input ProtectionContainerResource) 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/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/version.go new file mode 100644 index 00000000000..b57287bae76 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers/version.go @@ -0,0 +1,12 @@ +package backupprotectioncontainers + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupprotectioncontainers/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/README.md new file mode 100644 index 00000000000..f90069fea9f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent` Documentation + +The `backupprotectionintent` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupprotectionintent" +``` + + +### Client Initialization + +```go +client := backupprotectionintent.NewBackupProtectionIntentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupProtectionIntentClient.List` + +```go +ctx := context.TODO() +id := backupprotectionintent.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, backupprotectionintent.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backupprotectionintent.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/client.go new file mode 100644 index 00000000000..10dc6db01e1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/client.go @@ -0,0 +1,18 @@ +package backupprotectionintent + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupProtectionIntentClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupProtectionIntentClientWithBaseURI(endpoint string) BackupProtectionIntentClient { + return BackupProtectionIntentClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/constants.go new file mode 100644 index 00000000000..8f986ff7614 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/constants.go @@ -0,0 +1,132 @@ +package backupprotectionintent + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type ProtectionIntentItemType string + +const ( + ProtectionIntentItemTypeAzureResourceItem ProtectionIntentItemType = "AzureResourceItem" + ProtectionIntentItemTypeAzureWorkloadAutoProtectionIntent ProtectionIntentItemType = "AzureWorkloadAutoProtectionIntent" + ProtectionIntentItemTypeAzureWorkloadContainerAutoProtectionIntent ProtectionIntentItemType = "AzureWorkloadContainerAutoProtectionIntent" + ProtectionIntentItemTypeAzureWorkloadSQLAutoProtectionIntent ProtectionIntentItemType = "AzureWorkloadSQLAutoProtectionIntent" + ProtectionIntentItemTypeInvalid ProtectionIntentItemType = "Invalid" + ProtectionIntentItemTypeRecoveryServiceVaultItem ProtectionIntentItemType = "RecoveryServiceVaultItem" +) + +func PossibleValuesForProtectionIntentItemType() []string { + return []string{ + string(ProtectionIntentItemTypeAzureResourceItem), + string(ProtectionIntentItemTypeAzureWorkloadAutoProtectionIntent), + string(ProtectionIntentItemTypeAzureWorkloadContainerAutoProtectionIntent), + string(ProtectionIntentItemTypeAzureWorkloadSQLAutoProtectionIntent), + string(ProtectionIntentItemTypeInvalid), + string(ProtectionIntentItemTypeRecoveryServiceVaultItem), + } +} + +func parseProtectionIntentItemType(input string) (*ProtectionIntentItemType, error) { + vals := map[string]ProtectionIntentItemType{ + "azureresourceitem": ProtectionIntentItemTypeAzureResourceItem, + "azureworkloadautoprotectionintent": ProtectionIntentItemTypeAzureWorkloadAutoProtectionIntent, + "azureworkloadcontainerautoprotectionintent": ProtectionIntentItemTypeAzureWorkloadContainerAutoProtectionIntent, + "azureworkloadsqlautoprotectionintent": ProtectionIntentItemTypeAzureWorkloadSQLAutoProtectionIntent, + "invalid": ProtectionIntentItemTypeInvalid, + "recoveryservicevaultitem": ProtectionIntentItemTypeRecoveryServiceVaultItem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionIntentItemType(input) + return &out, nil +} + +type ProtectionStatus string + +const ( + ProtectionStatusInvalid ProtectionStatus = "Invalid" + ProtectionStatusNotProtected ProtectionStatus = "NotProtected" + ProtectionStatusProtected ProtectionStatus = "Protected" + ProtectionStatusProtecting ProtectionStatus = "Protecting" + ProtectionStatusProtectionFailed ProtectionStatus = "ProtectionFailed" +) + +func PossibleValuesForProtectionStatus() []string { + return []string{ + string(ProtectionStatusInvalid), + string(ProtectionStatusNotProtected), + string(ProtectionStatusProtected), + string(ProtectionStatusProtecting), + string(ProtectionStatusProtectionFailed), + } +} + +func parseProtectionStatus(input string) (*ProtectionStatus, error) { + vals := map[string]ProtectionStatus{ + "invalid": ProtectionStatusInvalid, + "notprotected": ProtectionStatusNotProtected, + "protected": ProtectionStatusProtected, + "protecting": ProtectionStatusProtecting, + "protectionfailed": ProtectionStatusProtectionFailed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/id_vault.go new file mode 100644 index 00000000000..f8a6cbb1996 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/id_vault.go @@ -0,0 +1,127 @@ +package backupprotectionintent + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/id_vault_test.go new file mode 100644 index 00000000000..8ce44169d5e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/id_vault_test.go @@ -0,0 +1,282 @@ +package backupprotectionintent + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupprotectionintent/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/method_list_autorest.go new file mode 100644 index 00000000000..9e4e60e7b48 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/method_list_autorest.go @@ -0,0 +1,215 @@ +package backupprotectionintent + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionIntentResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ProtectionIntentResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupProtectionIntentClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectionintent.BackupProtectionIntentClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectionintent.BackupProtectionIntentClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectionintent.BackupProtectionIntentClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupProtectionIntentClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupProtectionIntents", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupProtectionIntentClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupProtectionIntentClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ProtectionIntentResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectionintent.BackupProtectionIntentClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectionintent.BackupProtectionIntentClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupprotectionintent.BackupProtectionIntentClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupProtectionIntentClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ProtectionIntentResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupProtectionIntentClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate ProtectionIntentResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ProtectionIntentResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azurerecoveryservicevaultprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azurerecoveryservicevaultprotectionintent.go new file mode 100644 index 00000000000..b977432cd8e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azurerecoveryservicevaultprotectionintent.go @@ -0,0 +1,45 @@ +package backupprotectionintent + +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 _ ProtectionIntent = AzureRecoveryServiceVaultProtectionIntent{} + +type AzureRecoveryServiceVaultProtectionIntent struct { + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureRecoveryServiceVaultProtectionIntent{} + +func (s AzureRecoveryServiceVaultProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureRecoveryServiceVaultProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "RecoveryServiceVaultItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureresourceprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureresourceprotectionintent.go new file mode 100644 index 00000000000..4583889073c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureresourceprotectionintent.go @@ -0,0 +1,46 @@ +package backupprotectionintent + +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 _ ProtectionIntent = AzureResourceProtectionIntent{} + +type AzureResourceProtectionIntent struct { + FriendlyName *string `json:"friendlyName,omitempty"` + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureResourceProtectionIntent{} + +func (s AzureResourceProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureResourceProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureResourceProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureResourceProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "AzureResourceItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureResourceProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureworkloadautoprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureworkloadautoprotectionintent.go new file mode 100644 index 00000000000..267e3b491a5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureworkloadautoprotectionintent.go @@ -0,0 +1,45 @@ +package backupprotectionintent + +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 _ ProtectionIntent = AzureWorkloadAutoProtectionIntent{} + +type AzureWorkloadAutoProtectionIntent struct { + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureWorkloadAutoProtectionIntent{} + +func (s AzureWorkloadAutoProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadAutoProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadAutoProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadAutoProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "AzureWorkloadAutoProtectionIntent" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadAutoProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureworkloadcontainerautoprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureworkloadcontainerautoprotectionintent.go new file mode 100644 index 00000000000..a8769e454d8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_azureworkloadcontainerautoprotectionintent.go @@ -0,0 +1,45 @@ +package backupprotectionintent + +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 _ ProtectionIntent = AzureWorkloadContainerAutoProtectionIntent{} + +type AzureWorkloadContainerAutoProtectionIntent struct { + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureWorkloadContainerAutoProtectionIntent{} + +func (s AzureWorkloadContainerAutoProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadContainerAutoProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "AzureWorkloadContainerAutoProtectionIntent" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_protectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_protectionintent.go new file mode 100644 index 00000000000..7196eeb5c88 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_protectionintent.go @@ -0,0 +1,72 @@ +package backupprotectionintent + +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 ProtectionIntent interface { +} + +func unmarshalProtectionIntentImplementation(input []byte) (ProtectionIntent, 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 ProtectionIntent into map[string]interface: %+v", err) + } + + value, ok := temp["protectionIntentItemType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "RecoveryServiceVaultItem") { + var out AzureRecoveryServiceVaultProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureResourceItem") { + var out AzureResourceProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureResourceProtectionIntent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadAutoProtectionIntent") { + var out AzureWorkloadAutoProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadAutoProtectionIntent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadContainerAutoProtectionIntent") { + var out AzureWorkloadContainerAutoProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + return out, nil + } + + type RawProtectionIntentImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionIntentImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_protectionintentresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_protectionintentresource.go new file mode 100644 index 00000000000..08b6ed4abda --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/model_protectionintentresource.go @@ -0,0 +1,50 @@ +package backupprotectionintent + +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 ProtectionIntentResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectionIntent `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionIntentResource{} + +func (s *ProtectionIntentResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectionIntentResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionIntentResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionIntentResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectionIntentImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectionIntentResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/predicates.go new file mode 100644 index 00000000000..1732c62d604 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/predicates.go @@ -0,0 +1,37 @@ +package backupprotectionintent + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionIntentResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectionIntentResourceOperationPredicate) Matches(input ProtectionIntentResource) 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/recoveryservicesbackup/2023-02-01/backupprotectionintent/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/version.go new file mode 100644 index 00000000000..c7c698bd514 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent/version.go @@ -0,0 +1,12 @@ +package backupprotectionintent + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupprotectionintent/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/README.md new file mode 100644 index 00000000000..7a3fb4baeee --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs` Documentation + +The `backupresourceencryptionconfigs` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs" +``` + + +### Client Initialization + +```go +client := backupresourceencryptionconfigs.NewBackupResourceEncryptionConfigsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupResourceEncryptionConfigsClient.Get` + +```go +ctx := context.TODO() +id := backupresourceencryptionconfigs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +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: `BackupResourceEncryptionConfigsClient.Update` + +```go +ctx := context.TODO() +id := backupresourceencryptionconfigs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := backupresourceencryptionconfigs.BackupResourceEncryptionConfigResource{ + // ... +} + + +read, err := client.Update(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/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/client.go new file mode 100644 index 00000000000..5b406d30285 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/client.go @@ -0,0 +1,18 @@ +package backupresourceencryptionconfigs + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceEncryptionConfigsClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupResourceEncryptionConfigsClientWithBaseURI(endpoint string) BackupResourceEncryptionConfigsClient { + return BackupResourceEncryptionConfigsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/constants.go new file mode 100644 index 00000000000..0c18f2887db --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/constants.go @@ -0,0 +1,114 @@ +package backupresourceencryptionconfigs + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionAtRestType string + +const ( + EncryptionAtRestTypeCustomerManaged EncryptionAtRestType = "CustomerManaged" + EncryptionAtRestTypeInvalid EncryptionAtRestType = "Invalid" + EncryptionAtRestTypeMicrosoftManaged EncryptionAtRestType = "MicrosoftManaged" +) + +func PossibleValuesForEncryptionAtRestType() []string { + return []string{ + string(EncryptionAtRestTypeCustomerManaged), + string(EncryptionAtRestTypeInvalid), + string(EncryptionAtRestTypeMicrosoftManaged), + } +} + +func parseEncryptionAtRestType(input string) (*EncryptionAtRestType, error) { + vals := map[string]EncryptionAtRestType{ + "customermanaged": EncryptionAtRestTypeCustomerManaged, + "invalid": EncryptionAtRestTypeInvalid, + "microsoftmanaged": EncryptionAtRestTypeMicrosoftManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EncryptionAtRestType(input) + return &out, nil +} + +type InfrastructureEncryptionState string + +const ( + InfrastructureEncryptionStateDisabled InfrastructureEncryptionState = "Disabled" + InfrastructureEncryptionStateEnabled InfrastructureEncryptionState = "Enabled" + InfrastructureEncryptionStateInvalid InfrastructureEncryptionState = "Invalid" +) + +func PossibleValuesForInfrastructureEncryptionState() []string { + return []string{ + string(InfrastructureEncryptionStateDisabled), + string(InfrastructureEncryptionStateEnabled), + string(InfrastructureEncryptionStateInvalid), + } +} + +func parseInfrastructureEncryptionState(input string) (*InfrastructureEncryptionState, error) { + vals := map[string]InfrastructureEncryptionState{ + "disabled": InfrastructureEncryptionStateDisabled, + "enabled": InfrastructureEncryptionStateEnabled, + "invalid": InfrastructureEncryptionStateInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InfrastructureEncryptionState(input) + return &out, nil +} + +type LastUpdateStatus string + +const ( + LastUpdateStatusFailed LastUpdateStatus = "Failed" + LastUpdateStatusFirstInitialization LastUpdateStatus = "FirstInitialization" + LastUpdateStatusInitialized LastUpdateStatus = "Initialized" + LastUpdateStatusInvalid LastUpdateStatus = "Invalid" + LastUpdateStatusNotEnabled LastUpdateStatus = "NotEnabled" + LastUpdateStatusPartiallyFailed LastUpdateStatus = "PartiallyFailed" + LastUpdateStatusPartiallySucceeded LastUpdateStatus = "PartiallySucceeded" + LastUpdateStatusSucceeded LastUpdateStatus = "Succeeded" +) + +func PossibleValuesForLastUpdateStatus() []string { + return []string{ + string(LastUpdateStatusFailed), + string(LastUpdateStatusFirstInitialization), + string(LastUpdateStatusInitialized), + string(LastUpdateStatusInvalid), + string(LastUpdateStatusNotEnabled), + string(LastUpdateStatusPartiallyFailed), + string(LastUpdateStatusPartiallySucceeded), + string(LastUpdateStatusSucceeded), + } +} + +func parseLastUpdateStatus(input string) (*LastUpdateStatus, error) { + vals := map[string]LastUpdateStatus{ + "failed": LastUpdateStatusFailed, + "firstinitialization": LastUpdateStatusFirstInitialization, + "initialized": LastUpdateStatusInitialized, + "invalid": LastUpdateStatusInvalid, + "notenabled": LastUpdateStatusNotEnabled, + "partiallyfailed": LastUpdateStatusPartiallyFailed, + "partiallysucceeded": LastUpdateStatusPartiallySucceeded, + "succeeded": LastUpdateStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LastUpdateStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/id_vault.go new file mode 100644 index 00000000000..e3351a60be4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/id_vault.go @@ -0,0 +1,127 @@ +package backupresourceencryptionconfigs + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/id_vault_test.go new file mode 100644 index 00000000000..cdc323a8d45 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/id_vault_test.go @@ -0,0 +1,282 @@ +package backupresourceencryptionconfigs + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/method_get_autorest.go new file mode 100644 index 00000000000..8946fde875a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/method_get_autorest.go @@ -0,0 +1,69 @@ +package backupresourceencryptionconfigs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *BackupResourceEncryptionConfigExtendedResource +} + +// Get ... +func (c BackupResourceEncryptionConfigsClient) Get(ctx context.Context, id VaultId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourceencryptionconfigs.BackupResourceEncryptionConfigsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourceencryptionconfigs.BackupResourceEncryptionConfigsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourceencryptionconfigs.BackupResourceEncryptionConfigsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c BackupResourceEncryptionConfigsClient) preparerForGet(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupEncryptionConfigs/backupResourceEncryptionConfig", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c BackupResourceEncryptionConfigsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/method_update_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/method_update_autorest.go new file mode 100644 index 00000000000..8e72a546ee0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/method_update_autorest.go @@ -0,0 +1,68 @@ +package backupresourceencryptionconfigs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response +} + +// Update ... +func (c BackupResourceEncryptionConfigsClient) Update(ctx context.Context, id VaultId, input BackupResourceEncryptionConfigResource) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourceencryptionconfigs.BackupResourceEncryptionConfigsClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourceencryptionconfigs.BackupResourceEncryptionConfigsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourceencryptionconfigs.BackupResourceEncryptionConfigsClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c BackupResourceEncryptionConfigsClient) preparerForUpdate(ctx context.Context, id VaultId, input BackupResourceEncryptionConfigResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupEncryptionConfigs/backupResourceEncryptionConfig", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUpdate handles the response to the Update request. The method always +// closes the http.Response Body. +func (c BackupResourceEncryptionConfigsClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfig.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfig.go new file mode 100644 index 00000000000..04c2d9832cb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfig.go @@ -0,0 +1,12 @@ +package backupresourceencryptionconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceEncryptionConfig struct { + EncryptionAtRestType *EncryptionAtRestType `json:"encryptionAtRestType,omitempty"` + InfrastructureEncryptionState *InfrastructureEncryptionState `json:"infrastructureEncryptionState,omitempty"` + KeyUri *string `json:"keyUri,omitempty"` + LastUpdateStatus *LastUpdateStatus `json:"lastUpdateStatus,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigextended.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigextended.go new file mode 100644 index 00000000000..c58a1406581 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigextended.go @@ -0,0 +1,14 @@ +package backupresourceencryptionconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceEncryptionConfigExtended struct { + EncryptionAtRestType *EncryptionAtRestType `json:"encryptionAtRestType,omitempty"` + InfrastructureEncryptionState *InfrastructureEncryptionState `json:"infrastructureEncryptionState,omitempty"` + KeyUri *string `json:"keyUri,omitempty"` + LastUpdateStatus *LastUpdateStatus `json:"lastUpdateStatus,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + UseSystemAssignedIdentity *bool `json:"useSystemAssignedIdentity,omitempty"` + UserAssignedIdentity *string `json:"userAssignedIdentity,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigextendedresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigextendedresource.go new file mode 100644 index 00000000000..748ecae7a86 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigextendedresource.go @@ -0,0 +1,14 @@ +package backupresourceencryptionconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceEncryptionConfigExtendedResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupResourceEncryptionConfigExtended `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigresource.go new file mode 100644 index 00000000000..2bdfb74ffb3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/model_backupresourceencryptionconfigresource.go @@ -0,0 +1,14 @@ +package backupresourceencryptionconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceEncryptionConfigResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupResourceEncryptionConfig `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/version.go new file mode 100644 index 00000000000..fb0529801b3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs/version.go @@ -0,0 +1,12 @@ +package backupresourceencryptionconfigs + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupresourceencryptionconfigs/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/README.md new file mode 100644 index 00000000000..d04dbb01251 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/README.md @@ -0,0 +1,78 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr` Documentation + +The `backupresourcestorageconfigsnoncrr` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr" +``` + + +### Client Initialization + +```go +client := backupresourcestorageconfigsnoncrr.NewBackupResourceStorageConfigsNonCRRClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupResourceStorageConfigsNonCRRClient.Get` + +```go +ctx := context.TODO() +id := backupresourcestorageconfigsnoncrr.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +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: `BackupResourceStorageConfigsNonCRRClient.Patch` + +```go +ctx := context.TODO() +id := backupresourcestorageconfigsnoncrr.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := backupresourcestorageconfigsnoncrr.BackupResourceConfigResource{ + // ... +} + + +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: `BackupResourceStorageConfigsNonCRRClient.Update` + +```go +ctx := context.TODO() +id := backupresourcestorageconfigsnoncrr.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := backupresourcestorageconfigsnoncrr.BackupResourceConfigResource{ + // ... +} + + +read, err := client.Update(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/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/client.go new file mode 100644 index 00000000000..88d28c49c49 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/client.go @@ -0,0 +1,18 @@ +package backupresourcestorageconfigsnoncrr + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceStorageConfigsNonCRRClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupResourceStorageConfigsNonCRRClientWithBaseURI(endpoint string) BackupResourceStorageConfigsNonCRRClient { + return BackupResourceStorageConfigsNonCRRClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/constants.go new file mode 100644 index 00000000000..6ae51ba9c4a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/constants.go @@ -0,0 +1,136 @@ +package backupresourcestorageconfigsnoncrr + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DedupState string + +const ( + DedupStateDisabled DedupState = "Disabled" + DedupStateEnabled DedupState = "Enabled" + DedupStateInvalid DedupState = "Invalid" +) + +func PossibleValuesForDedupState() []string { + return []string{ + string(DedupStateDisabled), + string(DedupStateEnabled), + string(DedupStateInvalid), + } +} + +func parseDedupState(input string) (*DedupState, error) { + vals := map[string]DedupState{ + "disabled": DedupStateDisabled, + "enabled": DedupStateEnabled, + "invalid": DedupStateInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DedupState(input) + return &out, nil +} + +type StorageType string + +const ( + StorageTypeGeoRedundant StorageType = "GeoRedundant" + StorageTypeInvalid StorageType = "Invalid" + StorageTypeLocallyRedundant StorageType = "LocallyRedundant" + StorageTypeReadAccessGeoZoneRedundant StorageType = "ReadAccessGeoZoneRedundant" + StorageTypeZoneRedundant StorageType = "ZoneRedundant" +) + +func PossibleValuesForStorageType() []string { + return []string{ + string(StorageTypeGeoRedundant), + string(StorageTypeInvalid), + string(StorageTypeLocallyRedundant), + string(StorageTypeReadAccessGeoZoneRedundant), + string(StorageTypeZoneRedundant), + } +} + +func parseStorageType(input string) (*StorageType, error) { + vals := map[string]StorageType{ + "georedundant": StorageTypeGeoRedundant, + "invalid": StorageTypeInvalid, + "locallyredundant": StorageTypeLocallyRedundant, + "readaccessgeozoneredundant": StorageTypeReadAccessGeoZoneRedundant, + "zoneredundant": StorageTypeZoneRedundant, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageType(input) + return &out, nil +} + +type StorageTypeState string + +const ( + StorageTypeStateInvalid StorageTypeState = "Invalid" + StorageTypeStateLocked StorageTypeState = "Locked" + StorageTypeStateUnlocked StorageTypeState = "Unlocked" +) + +func PossibleValuesForStorageTypeState() []string { + return []string{ + string(StorageTypeStateInvalid), + string(StorageTypeStateLocked), + string(StorageTypeStateUnlocked), + } +} + +func parseStorageTypeState(input string) (*StorageTypeState, error) { + vals := map[string]StorageTypeState{ + "invalid": StorageTypeStateInvalid, + "locked": StorageTypeStateLocked, + "unlocked": StorageTypeStateUnlocked, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageTypeState(input) + return &out, nil +} + +type XcoolState string + +const ( + XcoolStateDisabled XcoolState = "Disabled" + XcoolStateEnabled XcoolState = "Enabled" + XcoolStateInvalid XcoolState = "Invalid" +) + +func PossibleValuesForXcoolState() []string { + return []string{ + string(XcoolStateDisabled), + string(XcoolStateEnabled), + string(XcoolStateInvalid), + } +} + +func parseXcoolState(input string) (*XcoolState, error) { + vals := map[string]XcoolState{ + "disabled": XcoolStateDisabled, + "enabled": XcoolStateEnabled, + "invalid": XcoolStateInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := XcoolState(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/id_vault.go new file mode 100644 index 00000000000..2ef7515d0f8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/id_vault.go @@ -0,0 +1,127 @@ +package backupresourcestorageconfigsnoncrr + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/id_vault_test.go new file mode 100644 index 00000000000..146c3b1d168 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/id_vault_test.go @@ -0,0 +1,282 @@ +package backupresourcestorageconfigsnoncrr + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_get_autorest.go new file mode 100644 index 00000000000..dfa7631d81e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_get_autorest.go @@ -0,0 +1,69 @@ +package backupresourcestorageconfigsnoncrr + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *BackupResourceConfigResource +} + +// Get ... +func (c BackupResourceStorageConfigsNonCRRClient) Get(ctx context.Context, id VaultId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c BackupResourceStorageConfigsNonCRRClient) preparerForGet(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupStorageConfig/vaultStorageConfig", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c BackupResourceStorageConfigsNonCRRClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_patch_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_patch_autorest.go new file mode 100644 index 00000000000..06e35a3cb44 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_patch_autorest.go @@ -0,0 +1,68 @@ +package backupresourcestorageconfigsnoncrr + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchOperationResponse struct { + HttpResponse *http.Response +} + +// Patch ... +func (c BackupResourceStorageConfigsNonCRRClient) Patch(ctx context.Context, id VaultId, input BackupResourceConfigResource) (result PatchOperationResponse, err error) { + req, err := c.preparerForPatch(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Patch", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Patch", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPatch(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Patch", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPatch prepares the Patch request. +func (c BackupResourceStorageConfigsNonCRRClient) preparerForPatch(ctx context.Context, id VaultId, input BackupResourceConfigResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupStorageConfig/vaultStorageConfig", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPatch handles the response to the Patch request. The method always +// closes the http.Response Body. +func (c BackupResourceStorageConfigsNonCRRClient) responderForPatch(resp *http.Response) (result PatchOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_update_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_update_autorest.go new file mode 100644 index 00000000000..13a010ee69d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/method_update_autorest.go @@ -0,0 +1,70 @@ +package backupresourcestorageconfigsnoncrr + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *BackupResourceConfigResource +} + +// Update ... +func (c BackupResourceStorageConfigsNonCRRClient) Update(ctx context.Context, id VaultId, input BackupResourceConfigResource) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c BackupResourceStorageConfigsNonCRRClient) preparerForUpdate(ctx context.Context, id VaultId, input BackupResourceConfigResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupStorageConfig/vaultStorageConfig", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUpdate handles the response to the Update request. The method always +// closes the http.Response Body. +func (c BackupResourceStorageConfigsNonCRRClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/model_backupresourceconfig.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/model_backupresourceconfig.go new file mode 100644 index 00000000000..69f226c0dcf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/model_backupresourceconfig.go @@ -0,0 +1,13 @@ +package backupresourcestorageconfigsnoncrr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceConfig struct { + CrossRegionRestoreFlag *bool `json:"crossRegionRestoreFlag,omitempty"` + DedupState *DedupState `json:"dedupState,omitempty"` + StorageModelType *StorageType `json:"storageModelType,omitempty"` + StorageType *StorageType `json:"storageType,omitempty"` + StorageTypeState *StorageTypeState `json:"storageTypeState,omitempty"` + XcoolState *XcoolState `json:"xcoolState,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/model_backupresourceconfigresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/model_backupresourceconfigresource.go new file mode 100644 index 00000000000..8fc2680cafb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/model_backupresourceconfigresource.go @@ -0,0 +1,14 @@ +package backupresourcestorageconfigsnoncrr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceConfigResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupResourceConfig `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/version.go new file mode 100644 index 00000000000..0184cb1ad5d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr/version.go @@ -0,0 +1,12 @@ +package backupresourcestorageconfigsnoncrr + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupresourcestorageconfigsnoncrr/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/README.md new file mode 100644 index 00000000000..cd5b5749f92 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/README.md @@ -0,0 +1,78 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs` Documentation + +The `backupresourcevaultconfigs` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs" +``` + + +### Client Initialization + +```go +client := backupresourcevaultconfigs.NewBackupResourceVaultConfigsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupResourceVaultConfigsClient.Get` + +```go +ctx := context.TODO() +id := backupresourcevaultconfigs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +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: `BackupResourceVaultConfigsClient.Put` + +```go +ctx := context.TODO() +id := backupresourcevaultconfigs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := backupresourcevaultconfigs.BackupResourceVaultConfigResource{ + // ... +} + + +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 +} +``` + + +### Example Usage: `BackupResourceVaultConfigsClient.Update` + +```go +ctx := context.TODO() +id := backupresourcevaultconfigs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := backupresourcevaultconfigs.BackupResourceVaultConfigResource{ + // ... +} + + +read, err := client.Update(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/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/client.go new file mode 100644 index 00000000000..b56d05bcc6b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/client.go @@ -0,0 +1,18 @@ +package backupresourcevaultconfigs + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceVaultConfigsClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupResourceVaultConfigsClientWithBaseURI(endpoint string) BackupResourceVaultConfigsClient { + return BackupResourceVaultConfigsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/constants.go new file mode 100644 index 00000000000..95d3b28e3f0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/constants.go @@ -0,0 +1,136 @@ +package backupresourcevaultconfigs + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnhancedSecurityState string + +const ( + EnhancedSecurityStateDisabled EnhancedSecurityState = "Disabled" + EnhancedSecurityStateEnabled EnhancedSecurityState = "Enabled" + EnhancedSecurityStateInvalid EnhancedSecurityState = "Invalid" +) + +func PossibleValuesForEnhancedSecurityState() []string { + return []string{ + string(EnhancedSecurityStateDisabled), + string(EnhancedSecurityStateEnabled), + string(EnhancedSecurityStateInvalid), + } +} + +func parseEnhancedSecurityState(input string) (*EnhancedSecurityState, error) { + vals := map[string]EnhancedSecurityState{ + "disabled": EnhancedSecurityStateDisabled, + "enabled": EnhancedSecurityStateEnabled, + "invalid": EnhancedSecurityStateInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnhancedSecurityState(input) + return &out, nil +} + +type SoftDeleteFeatureState string + +const ( + SoftDeleteFeatureStateDisabled SoftDeleteFeatureState = "Disabled" + SoftDeleteFeatureStateEnabled SoftDeleteFeatureState = "Enabled" + SoftDeleteFeatureStateInvalid SoftDeleteFeatureState = "Invalid" +) + +func PossibleValuesForSoftDeleteFeatureState() []string { + return []string{ + string(SoftDeleteFeatureStateDisabled), + string(SoftDeleteFeatureStateEnabled), + string(SoftDeleteFeatureStateInvalid), + } +} + +func parseSoftDeleteFeatureState(input string) (*SoftDeleteFeatureState, error) { + vals := map[string]SoftDeleteFeatureState{ + "disabled": SoftDeleteFeatureStateDisabled, + "enabled": SoftDeleteFeatureStateEnabled, + "invalid": SoftDeleteFeatureStateInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoftDeleteFeatureState(input) + return &out, nil +} + +type StorageType string + +const ( + StorageTypeGeoRedundant StorageType = "GeoRedundant" + StorageTypeInvalid StorageType = "Invalid" + StorageTypeLocallyRedundant StorageType = "LocallyRedundant" + StorageTypeReadAccessGeoZoneRedundant StorageType = "ReadAccessGeoZoneRedundant" + StorageTypeZoneRedundant StorageType = "ZoneRedundant" +) + +func PossibleValuesForStorageType() []string { + return []string{ + string(StorageTypeGeoRedundant), + string(StorageTypeInvalid), + string(StorageTypeLocallyRedundant), + string(StorageTypeReadAccessGeoZoneRedundant), + string(StorageTypeZoneRedundant), + } +} + +func parseStorageType(input string) (*StorageType, error) { + vals := map[string]StorageType{ + "georedundant": StorageTypeGeoRedundant, + "invalid": StorageTypeInvalid, + "locallyredundant": StorageTypeLocallyRedundant, + "readaccessgeozoneredundant": StorageTypeReadAccessGeoZoneRedundant, + "zoneredundant": StorageTypeZoneRedundant, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageType(input) + return &out, nil +} + +type StorageTypeState string + +const ( + StorageTypeStateInvalid StorageTypeState = "Invalid" + StorageTypeStateLocked StorageTypeState = "Locked" + StorageTypeStateUnlocked StorageTypeState = "Unlocked" +) + +func PossibleValuesForStorageTypeState() []string { + return []string{ + string(StorageTypeStateInvalid), + string(StorageTypeStateLocked), + string(StorageTypeStateUnlocked), + } +} + +func parseStorageTypeState(input string) (*StorageTypeState, error) { + vals := map[string]StorageTypeState{ + "invalid": StorageTypeStateInvalid, + "locked": StorageTypeStateLocked, + "unlocked": StorageTypeStateUnlocked, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageTypeState(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/id_vault.go new file mode 100644 index 00000000000..51077e303e5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/id_vault.go @@ -0,0 +1,127 @@ +package backupresourcevaultconfigs + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/id_vault_test.go new file mode 100644 index 00000000000..81754279bbb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/id_vault_test.go @@ -0,0 +1,282 @@ +package backupresourcevaultconfigs + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_get_autorest.go new file mode 100644 index 00000000000..709a6190da7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_get_autorest.go @@ -0,0 +1,69 @@ +package backupresourcevaultconfigs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *BackupResourceVaultConfigResource +} + +// Get ... +func (c BackupResourceVaultConfigsClient) Get(ctx context.Context, id VaultId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c BackupResourceVaultConfigsClient) preparerForGet(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupconfig/vaultconfig", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c BackupResourceVaultConfigsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_put_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_put_autorest.go new file mode 100644 index 00000000000..d7874fa3e4f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_put_autorest.go @@ -0,0 +1,70 @@ +package backupresourcevaultconfigs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutOperationResponse struct { + HttpResponse *http.Response + Model *BackupResourceVaultConfigResource +} + +// Put ... +func (c BackupResourceVaultConfigsClient) Put(ctx context.Context, id VaultId, input BackupResourceVaultConfigResource) (result PutOperationResponse, err error) { + req, err := c.preparerForPut(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Put", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Put", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPut(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Put", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPut prepares the Put request. +func (c BackupResourceVaultConfigsClient) preparerForPut(ctx context.Context, id VaultId, input BackupResourceVaultConfigResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupconfig/vaultconfig", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPut handles the response to the Put request. The method always +// closes the http.Response Body. +func (c BackupResourceVaultConfigsClient) responderForPut(resp *http.Response) (result PutOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_update_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_update_autorest.go new file mode 100644 index 00000000000..834657e3477 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/method_update_autorest.go @@ -0,0 +1,70 @@ +package backupresourcevaultconfigs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + Model *BackupResourceVaultConfigResource +} + +// Update ... +func (c BackupResourceVaultConfigsClient) Update(ctx context.Context, id VaultId, input BackupResourceVaultConfigResource) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupresourcevaultconfigs.BackupResourceVaultConfigsClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c BackupResourceVaultConfigsClient) preparerForUpdate(ctx context.Context, id VaultId, input BackupResourceVaultConfigResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupconfig/vaultconfig", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUpdate handles the response to the Update request. The method always +// closes the http.Response Body. +func (c BackupResourceVaultConfigsClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/model_backupresourcevaultconfig.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/model_backupresourcevaultconfig.go new file mode 100644 index 00000000000..1e68a54676e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/model_backupresourcevaultconfig.go @@ -0,0 +1,14 @@ +package backupresourcevaultconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceVaultConfig struct { + EnhancedSecurityState *EnhancedSecurityState `json:"enhancedSecurityState,omitempty"` + IsSoftDeleteFeatureStateEditable *bool `json:"isSoftDeleteFeatureStateEditable,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteFeatureState *SoftDeleteFeatureState `json:"softDeleteFeatureState,omitempty"` + StorageModelType *StorageType `json:"storageModelType,omitempty"` + StorageType *StorageType `json:"storageType,omitempty"` + StorageTypeState *StorageTypeState `json:"storageTypeState,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/model_backupresourcevaultconfigresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/model_backupresourcevaultconfigresource.go new file mode 100644 index 00000000000..9957131bbd6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/model_backupresourcevaultconfigresource.go @@ -0,0 +1,14 @@ +package backupresourcevaultconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupResourceVaultConfigResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupResourceVaultConfig `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/version.go new file mode 100644 index 00000000000..3c29b187dfd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs/version.go @@ -0,0 +1,12 @@ +package backupresourcevaultconfigs + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupresourcevaultconfigs/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backups/README.md new file mode 100644 index 00000000000..ea49925107d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backups` Documentation + +The `backups` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backups" +``` + + +### Client Initialization + +```go +client := backups.NewBackupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupsClient.Trigger` + +```go +ctx := context.TODO() +id := backups.NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + +payload := backups.BackupRequestResource{ + // ... +} + + +read, err := client.Trigger(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/recoveryservicesbackup/2023-02-01/backups/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/client.go new file mode 100644 index 00000000000..8669bac74ee --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/client.go @@ -0,0 +1,18 @@ +package backups + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupsClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupsClientWithBaseURI(endpoint string) BackupsClient { + return BackupsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/constants.go new file mode 100644 index 00000000000..28cae0d72b3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/constants.go @@ -0,0 +1,52 @@ +package backups + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupType string + +const ( + BackupTypeCopyOnlyFull BackupType = "CopyOnlyFull" + BackupTypeDifferential BackupType = "Differential" + BackupTypeFull BackupType = "Full" + BackupTypeIncremental BackupType = "Incremental" + BackupTypeInvalid BackupType = "Invalid" + BackupTypeLog BackupType = "Log" + BackupTypeSnapshotCopyOnlyFull BackupType = "SnapshotCopyOnlyFull" + BackupTypeSnapshotFull BackupType = "SnapshotFull" +) + +func PossibleValuesForBackupType() []string { + return []string{ + string(BackupTypeCopyOnlyFull), + string(BackupTypeDifferential), + string(BackupTypeFull), + string(BackupTypeIncremental), + string(BackupTypeInvalid), + string(BackupTypeLog), + string(BackupTypeSnapshotCopyOnlyFull), + string(BackupTypeSnapshotFull), + } +} + +func parseBackupType(input string) (*BackupType, error) { + vals := map[string]BackupType{ + "copyonlyfull": BackupTypeCopyOnlyFull, + "differential": BackupTypeDifferential, + "full": BackupTypeFull, + "incremental": BackupTypeIncremental, + "invalid": BackupTypeInvalid, + "log": BackupTypeLog, + "snapshotcopyonlyfull": BackupTypeSnapshotCopyOnlyFull, + "snapshotfull": BackupTypeSnapshotFull, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/id_protecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/id_protecteditem.go new file mode 100644 index 00000000000..60b887038ce --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/id_protecteditem.go @@ -0,0 +1,166 @@ +package backups + +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 = ProtectedItemId{} + +// ProtectedItemId is a struct representing the Resource ID for a Protected Item +type ProtectedItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string +} + +// NewProtectedItemID returns a new ProtectedItemId struct +func NewProtectedItemID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string) ProtectedItemId { + return ProtectedItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + } +} + +// ParseProtectedItemID parses 'input' into a ProtectedItemId +func ParseProtectedItemID(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProtectedItemIDInsensitively parses 'input' case-insensitively into a ProtectedItemId +// note: this method should only be used for API response data and not user input +func ParseProtectedItemIDInsensitively(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProtectedItemID checks that 'input' can be parsed as a Protected Item ID +func ValidateProtectedItemID(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 := ParseProtectedItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Protected Item ID +func (id ProtectedItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Protected Item ID +func (id ProtectedItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + } +} + +// String returns a human-readable description of this Protected Item ID +func (id ProtectedItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + } + return fmt.Sprintf("Protected Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/id_protecteditem_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/id_protecteditem_test.go new file mode 100644 index 00000000000..d4457b32a07 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/id_protecteditem_test.go @@ -0,0 +1,417 @@ +package backups + +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 = ProtectedItemId{} + +func TestNewProtectedItemID(t *testing.T) { + id := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } +} + +func TestFormatProtectedItemID(t *testing.T) { + actual := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProtectedItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestParseProtectedItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestSegmentsForProtectedItemId(t *testing.T) { + segments := ProtectedItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProtectedItemId 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/recoveryservicesbackup/2023-02-01/backups/method_trigger_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/method_trigger_autorest.go new file mode 100644 index 00000000000..bf23ac4685b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/method_trigger_autorest.go @@ -0,0 +1,68 @@ +package backups + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerOperationResponse struct { + HttpResponse *http.Response +} + +// Trigger ... +func (c BackupsClient) Trigger(ctx context.Context, id ProtectedItemId, input BackupRequestResource) (result TriggerOperationResponse, err error) { + req, err := c.preparerForTrigger(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "backups.BackupsClient", "Trigger", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backups.BackupsClient", "Trigger", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForTrigger(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backups.BackupsClient", "Trigger", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForTrigger prepares the Trigger request. +func (c BackupsClient) preparerForTrigger(ctx context.Context, id ProtectedItemId, input BackupRequestResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backup", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForTrigger handles the response to the Trigger request. The method always +// closes the http.Response Body. +func (c BackupsClient) responderForTrigger(resp *http.Response) (result TriggerOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_azurefilesharebackuprequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_azurefilesharebackuprequest.go new file mode 100644 index 00000000000..99ddceed9c6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_azurefilesharebackuprequest.go @@ -0,0 +1,41 @@ +package backups + +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 _ BackupRequest = AzureFileShareBackupRequest{} + +type AzureFileShareBackupRequest struct { + RecoveryPointExpiryTimeInUTC *string `json:"recoveryPointExpiryTimeInUTC,omitempty"` + + // Fields inherited from BackupRequest +} + +var _ json.Marshaler = AzureFileShareBackupRequest{} + +func (s AzureFileShareBackupRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareBackupRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareBackupRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareBackupRequest: %+v", err) + } + decoded["objectType"] = "AzureFileShareBackupRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareBackupRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_azureworkloadbackuprequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_azureworkloadbackuprequest.go new file mode 100644 index 00000000000..dff561d8271 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_azureworkloadbackuprequest.go @@ -0,0 +1,43 @@ +package backups + +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 _ BackupRequest = AzureWorkloadBackupRequest{} + +type AzureWorkloadBackupRequest struct { + BackupType *BackupType `json:"backupType,omitempty"` + EnableCompression *bool `json:"enableCompression,omitempty"` + RecoveryPointExpiryTimeInUTC *string `json:"recoveryPointExpiryTimeInUTC,omitempty"` + + // Fields inherited from BackupRequest +} + +var _ json.Marshaler = AzureWorkloadBackupRequest{} + +func (s AzureWorkloadBackupRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadBackupRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadBackupRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadBackupRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadBackupRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadBackupRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_backuprequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_backuprequest.go new file mode 100644 index 00000000000..6dcc49d7502 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_backuprequest.go @@ -0,0 +1,64 @@ +package backups + +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 BackupRequest interface { +} + +func unmarshalBackupRequestImplementation(input []byte) (BackupRequest, 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 BackupRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareBackupRequest") { + var out AzureFileShareBackupRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareBackupRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadBackupRequest") { + var out AzureWorkloadBackupRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadBackupRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMBackupRequest") { + var out IaasVMBackupRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMBackupRequest: %+v", err) + } + return out, nil + } + + type RawBackupRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawBackupRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_backuprequestresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_backuprequestresource.go new file mode 100644 index 00000000000..9f57a8a255b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_backuprequestresource.go @@ -0,0 +1,50 @@ +package backups + +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 BackupRequestResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties BackupRequest `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &BackupRequestResource{} + +func (s *BackupRequestResource) UnmarshalJSON(bytes []byte) error { + type alias BackupRequestResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into BackupRequestResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BackupRequestResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalBackupRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'BackupRequestResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_iaasvmbackuprequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_iaasvmbackuprequest.go new file mode 100644 index 00000000000..d40c0c3ccf0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/model_iaasvmbackuprequest.go @@ -0,0 +1,41 @@ +package backups + +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 _ BackupRequest = IaasVMBackupRequest{} + +type IaasVMBackupRequest struct { + RecoveryPointExpiryTimeInUTC *string `json:"recoveryPointExpiryTimeInUTC,omitempty"` + + // Fields inherited from BackupRequest +} + +var _ json.Marshaler = IaasVMBackupRequest{} + +func (s IaasVMBackupRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMBackupRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMBackupRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMBackupRequest: %+v", err) + } + decoded["objectType"] = "IaasVMBackupRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMBackupRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backups/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backups/version.go new file mode 100644 index 00000000000..966073657e1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backups/version.go @@ -0,0 +1,12 @@ +package backups + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backups/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/README.md new file mode 100644 index 00000000000..73d600a5a88 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus` Documentation + +The `backupstatus` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupstatus" +``` + + +### Client Initialization + +```go +client := backupstatus.NewBackupStatusClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupStatusClient.Get` + +```go +ctx := context.TODO() +id := backupstatus.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := backupstatus.BackupStatusRequest{ + // ... +} + + +read, err := client.Get(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/recoveryservicesbackup/2023-02-01/backupstatus/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/client.go new file mode 100644 index 00000000000..d17f64f2d24 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/client.go @@ -0,0 +1,18 @@ +package backupstatus + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupStatusClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupStatusClientWithBaseURI(endpoint string) BackupStatusClient { + return BackupStatusClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/constants.go new file mode 100644 index 00000000000..9aaf6a8c63b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/constants.go @@ -0,0 +1,141 @@ +package backupstatus + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataSourceType string + +const ( + DataSourceTypeAzureFileShare DataSourceType = "AzureFileShare" + DataSourceTypeAzureSqlDb DataSourceType = "AzureSqlDb" + DataSourceTypeClient DataSourceType = "Client" + DataSourceTypeExchange DataSourceType = "Exchange" + DataSourceTypeFileFolder DataSourceType = "FileFolder" + DataSourceTypeGenericDataSource DataSourceType = "GenericDataSource" + DataSourceTypeInvalid DataSourceType = "Invalid" + DataSourceTypeSAPAseDatabase DataSourceType = "SAPAseDatabase" + DataSourceTypeSAPHanaDBInstance DataSourceType = "SAPHanaDBInstance" + DataSourceTypeSAPHanaDatabase DataSourceType = "SAPHanaDatabase" + DataSourceTypeSQLDB DataSourceType = "SQLDB" + DataSourceTypeSQLDataBase DataSourceType = "SQLDataBase" + DataSourceTypeSharepoint DataSourceType = "Sharepoint" + DataSourceTypeSystemState DataSourceType = "SystemState" + DataSourceTypeVM DataSourceType = "VM" + DataSourceTypeVMwareVM DataSourceType = "VMwareVM" +) + +func PossibleValuesForDataSourceType() []string { + return []string{ + string(DataSourceTypeAzureFileShare), + string(DataSourceTypeAzureSqlDb), + string(DataSourceTypeClient), + string(DataSourceTypeExchange), + string(DataSourceTypeFileFolder), + string(DataSourceTypeGenericDataSource), + string(DataSourceTypeInvalid), + string(DataSourceTypeSAPAseDatabase), + string(DataSourceTypeSAPHanaDBInstance), + string(DataSourceTypeSAPHanaDatabase), + string(DataSourceTypeSQLDB), + string(DataSourceTypeSQLDataBase), + string(DataSourceTypeSharepoint), + string(DataSourceTypeSystemState), + string(DataSourceTypeVM), + string(DataSourceTypeVMwareVM), + } +} + +func parseDataSourceType(input string) (*DataSourceType, error) { + vals := map[string]DataSourceType{ + "azurefileshare": DataSourceTypeAzureFileShare, + "azuresqldb": DataSourceTypeAzureSqlDb, + "client": DataSourceTypeClient, + "exchange": DataSourceTypeExchange, + "filefolder": DataSourceTypeFileFolder, + "genericdatasource": DataSourceTypeGenericDataSource, + "invalid": DataSourceTypeInvalid, + "sapasedatabase": DataSourceTypeSAPAseDatabase, + "saphanadbinstance": DataSourceTypeSAPHanaDBInstance, + "saphanadatabase": DataSourceTypeSAPHanaDatabase, + "sqldb": DataSourceTypeSQLDB, + "sqldatabase": DataSourceTypeSQLDataBase, + "sharepoint": DataSourceTypeSharepoint, + "systemstate": DataSourceTypeSystemState, + "vm": DataSourceTypeVM, + "vmwarevm": DataSourceTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataSourceType(input) + return &out, nil +} + +type FabricName string + +const ( + FabricNameAzure FabricName = "Azure" + FabricNameInvalid FabricName = "Invalid" +) + +func PossibleValuesForFabricName() []string { + return []string{ + string(FabricNameAzure), + string(FabricNameInvalid), + } +} + +func parseFabricName(input string) (*FabricName, error) { + vals := map[string]FabricName{ + "azure": FabricNameAzure, + "invalid": FabricNameInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FabricName(input) + return &out, nil +} + +type ProtectionStatus string + +const ( + ProtectionStatusInvalid ProtectionStatus = "Invalid" + ProtectionStatusNotProtected ProtectionStatus = "NotProtected" + ProtectionStatusProtected ProtectionStatus = "Protected" + ProtectionStatusProtecting ProtectionStatus = "Protecting" + ProtectionStatusProtectionFailed ProtectionStatus = "ProtectionFailed" +) + +func PossibleValuesForProtectionStatus() []string { + return []string{ + string(ProtectionStatusInvalid), + string(ProtectionStatusNotProtected), + string(ProtectionStatusProtected), + string(ProtectionStatusProtecting), + string(ProtectionStatusProtectionFailed), + } +} + +func parseProtectionStatus(input string) (*ProtectionStatus, error) { + vals := map[string]ProtectionStatus{ + "invalid": ProtectionStatusInvalid, + "notprotected": ProtectionStatusNotProtected, + "protected": ProtectionStatusProtected, + "protecting": ProtectionStatusProtecting, + "protectionfailed": ProtectionStatusProtectionFailed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/id_location.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/id_location.go new file mode 100644 index 00000000000..1f43d9457dc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/id_location.go @@ -0,0 +1,114 @@ +package backupstatus + +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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, 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.RecoveryServices/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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + 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/recoveryservicesbackup/2023-02-01/backupstatus/id_location_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/id_location_test.go new file mode 100644 index 00000000000..74a0c58de05 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/id_location_test.go @@ -0,0 +1,237 @@ +package backupstatus + +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.RecoveryServices/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/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.RecoveryServices/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/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.RecoveryServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/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.rEcOvErYsErViCeS/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/recoveryservicesbackup/2023-02-01/backupstatus/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/method_get_autorest.go new file mode 100644 index 00000000000..5bdbd049ea0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/method_get_autorest.go @@ -0,0 +1,70 @@ +package backupstatus + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *BackupStatusResponse +} + +// Get ... +func (c BackupStatusClient) Get(ctx context.Context, id LocationId, input BackupStatusRequest) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "backupstatus.BackupStatusClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupstatus.BackupStatusClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupstatus.BackupStatusClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c BackupStatusClient) preparerForGet(ctx context.Context, id LocationId, input BackupStatusRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupStatus", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c BackupStatusClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/model_backupstatusrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/model_backupstatusrequest.go new file mode 100644 index 00000000000..18355d1d1a4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/model_backupstatusrequest.go @@ -0,0 +1,10 @@ +package backupstatus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupStatusRequest struct { + PoLogicalName *string `json:"poLogicalName,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + ResourceType *DataSourceType `json:"resourceType,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/model_backupstatusresponse.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/model_backupstatusresponse.go new file mode 100644 index 00000000000..f3568b8ffe5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/model_backupstatusresponse.go @@ -0,0 +1,16 @@ +package backupstatus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupStatusResponse struct { + ContainerName *string `json:"containerName,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + FabricName *FabricName `json:"fabricName,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ProtectedItemName *string `json:"protectedItemName,omitempty"` + ProtectionStatus *ProtectionStatus `json:"protectionStatus,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` + VaultId *string `json:"vaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/version.go new file mode 100644 index 00000000000..b3f50367e7f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus/version.go @@ -0,0 +1,12 @@ +package backupstatus + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupstatus/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/README.md new file mode 100644 index 00000000000..5cf6253b637 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries` Documentation + +The `backupusagesummaries` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupusagesummaries" +``` + + +### Client Initialization + +```go +client := backupusagesummaries.NewBackupUsageSummariesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupUsageSummariesClient.List` + +```go +ctx := context.TODO() +id := backupusagesummaries.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +read, err := client.List(ctx, id, backupusagesummaries.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/client.go new file mode 100644 index 00000000000..d6dbffa806e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/client.go @@ -0,0 +1,18 @@ +package backupusagesummaries + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupUsageSummariesClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupUsageSummariesClientWithBaseURI(endpoint string) BackupUsageSummariesClient { + return BackupUsageSummariesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/constants.go new file mode 100644 index 00000000000..397d5b32331 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/constants.go @@ -0,0 +1,46 @@ +package backupusagesummaries + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesUnit string + +const ( + UsagesUnitBytes UsagesUnit = "Bytes" + UsagesUnitBytesPerSecond UsagesUnit = "BytesPerSecond" + UsagesUnitCount UsagesUnit = "Count" + UsagesUnitCountPerSecond UsagesUnit = "CountPerSecond" + UsagesUnitPercent UsagesUnit = "Percent" + UsagesUnitSeconds UsagesUnit = "Seconds" +) + +func PossibleValuesForUsagesUnit() []string { + return []string{ + string(UsagesUnitBytes), + string(UsagesUnitBytesPerSecond), + string(UsagesUnitCount), + string(UsagesUnitCountPerSecond), + string(UsagesUnitPercent), + string(UsagesUnitSeconds), + } +} + +func parseUsagesUnit(input string) (*UsagesUnit, error) { + vals := map[string]UsagesUnit{ + "bytes": UsagesUnitBytes, + "bytespersecond": UsagesUnitBytesPerSecond, + "count": UsagesUnitCount, + "countpersecond": UsagesUnitCountPerSecond, + "percent": UsagesUnitPercent, + "seconds": UsagesUnitSeconds, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsagesUnit(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/id_vault.go new file mode 100644 index 00000000000..81e1a81b7ab --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/id_vault.go @@ -0,0 +1,127 @@ +package backupusagesummaries + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/id_vault_test.go new file mode 100644 index 00000000000..dffbd0529e6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/id_vault_test.go @@ -0,0 +1,282 @@ +package backupusagesummaries + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/backupusagesummaries/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/method_list_autorest.go new file mode 100644 index 00000000000..eb50ac6c024 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/method_list_autorest.go @@ -0,0 +1,98 @@ +package backupusagesummaries + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *BackupManagementUsage +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupUsageSummariesClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (result ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupusagesummaries.BackupUsageSummariesClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupusagesummaries.BackupUsageSummariesClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupusagesummaries.BackupUsageSummariesClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForList prepares the List request. +func (c BackupUsageSummariesClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupUsageSummaries", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupUsageSummariesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/model_backupmanagementusage.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/model_backupmanagementusage.go new file mode 100644 index 00000000000..decb29b6951 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/model_backupmanagementusage.go @@ -0,0 +1,31 @@ +package backupusagesummaries + +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 BackupManagementUsage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *NameInfo `json:"name,omitempty"` + NextResetTime *string `json:"nextResetTime,omitempty"` + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + Unit *UsagesUnit `json:"unit,omitempty"` +} + +func (o *BackupManagementUsage) GetNextResetTimeAsTime() (*time.Time, error) { + if o.NextResetTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NextResetTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *BackupManagementUsage) SetNextResetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NextResetTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/model_nameinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/model_nameinfo.go new file mode 100644 index 00000000000..68fde56d864 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/model_nameinfo.go @@ -0,0 +1,9 @@ +package backupusagesummaries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameInfo struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/version.go new file mode 100644 index 00000000000..b3d20ce1066 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries/version.go @@ -0,0 +1,12 @@ +package backupusagesummaries + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupusagesummaries/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/README.md new file mode 100644 index 00000000000..d91865c652b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems` Documentation + +The `backupworkloaditems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/backupworkloaditems" +``` + + +### Client Initialization + +```go +client := backupworkloaditems.NewBackupWorkloadItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupWorkloadItemsClient.List` + +```go +ctx := context.TODO() +id := backupworkloaditems.NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue") + +// alternatively `client.List(ctx, id, backupworkloaditems.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, backupworkloaditems.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/client.go new file mode 100644 index 00000000000..2493a9d3ce5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/client.go @@ -0,0 +1,18 @@ +package backupworkloaditems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupWorkloadItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewBackupWorkloadItemsClientWithBaseURI(endpoint string) BackupWorkloadItemsClient { + return BackupWorkloadItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/constants.go new file mode 100644 index 00000000000..53f53e17687 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/constants.go @@ -0,0 +1,74 @@ +package backupworkloaditems + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionStatus string + +const ( + ProtectionStatusInvalid ProtectionStatus = "Invalid" + ProtectionStatusNotProtected ProtectionStatus = "NotProtected" + ProtectionStatusProtected ProtectionStatus = "Protected" + ProtectionStatusProtecting ProtectionStatus = "Protecting" + ProtectionStatusProtectionFailed ProtectionStatus = "ProtectionFailed" +) + +func PossibleValuesForProtectionStatus() []string { + return []string{ + string(ProtectionStatusInvalid), + string(ProtectionStatusNotProtected), + string(ProtectionStatusProtected), + string(ProtectionStatusProtecting), + string(ProtectionStatusProtectionFailed), + } +} + +func parseProtectionStatus(input string) (*ProtectionStatus, error) { + vals := map[string]ProtectionStatus{ + "invalid": ProtectionStatusInvalid, + "notprotected": ProtectionStatusNotProtected, + "protected": ProtectionStatusProtected, + "protecting": ProtectionStatusProtecting, + "protectionfailed": ProtectionStatusProtectionFailed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionStatus(input) + return &out, nil +} + +type SQLDataDirectoryType string + +const ( + SQLDataDirectoryTypeData SQLDataDirectoryType = "Data" + SQLDataDirectoryTypeInvalid SQLDataDirectoryType = "Invalid" + SQLDataDirectoryTypeLog SQLDataDirectoryType = "Log" +) + +func PossibleValuesForSQLDataDirectoryType() []string { + return []string{ + string(SQLDataDirectoryTypeData), + string(SQLDataDirectoryTypeInvalid), + string(SQLDataDirectoryTypeLog), + } +} + +func parseSQLDataDirectoryType(input string) (*SQLDataDirectoryType, error) { + vals := map[string]SQLDataDirectoryType{ + "data": SQLDataDirectoryTypeData, + "invalid": SQLDataDirectoryTypeInvalid, + "log": SQLDataDirectoryTypeLog, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SQLDataDirectoryType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/id_protectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/id_protectioncontainer.go new file mode 100644 index 00000000000..4c22cd3fe7f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/id_protectioncontainer.go @@ -0,0 +1,153 @@ +package backupworkloaditems + +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 = ProtectionContainerId{} + +// ProtectionContainerId is a struct representing the Resource ID for a Protection Container +type ProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string + ProtectionContainerName string +} + +// NewProtectionContainerID returns a new ProtectionContainerId struct +func NewProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string) ProtectionContainerId { + return ProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + } +} + +// ParseProtectionContainerID parses 'input' into a ProtectionContainerId +func ParseProtectionContainerID(input string) (*ProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProtectionContainerIDInsensitively parses 'input' case-insensitively into a ProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseProtectionContainerIDInsensitively(input string) (*ProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProtectionContainerID checks that 'input' can be parsed as a Protection Container ID +func ValidateProtectionContainerID(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 := ParseProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Protection Container ID +func (id ProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Protection Container ID +func (id ProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + } +} + +// String returns a human-readable description of this Protection Container ID +func (id ProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + } + return fmt.Sprintf("Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/id_protectioncontainer_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/id_protectioncontainer_test.go new file mode 100644 index 00000000000..54442ebce90 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/id_protectioncontainer_test.go @@ -0,0 +1,372 @@ +package backupworkloaditems + +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 = ProtectionContainerId{} + +func TestNewProtectionContainerID(t *testing.T) { + id := NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } +} + +func TestFormatProtectionContainerID(t *testing.T) { + actual := NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProtectionContainerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Expected: &ProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectionContainerID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + } +} + +func TestParseProtectionContainerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Expected: &ProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Expected: &ProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectionContainerIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + } +} + +func TestSegmentsForProtectionContainerId(t *testing.T) { + segments := ProtectionContainerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProtectionContainerId 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/recoveryservicesbackup/2023-02-01/backupworkloaditems/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/method_list_autorest.go new file mode 100644 index 00000000000..a730a74a266 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/method_list_autorest.go @@ -0,0 +1,215 @@ +package backupworkloaditems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]WorkloadItemResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []WorkloadItemResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c BackupWorkloadItemsClient) List(ctx context.Context, id ProtectionContainerId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "backupworkloaditems.BackupWorkloadItemsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupworkloaditems.BackupWorkloadItemsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupworkloaditems.BackupWorkloadItemsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c BackupWorkloadItemsClient) preparerForList(ctx context.Context, id ProtectionContainerId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/items", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c BackupWorkloadItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c BackupWorkloadItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []WorkloadItemResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "backupworkloaditems.BackupWorkloadItemsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "backupworkloaditems.BackupWorkloadItemsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "backupworkloaditems.BackupWorkloadItemsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c BackupWorkloadItemsClient) ListComplete(ctx context.Context, id ProtectionContainerId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, WorkloadItemResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c BackupWorkloadItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id ProtectionContainerId, options ListOperationOptions, predicate WorkloadItemResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]WorkloadItemResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloaditem.go new file mode 100644 index 00000000000..69068df164a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloaditem.go @@ -0,0 +1,49 @@ +package backupworkloaditems + +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 _ WorkloadItem = AzureVMWorkloadItem{} + +type AzureVMWorkloadItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SubWorkloadItemCount *int64 `json:"subWorkloadItemCount,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + + // Fields inherited from WorkloadItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadItem{} + +func (s AzureVMWorkloadItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadItem: %+v", err) + } + decoded["workloadItemType"] = "AzureVmWorkloadItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsapasedatabaseworkloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsapasedatabaseworkloaditem.go new file mode 100644 index 00000000000..d2b7b5b550a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsapasedatabaseworkloaditem.go @@ -0,0 +1,49 @@ +package backupworkloaditems + +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 _ WorkloadItem = AzureVMWorkloadSAPAseDatabaseWorkloadItem{} + +type AzureVMWorkloadSAPAseDatabaseWorkloadItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SubWorkloadItemCount *int64 `json:"subWorkloadItemCount,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + + // Fields inherited from WorkloadItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPAseDatabaseWorkloadItem{} + +func (s AzureVMWorkloadSAPAseDatabaseWorkloadItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPAseDatabaseWorkloadItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPAseDatabaseWorkloadItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPAseDatabaseWorkloadItem: %+v", err) + } + decoded["workloadItemType"] = "SAPAseDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPAseDatabaseWorkloadItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsapasesystemworkloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsapasesystemworkloaditem.go new file mode 100644 index 00000000000..1f00dd9c164 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsapasesystemworkloaditem.go @@ -0,0 +1,49 @@ +package backupworkloaditems + +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 _ WorkloadItem = AzureVMWorkloadSAPAseSystemWorkloadItem{} + +type AzureVMWorkloadSAPAseSystemWorkloadItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SubWorkloadItemCount *int64 `json:"subWorkloadItemCount,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + + // Fields inherited from WorkloadItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPAseSystemWorkloadItem{} + +func (s AzureVMWorkloadSAPAseSystemWorkloadItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPAseSystemWorkloadItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPAseSystemWorkloadItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPAseSystemWorkloadItem: %+v", err) + } + decoded["workloadItemType"] = "SAPAseSystem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPAseSystemWorkloadItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsaphanadatabaseworkloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsaphanadatabaseworkloaditem.go new file mode 100644 index 00000000000..49058e10e85 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsaphanadatabaseworkloaditem.go @@ -0,0 +1,49 @@ +package backupworkloaditems + +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 _ WorkloadItem = AzureVMWorkloadSAPHanaDatabaseWorkloadItem{} + +type AzureVMWorkloadSAPHanaDatabaseWorkloadItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SubWorkloadItemCount *int64 `json:"subWorkloadItemCount,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + + // Fields inherited from WorkloadItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaDatabaseWorkloadItem{} + +func (s AzureVMWorkloadSAPHanaDatabaseWorkloadItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaDatabaseWorkloadItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaDatabaseWorkloadItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaDatabaseWorkloadItem: %+v", err) + } + decoded["workloadItemType"] = "SAPHanaDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaDatabaseWorkloadItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsaphanasystemworkloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsaphanasystemworkloaditem.go new file mode 100644 index 00000000000..9b7e843c0bd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsaphanasystemworkloaditem.go @@ -0,0 +1,49 @@ +package backupworkloaditems + +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 _ WorkloadItem = AzureVMWorkloadSAPHanaSystemWorkloadItem{} + +type AzureVMWorkloadSAPHanaSystemWorkloadItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SubWorkloadItemCount *int64 `json:"subWorkloadItemCount,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + + // Fields inherited from WorkloadItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaSystemWorkloadItem{} + +func (s AzureVMWorkloadSAPHanaSystemWorkloadItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaSystemWorkloadItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaSystemWorkloadItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaSystemWorkloadItem: %+v", err) + } + decoded["workloadItemType"] = "SAPHanaSystem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaSystemWorkloadItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsqldatabaseworkloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsqldatabaseworkloaditem.go new file mode 100644 index 00000000000..d857da81c38 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsqldatabaseworkloaditem.go @@ -0,0 +1,49 @@ +package backupworkloaditems + +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 _ WorkloadItem = AzureVMWorkloadSQLDatabaseWorkloadItem{} + +type AzureVMWorkloadSQLDatabaseWorkloadItem struct { + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SubWorkloadItemCount *int64 `json:"subWorkloadItemCount,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + + // Fields inherited from WorkloadItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSQLDatabaseWorkloadItem{} + +func (s AzureVMWorkloadSQLDatabaseWorkloadItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSQLDatabaseWorkloadItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSQLDatabaseWorkloadItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSQLDatabaseWorkloadItem: %+v", err) + } + decoded["workloadItemType"] = "SQLDataBase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSQLDatabaseWorkloadItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsqlinstanceworkloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsqlinstanceworkloaditem.go new file mode 100644 index 00000000000..1179d25dea3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_azurevmworkloadsqlinstanceworkloaditem.go @@ -0,0 +1,50 @@ +package backupworkloaditems + +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 _ WorkloadItem = AzureVMWorkloadSQLInstanceWorkloadItem{} + +type AzureVMWorkloadSQLInstanceWorkloadItem struct { + DataDirectoryPaths *[]SQLDataDirectory `json:"dataDirectoryPaths,omitempty"` + IsAutoProtectable *bool `json:"isAutoProtectable,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SubWorkloadItemCount *int64 `json:"subWorkloadItemCount,omitempty"` + Subinquireditemcount *int64 `json:"subinquireditemcount,omitempty"` + + // Fields inherited from WorkloadItem + BackupManagementType *string `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadSQLInstanceWorkloadItem{} + +func (s AzureVMWorkloadSQLInstanceWorkloadItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSQLInstanceWorkloadItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSQLInstanceWorkloadItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSQLInstanceWorkloadItem: %+v", err) + } + decoded["workloadItemType"] = "SQLInstance" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSQLInstanceWorkloadItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_sqldatadirectory.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_sqldatadirectory.go new file mode 100644 index 00000000000..2bae2b886be --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_sqldatadirectory.go @@ -0,0 +1,10 @@ +package backupworkloaditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SQLDataDirectory struct { + LogicalName *string `json:"logicalName,omitempty"` + Path *string `json:"path,omitempty"` + Type *SQLDataDirectoryType `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_workloaditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_workloaditem.go new file mode 100644 index 00000000000..61acc5d4e1c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_workloaditem.go @@ -0,0 +1,96 @@ +package backupworkloaditems + +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 WorkloadItem interface { +} + +func unmarshalWorkloadItemImplementation(input []byte) (WorkloadItem, 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 WorkloadItem into map[string]interface: %+v", err) + } + + value, ok := temp["workloadItemType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadItem") { + var out AzureVMWorkloadItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPAseDatabase") { + var out AzureVMWorkloadSAPAseDatabaseWorkloadItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPAseDatabaseWorkloadItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPAseSystem") { + var out AzureVMWorkloadSAPAseSystemWorkloadItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPAseSystemWorkloadItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPHanaDatabase") { + var out AzureVMWorkloadSAPHanaDatabaseWorkloadItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaDatabaseWorkloadItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SAPHanaSystem") { + var out AzureVMWorkloadSAPHanaSystemWorkloadItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaSystemWorkloadItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLDataBase") { + var out AzureVMWorkloadSQLDatabaseWorkloadItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSQLDatabaseWorkloadItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLInstance") { + var out AzureVMWorkloadSQLInstanceWorkloadItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSQLInstanceWorkloadItem: %+v", err) + } + return out, nil + } + + type RawWorkloadItemImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawWorkloadItemImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_workloaditemresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_workloaditemresource.go new file mode 100644 index 00000000000..2c4a15f25c6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/model_workloaditemresource.go @@ -0,0 +1,50 @@ +package backupworkloaditems + +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 WorkloadItemResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties WorkloadItem `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &WorkloadItemResource{} + +func (s *WorkloadItemResource) UnmarshalJSON(bytes []byte) error { + type alias WorkloadItemResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into WorkloadItemResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling WorkloadItemResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalWorkloadItemImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'WorkloadItemResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/predicates.go new file mode 100644 index 00000000000..f69a0b485e2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/predicates.go @@ -0,0 +1,37 @@ +package backupworkloaditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadItemResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p WorkloadItemResourceOperationPredicate) Matches(input WorkloadItemResource) 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/recoveryservicesbackup/2023-02-01/backupworkloaditems/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/version.go new file mode 100644 index 00000000000..a0c3d728327 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems/version.go @@ -0,0 +1,12 @@ +package backupworkloaditems + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupworkloaditems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/client.go new file mode 100644 index 00000000000..3c2e4d7520e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/client.go @@ -0,0 +1,233 @@ +package v2023_02_01 + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupengines" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupjobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backuppolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectableitems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotecteditems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectioncontainers" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupprotectionintent" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupresourceencryptionconfigs" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcestorageconfigsnoncrr" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupresourcevaultconfigs" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backups" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupstatus" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupusagesummaries" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/backupworkloaditems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/datamove" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/jobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/operation" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/restores" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/securitypins" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Client struct { + BackupEngines *backupengines.BackupEnginesClient + BackupJobs *backupjobs.BackupJobsClient + BackupPolicies *backuppolicies.BackupPoliciesClient + BackupProtectableItems *backupprotectableitems.BackupProtectableItemsClient + BackupProtectedItems *backupprotecteditems.BackupProtectedItemsClient + BackupProtectionContainers *backupprotectioncontainers.BackupProtectionContainersClient + BackupProtectionIntent *backupprotectionintent.BackupProtectionIntentClient + BackupResourceEncryptionConfigs *backupresourceencryptionconfigs.BackupResourceEncryptionConfigsClient + BackupResourceStorageConfigsNonCRR *backupresourcestorageconfigsnoncrr.BackupResourceStorageConfigsNonCRRClient + BackupResourceVaultConfigs *backupresourcevaultconfigs.BackupResourceVaultConfigsClient + BackupStatus *backupstatus.BackupStatusClient + BackupUsageSummaries *backupusagesummaries.BackupUsageSummariesClient + BackupWorkloadItems *backupworkloaditems.BackupWorkloadItemsClient + Backups *backups.BackupsClient + DataMove *datamove.DataMoveClient + FeatureSupport *featuresupport.FeatureSupportClient + ItemLevelRecoveryConnections *itemlevelrecoveryconnections.ItemLevelRecoveryConnectionsClient + JobCancellations *jobcancellations.JobCancellationsClient + JobDetails *jobdetails.JobDetailsClient + Jobs *jobs.JobsClient + Operation *operation.OperationClient + PrivateEndpointConnection *privateendpointconnection.PrivateEndpointConnectionClient + ProtectableContainers *protectablecontainers.ProtectableContainersClient + ProtectedItems *protecteditems.ProtectedItemsClient + ProtectionContainers *protectioncontainers.ProtectionContainersClient + ProtectionIntent *protectionintent.ProtectionIntentClient + ProtectionPolicies *protectionpolicies.ProtectionPoliciesClient + RecoveryPoint *recoverypoint.RecoveryPointClient + RecoveryPoints *recoverypoints.RecoveryPointsClient + RecoveryPointsRecommendedForMove *recoverypointsrecommendedformove.RecoveryPointsRecommendedForMoveClient + ResourceGuardProxies *resourceguardproxies.ResourceGuardProxiesClient + ResourceGuardProxy *resourceguardproxy.ResourceGuardProxyClient + Restores *restores.RestoresClient + SecurityPINs *securitypins.SecurityPINsClient + SoftDeletedContainers *softdeletedcontainers.SoftDeletedContainersClient + ValidateOperation *validateoperation.ValidateOperationClient +} + +func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { + + backupEnginesClient := backupengines.NewBackupEnginesClientWithBaseURI(endpoint) + configureAuthFunc(&backupEnginesClient.Client) + + backupJobsClient := backupjobs.NewBackupJobsClientWithBaseURI(endpoint) + configureAuthFunc(&backupJobsClient.Client) + + backupPoliciesClient := backuppolicies.NewBackupPoliciesClientWithBaseURI(endpoint) + configureAuthFunc(&backupPoliciesClient.Client) + + backupProtectableItemsClient := backupprotectableitems.NewBackupProtectableItemsClientWithBaseURI(endpoint) + configureAuthFunc(&backupProtectableItemsClient.Client) + + backupProtectedItemsClient := backupprotecteditems.NewBackupProtectedItemsClientWithBaseURI(endpoint) + configureAuthFunc(&backupProtectedItemsClient.Client) + + backupProtectionContainersClient := backupprotectioncontainers.NewBackupProtectionContainersClientWithBaseURI(endpoint) + configureAuthFunc(&backupProtectionContainersClient.Client) + + backupProtectionIntentClient := backupprotectionintent.NewBackupProtectionIntentClientWithBaseURI(endpoint) + configureAuthFunc(&backupProtectionIntentClient.Client) + + backupResourceEncryptionConfigsClient := backupresourceencryptionconfigs.NewBackupResourceEncryptionConfigsClientWithBaseURI(endpoint) + configureAuthFunc(&backupResourceEncryptionConfigsClient.Client) + + backupResourceStorageConfigsNonCRRClient := backupresourcestorageconfigsnoncrr.NewBackupResourceStorageConfigsNonCRRClientWithBaseURI(endpoint) + configureAuthFunc(&backupResourceStorageConfigsNonCRRClient.Client) + + backupResourceVaultConfigsClient := backupresourcevaultconfigs.NewBackupResourceVaultConfigsClientWithBaseURI(endpoint) + configureAuthFunc(&backupResourceVaultConfigsClient.Client) + + backupStatusClient := backupstatus.NewBackupStatusClientWithBaseURI(endpoint) + configureAuthFunc(&backupStatusClient.Client) + + backupUsageSummariesClient := backupusagesummaries.NewBackupUsageSummariesClientWithBaseURI(endpoint) + configureAuthFunc(&backupUsageSummariesClient.Client) + + backupWorkloadItemsClient := backupworkloaditems.NewBackupWorkloadItemsClientWithBaseURI(endpoint) + configureAuthFunc(&backupWorkloadItemsClient.Client) + + backupsClient := backups.NewBackupsClientWithBaseURI(endpoint) + configureAuthFunc(&backupsClient.Client) + + dataMoveClient := datamove.NewDataMoveClientWithBaseURI(endpoint) + configureAuthFunc(&dataMoveClient.Client) + + featureSupportClient := featuresupport.NewFeatureSupportClientWithBaseURI(endpoint) + configureAuthFunc(&featureSupportClient.Client) + + itemLevelRecoveryConnectionsClient := itemlevelrecoveryconnections.NewItemLevelRecoveryConnectionsClientWithBaseURI(endpoint) + configureAuthFunc(&itemLevelRecoveryConnectionsClient.Client) + + jobCancellationsClient := jobcancellations.NewJobCancellationsClientWithBaseURI(endpoint) + configureAuthFunc(&jobCancellationsClient.Client) + + jobDetailsClient := jobdetails.NewJobDetailsClientWithBaseURI(endpoint) + configureAuthFunc(&jobDetailsClient.Client) + + jobsClient := jobs.NewJobsClientWithBaseURI(endpoint) + configureAuthFunc(&jobsClient.Client) + + operationClient := operation.NewOperationClientWithBaseURI(endpoint) + configureAuthFunc(&operationClient.Client) + + privateEndpointConnectionClient := privateendpointconnection.NewPrivateEndpointConnectionClientWithBaseURI(endpoint) + configureAuthFunc(&privateEndpointConnectionClient.Client) + + protectableContainersClient := protectablecontainers.NewProtectableContainersClientWithBaseURI(endpoint) + configureAuthFunc(&protectableContainersClient.Client) + + protectedItemsClient := protecteditems.NewProtectedItemsClientWithBaseURI(endpoint) + configureAuthFunc(&protectedItemsClient.Client) + + protectionContainersClient := protectioncontainers.NewProtectionContainersClientWithBaseURI(endpoint) + configureAuthFunc(&protectionContainersClient.Client) + + protectionIntentClient := protectionintent.NewProtectionIntentClientWithBaseURI(endpoint) + configureAuthFunc(&protectionIntentClient.Client) + + protectionPoliciesClient := protectionpolicies.NewProtectionPoliciesClientWithBaseURI(endpoint) + configureAuthFunc(&protectionPoliciesClient.Client) + + recoveryPointClient := recoverypoint.NewRecoveryPointClientWithBaseURI(endpoint) + configureAuthFunc(&recoveryPointClient.Client) + + recoveryPointsClient := recoverypoints.NewRecoveryPointsClientWithBaseURI(endpoint) + configureAuthFunc(&recoveryPointsClient.Client) + + recoveryPointsRecommendedForMoveClient := recoverypointsrecommendedformove.NewRecoveryPointsRecommendedForMoveClientWithBaseURI(endpoint) + configureAuthFunc(&recoveryPointsRecommendedForMoveClient.Client) + + resourceGuardProxiesClient := resourceguardproxies.NewResourceGuardProxiesClientWithBaseURI(endpoint) + configureAuthFunc(&resourceGuardProxiesClient.Client) + + resourceGuardProxyClient := resourceguardproxy.NewResourceGuardProxyClientWithBaseURI(endpoint) + configureAuthFunc(&resourceGuardProxyClient.Client) + + restoresClient := restores.NewRestoresClientWithBaseURI(endpoint) + configureAuthFunc(&restoresClient.Client) + + securityPINsClient := securitypins.NewSecurityPINsClientWithBaseURI(endpoint) + configureAuthFunc(&securityPINsClient.Client) + + softDeletedContainersClient := softdeletedcontainers.NewSoftDeletedContainersClientWithBaseURI(endpoint) + configureAuthFunc(&softDeletedContainersClient.Client) + + validateOperationClient := validateoperation.NewValidateOperationClientWithBaseURI(endpoint) + configureAuthFunc(&validateOperationClient.Client) + + return Client{ + BackupEngines: &backupEnginesClient, + BackupJobs: &backupJobsClient, + BackupPolicies: &backupPoliciesClient, + BackupProtectableItems: &backupProtectableItemsClient, + BackupProtectedItems: &backupProtectedItemsClient, + BackupProtectionContainers: &backupProtectionContainersClient, + BackupProtectionIntent: &backupProtectionIntentClient, + BackupResourceEncryptionConfigs: &backupResourceEncryptionConfigsClient, + BackupResourceStorageConfigsNonCRR: &backupResourceStorageConfigsNonCRRClient, + BackupResourceVaultConfigs: &backupResourceVaultConfigsClient, + BackupStatus: &backupStatusClient, + BackupUsageSummaries: &backupUsageSummariesClient, + BackupWorkloadItems: &backupWorkloadItemsClient, + Backups: &backupsClient, + DataMove: &dataMoveClient, + FeatureSupport: &featureSupportClient, + ItemLevelRecoveryConnections: &itemLevelRecoveryConnectionsClient, + JobCancellations: &jobCancellationsClient, + JobDetails: &jobDetailsClient, + Jobs: &jobsClient, + Operation: &operationClient, + PrivateEndpointConnection: &privateEndpointConnectionClient, + ProtectableContainers: &protectableContainersClient, + ProtectedItems: &protectedItemsClient, + ProtectionContainers: &protectionContainersClient, + ProtectionIntent: &protectionIntentClient, + ProtectionPolicies: &protectionPoliciesClient, + RecoveryPoint: &recoveryPointClient, + RecoveryPoints: &recoveryPointsClient, + RecoveryPointsRecommendedForMove: &recoveryPointsRecommendedForMoveClient, + ResourceGuardProxies: &resourceGuardProxiesClient, + ResourceGuardProxy: &resourceGuardProxyClient, + Restores: &restoresClient, + SecurityPINs: &securityPINsClient, + SoftDeletedContainers: &softDeletedContainersClient, + ValidateOperation: &validateOperationClient, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/README.md new file mode 100644 index 00000000000..16126f3bfde --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/datamove` Documentation + +The `datamove` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/datamove" +``` + + +### Client Initialization + +```go +client := datamove.NewDataMoveClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataMoveClient.BMSPrepareDataMove` + +```go +ctx := context.TODO() +id := datamove.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := datamove.PrepareDataMoveRequest{ + // ... +} + + +if err := client.BMSPrepareDataMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DataMoveClient.BMSTriggerDataMove` + +```go +ctx := context.TODO() +id := datamove.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := datamove.TriggerDataMoveRequest{ + // ... +} + + +if err := client.BMSTriggerDataMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/client.go new file mode 100644 index 00000000000..bca13a32cd6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/client.go @@ -0,0 +1,18 @@ +package datamove + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMoveClient struct { + Client autorest.Client + baseUri string +} + +func NewDataMoveClientWithBaseURI(endpoint string) DataMoveClient { + return DataMoveClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/constants.go new file mode 100644 index 00000000000..86a3e471eea --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/constants.go @@ -0,0 +1,37 @@ +package datamove + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMoveLevel string + +const ( + DataMoveLevelContainer DataMoveLevel = "Container" + DataMoveLevelInvalid DataMoveLevel = "Invalid" + DataMoveLevelVault DataMoveLevel = "Vault" +) + +func PossibleValuesForDataMoveLevel() []string { + return []string{ + string(DataMoveLevelContainer), + string(DataMoveLevelInvalid), + string(DataMoveLevelVault), + } +} + +func parseDataMoveLevel(input string) (*DataMoveLevel, error) { + vals := map[string]DataMoveLevel{ + "container": DataMoveLevelContainer, + "invalid": DataMoveLevelInvalid, + "vault": DataMoveLevelVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMoveLevel(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/id_vault.go new file mode 100644 index 00000000000..7320e70755e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/id_vault.go @@ -0,0 +1,127 @@ +package datamove + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/id_vault_test.go new file mode 100644 index 00000000000..68c6a7df86f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/id_vault_test.go @@ -0,0 +1,282 @@ +package datamove + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/datamove/method_bmspreparedatamove_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/method_bmspreparedatamove_autorest.go new file mode 100644 index 00000000000..460642bf637 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/method_bmspreparedatamove_autorest.go @@ -0,0 +1,79 @@ +package datamove + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BMSPrepareDataMoveOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// BMSPrepareDataMove ... +func (c DataMoveClient) BMSPrepareDataMove(ctx context.Context, id VaultId, input PrepareDataMoveRequest) (result BMSPrepareDataMoveOperationResponse, err error) { + req, err := c.preparerForBMSPrepareDataMove(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "datamove.DataMoveClient", "BMSPrepareDataMove", nil, "Failure preparing request") + return + } + + result, err = c.senderForBMSPrepareDataMove(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "datamove.DataMoveClient", "BMSPrepareDataMove", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// BMSPrepareDataMoveThenPoll performs BMSPrepareDataMove then polls until it's completed +func (c DataMoveClient) BMSPrepareDataMoveThenPoll(ctx context.Context, id VaultId, input PrepareDataMoveRequest) error { + result, err := c.BMSPrepareDataMove(ctx, id, input) + if err != nil { + return fmt.Errorf("performing BMSPrepareDataMove: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after BMSPrepareDataMove: %+v", err) + } + + return nil +} + +// preparerForBMSPrepareDataMove prepares the BMSPrepareDataMove request. +func (c DataMoveClient) preparerForBMSPrepareDataMove(ctx context.Context, id VaultId, input PrepareDataMoveRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupStorageConfig/vaultStorageConfig/prepareDataMove", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForBMSPrepareDataMove sends the BMSPrepareDataMove request. The method will close the +// http.Response Body if it receives an error. +func (c DataMoveClient) senderForBMSPrepareDataMove(ctx context.Context, req *http.Request) (future BMSPrepareDataMoveOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/method_bmstriggerdatamove_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/method_bmstriggerdatamove_autorest.go new file mode 100644 index 00000000000..5f89d916019 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/method_bmstriggerdatamove_autorest.go @@ -0,0 +1,79 @@ +package datamove + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BMSTriggerDataMoveOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// BMSTriggerDataMove ... +func (c DataMoveClient) BMSTriggerDataMove(ctx context.Context, id VaultId, input TriggerDataMoveRequest) (result BMSTriggerDataMoveOperationResponse, err error) { + req, err := c.preparerForBMSTriggerDataMove(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "datamove.DataMoveClient", "BMSTriggerDataMove", nil, "Failure preparing request") + return + } + + result, err = c.senderForBMSTriggerDataMove(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "datamove.DataMoveClient", "BMSTriggerDataMove", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// BMSTriggerDataMoveThenPoll performs BMSTriggerDataMove then polls until it's completed +func (c DataMoveClient) BMSTriggerDataMoveThenPoll(ctx context.Context, id VaultId, input TriggerDataMoveRequest) error { + result, err := c.BMSTriggerDataMove(ctx, id, input) + if err != nil { + return fmt.Errorf("performing BMSTriggerDataMove: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after BMSTriggerDataMove: %+v", err) + } + + return nil +} + +// preparerForBMSTriggerDataMove prepares the BMSTriggerDataMove request. +func (c DataMoveClient) preparerForBMSTriggerDataMove(ctx context.Context, id VaultId, input TriggerDataMoveRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupStorageConfig/vaultStorageConfig/triggerDataMove", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForBMSTriggerDataMove sends the BMSTriggerDataMove request. The method will close the +// http.Response Body if it receives an error. +func (c DataMoveClient) senderForBMSTriggerDataMove(ctx context.Context, req *http.Request) (future BMSTriggerDataMoveOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/model_preparedatamoverequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/model_preparedatamoverequest.go new file mode 100644 index 00000000000..f2e39d1cd8a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/model_preparedatamoverequest.go @@ -0,0 +1,12 @@ +package datamove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrepareDataMoveRequest struct { + DataMoveLevel DataMoveLevel `json:"dataMoveLevel"` + IgnoreMoved *bool `json:"ignoreMoved,omitempty"` + SourceContainerArmIds *[]string `json:"sourceContainerArmIds,omitempty"` + TargetRegion string `json:"targetRegion"` + TargetResourceId string `json:"targetResourceId"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/model_triggerdatamoverequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/model_triggerdatamoverequest.go new file mode 100644 index 00000000000..eb35ce70218 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/model_triggerdatamoverequest.go @@ -0,0 +1,13 @@ +package datamove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerDataMoveRequest struct { + CorrelationId string `json:"correlationId"` + DataMoveLevel DataMoveLevel `json:"dataMoveLevel"` + PauseGC *bool `json:"pauseGC,omitempty"` + SourceContainerArmIds *[]string `json:"sourceContainerArmIds,omitempty"` + SourceRegion string `json:"sourceRegion"` + SourceResourceId string `json:"sourceResourceId"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/datamove/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/version.go new file mode 100644 index 00000000000..ab631f36fa6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/datamove/version.go @@ -0,0 +1,12 @@ +package datamove + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/datamove/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/README.md new file mode 100644 index 00000000000..881eb48d6dd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport` Documentation + +The `featuresupport` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/featuresupport" +``` + + +### Client Initialization + +```go +client := featuresupport.NewFeatureSupportClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FeatureSupportClient.Validate` + +```go +ctx := context.TODO() +id := featuresupport.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := featuresupport.FeatureSupportRequest{ + // ... +} + + +read, err := client.Validate(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/recoveryservicesbackup/2023-02-01/featuresupport/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/client.go new file mode 100644 index 00000000000..b4f22ceed18 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/client.go @@ -0,0 +1,18 @@ +package featuresupport + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FeatureSupportClient struct { + Client autorest.Client + baseUri string +} + +func NewFeatureSupportClientWithBaseURI(endpoint string) FeatureSupportClient { + return FeatureSupportClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/constants.go new file mode 100644 index 00000000000..e44ccfc6c48 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/constants.go @@ -0,0 +1,43 @@ +package featuresupport + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportStatus string + +const ( + SupportStatusDefaultOFF SupportStatus = "DefaultOFF" + SupportStatusDefaultON SupportStatus = "DefaultON" + SupportStatusInvalid SupportStatus = "Invalid" + SupportStatusNotSupported SupportStatus = "NotSupported" + SupportStatusSupported SupportStatus = "Supported" +) + +func PossibleValuesForSupportStatus() []string { + return []string{ + string(SupportStatusDefaultOFF), + string(SupportStatusDefaultON), + string(SupportStatusInvalid), + string(SupportStatusNotSupported), + string(SupportStatusSupported), + } +} + +func parseSupportStatus(input string) (*SupportStatus, error) { + vals := map[string]SupportStatus{ + "defaultoff": SupportStatusDefaultOFF, + "defaulton": SupportStatusDefaultON, + "invalid": SupportStatusInvalid, + "notsupported": SupportStatusNotSupported, + "supported": SupportStatusSupported, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SupportStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/id_location.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/id_location.go new file mode 100644 index 00000000000..cc38bc4eec4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/id_location.go @@ -0,0 +1,114 @@ +package featuresupport + +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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, 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.RecoveryServices/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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + 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/recoveryservicesbackup/2023-02-01/featuresupport/id_location_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/id_location_test.go new file mode 100644 index 00000000000..b8d683bb350 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/id_location_test.go @@ -0,0 +1,237 @@ +package featuresupport + +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.RecoveryServices/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/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.RecoveryServices/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/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.RecoveryServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/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.rEcOvErYsErViCeS/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/recoveryservicesbackup/2023-02-01/featuresupport/method_validate_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/method_validate_autorest.go new file mode 100644 index 00000000000..71e04fc843f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/method_validate_autorest.go @@ -0,0 +1,70 @@ +package featuresupport + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateOperationResponse struct { + HttpResponse *http.Response + Model *AzureVMResourceFeatureSupportResponse +} + +// Validate ... +func (c FeatureSupportClient) Validate(ctx context.Context, id LocationId, input FeatureSupportRequest) (result ValidateOperationResponse, err error) { + req, err := c.preparerForValidate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "featuresupport.FeatureSupportClient", "Validate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "featuresupport.FeatureSupportClient", "Validate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForValidate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "featuresupport.FeatureSupportClient", "Validate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForValidate prepares the Validate request. +func (c FeatureSupportClient) preparerForValidate(ctx context.Context, id LocationId, input FeatureSupportRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupValidateFeatures", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForValidate handles the response to the Validate request. The method always +// closes the http.Response Body. +func (c FeatureSupportClient) responderForValidate(resp *http.Response) (result ValidateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurebackupgoalfeaturesupportrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurebackupgoalfeaturesupportrequest.go new file mode 100644 index 00000000000..3d2bf051bd9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurebackupgoalfeaturesupportrequest.go @@ -0,0 +1,40 @@ +package featuresupport + +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 _ FeatureSupportRequest = AzureBackupGoalFeatureSupportRequest{} + +type AzureBackupGoalFeatureSupportRequest struct { + + // Fields inherited from FeatureSupportRequest +} + +var _ json.Marshaler = AzureBackupGoalFeatureSupportRequest{} + +func (s AzureBackupGoalFeatureSupportRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupGoalFeatureSupportRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupGoalFeatureSupportRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupGoalFeatureSupportRequest: %+v", err) + } + decoded["featureType"] = "AzureBackupGoals" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupGoalFeatureSupportRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurevmresourcefeaturesupportrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurevmresourcefeaturesupportrequest.go new file mode 100644 index 00000000000..b9e212a5b30 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurevmresourcefeaturesupportrequest.go @@ -0,0 +1,42 @@ +package featuresupport + +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 _ FeatureSupportRequest = AzureVMResourceFeatureSupportRequest{} + +type AzureVMResourceFeatureSupportRequest struct { + VMSize *string `json:"vmSize,omitempty"` + VMSku *string `json:"vmSku,omitempty"` + + // Fields inherited from FeatureSupportRequest +} + +var _ json.Marshaler = AzureVMResourceFeatureSupportRequest{} + +func (s AzureVMResourceFeatureSupportRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureVMResourceFeatureSupportRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMResourceFeatureSupportRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMResourceFeatureSupportRequest: %+v", err) + } + decoded["featureType"] = "AzureVMResourceBackup" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMResourceFeatureSupportRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurevmresourcefeaturesupportresponse.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurevmresourcefeaturesupportresponse.go new file mode 100644 index 00000000000..b9d8a42e54a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_azurevmresourcefeaturesupportresponse.go @@ -0,0 +1,8 @@ +package featuresupport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureVMResourceFeatureSupportResponse struct { + SupportStatus *SupportStatus `json:"supportStatus,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_featuresupportrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_featuresupportrequest.go new file mode 100644 index 00000000000..d854f7980de --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/model_featuresupportrequest.go @@ -0,0 +1,56 @@ +package featuresupport + +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 FeatureSupportRequest interface { +} + +func unmarshalFeatureSupportRequestImplementation(input []byte) (FeatureSupportRequest, 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 FeatureSupportRequest into map[string]interface: %+v", err) + } + + value, ok := temp["featureType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupGoals") { + var out AzureBackupGoalFeatureSupportRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupGoalFeatureSupportRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVMResourceBackup") { + var out AzureVMResourceFeatureSupportRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMResourceFeatureSupportRequest: %+v", err) + } + return out, nil + } + + type RawFeatureSupportRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawFeatureSupportRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/version.go new file mode 100644 index 00000000000..daa2a27b63e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/featuresupport/version.go @@ -0,0 +1,12 @@ +package featuresupport + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/featuresupport/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/README.md new file mode 100644 index 00000000000..59704ab313a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections` Documentation + +The `itemlevelrecoveryconnections` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections" +``` + + +### Client Initialization + +```go +client := itemlevelrecoveryconnections.NewItemLevelRecoveryConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ItemLevelRecoveryConnectionsClient.Provision` + +```go +ctx := context.TODO() +id := itemlevelrecoveryconnections.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue") + +payload := itemlevelrecoveryconnections.ILRRequestResource{ + // ... +} + + +read, err := client.Provision(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ItemLevelRecoveryConnectionsClient.Revoke` + +```go +ctx := context.TODO() +id := itemlevelrecoveryconnections.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue") + +read, err := client.Revoke(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/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/client.go new file mode 100644 index 00000000000..9dc4e42e08b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/client.go @@ -0,0 +1,18 @@ +package itemlevelrecoveryconnections + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ItemLevelRecoveryConnectionsClient struct { + Client autorest.Client + baseUri string +} + +func NewItemLevelRecoveryConnectionsClientWithBaseURI(endpoint string) ItemLevelRecoveryConnectionsClient { + return ItemLevelRecoveryConnectionsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/id_recoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/id_recoverypoint.go new file mode 100644 index 00000000000..9e27ce800cf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/id_recoverypoint.go @@ -0,0 +1,179 @@ +package itemlevelrecoveryconnections + +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 + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string + RecoveryPointId string +} + +// NewRecoveryPointID returns a new RecoveryPointId struct +func NewRecoveryPointID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string, recoveryPointId string) RecoveryPointId { + return RecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s/recoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName, 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + fmt.Sprintf("Recovery Point: %q", id.RecoveryPointId), + } + return fmt.Sprintf("Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/id_recoverypoint_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/id_recoverypoint_test.go new file mode 100644 index 00000000000..e7a1a81007c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/id_recoverypoint_test.go @@ -0,0 +1,462 @@ +package itemlevelrecoveryconnections + +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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } + + 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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS/rEcOvErYpOiNtIdVaLuE", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/method_provision_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/method_provision_autorest.go new file mode 100644 index 00000000000..9d96e89f2fd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/method_provision_autorest.go @@ -0,0 +1,68 @@ +package itemlevelrecoveryconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisionOperationResponse struct { + HttpResponse *http.Response +} + +// Provision ... +func (c ItemLevelRecoveryConnectionsClient) Provision(ctx context.Context, id RecoveryPointId, input ILRRequestResource) (result ProvisionOperationResponse, err error) { + req, err := c.preparerForProvision(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "itemlevelrecoveryconnections.ItemLevelRecoveryConnectionsClient", "Provision", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "itemlevelrecoveryconnections.ItemLevelRecoveryConnectionsClient", "Provision", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForProvision(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "itemlevelrecoveryconnections.ItemLevelRecoveryConnectionsClient", "Provision", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForProvision prepares the Provision request. +func (c ItemLevelRecoveryConnectionsClient) preparerForProvision(ctx context.Context, id RecoveryPointId, input ILRRequestResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/provisionInstantItemRecovery", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForProvision handles the response to the Provision request. The method always +// closes the http.Response Body. +func (c ItemLevelRecoveryConnectionsClient) responderForProvision(resp *http.Response) (result ProvisionOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/method_revoke_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/method_revoke_autorest.go new file mode 100644 index 00000000000..9ea351e638d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/method_revoke_autorest.go @@ -0,0 +1,67 @@ +package itemlevelrecoveryconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RevokeOperationResponse struct { + HttpResponse *http.Response +} + +// Revoke ... +func (c ItemLevelRecoveryConnectionsClient) Revoke(ctx context.Context, id RecoveryPointId) (result RevokeOperationResponse, err error) { + req, err := c.preparerForRevoke(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "itemlevelrecoveryconnections.ItemLevelRecoveryConnectionsClient", "Revoke", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "itemlevelrecoveryconnections.ItemLevelRecoveryConnectionsClient", "Revoke", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForRevoke(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "itemlevelrecoveryconnections.ItemLevelRecoveryConnectionsClient", "Revoke", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForRevoke prepares the Revoke request. +func (c ItemLevelRecoveryConnectionsClient) preparerForRevoke(ctx context.Context, id RecoveryPointId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/revokeInstantItemRecovery", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForRevoke handles the response to the Revoke request. The method always +// closes the http.Response Body. +func (c ItemLevelRecoveryConnectionsClient) responderForRevoke(resp *http.Response) (result RevokeOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_azurefileshareprovisionilrrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_azurefileshareprovisionilrrequest.go new file mode 100644 index 00000000000..d93f105af7a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_azurefileshareprovisionilrrequest.go @@ -0,0 +1,42 @@ +package itemlevelrecoveryconnections + +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 _ ILRRequest = AzureFileShareProvisionILRRequest{} + +type AzureFileShareProvisionILRRequest struct { + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + + // Fields inherited from ILRRequest +} + +var _ json.Marshaler = AzureFileShareProvisionILRRequest{} + +func (s AzureFileShareProvisionILRRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareProvisionILRRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareProvisionILRRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareProvisionILRRequest: %+v", err) + } + decoded["objectType"] = "AzureFileShareProvisionILRRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareProvisionILRRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_iaasvmilrregistrationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_iaasvmilrregistrationrequest.go new file mode 100644 index 00000000000..87056a3101b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_iaasvmilrregistrationrequest.go @@ -0,0 +1,44 @@ +package itemlevelrecoveryconnections + +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 _ ILRRequest = IaasVMILRRegistrationRequest{} + +type IaasVMILRRegistrationRequest struct { + InitiatorName *string `json:"initiatorName,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RenewExistingRegistration *bool `json:"renewExistingRegistration,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + + // Fields inherited from ILRRequest +} + +var _ json.Marshaler = IaasVMILRRegistrationRequest{} + +func (s IaasVMILRRegistrationRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMILRRegistrationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMILRRegistrationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMILRRegistrationRequest: %+v", err) + } + decoded["objectType"] = "IaasVMILRRegistrationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMILRRegistrationRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_ilrrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_ilrrequest.go new file mode 100644 index 00000000000..3cc4ab320e0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_ilrrequest.go @@ -0,0 +1,56 @@ +package itemlevelrecoveryconnections + +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 ILRRequest interface { +} + +func unmarshalILRRequestImplementation(input []byte) (ILRRequest, 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 ILRRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareProvisionILRRequest") { + var out AzureFileShareProvisionILRRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareProvisionILRRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMILRRegistrationRequest") { + var out IaasVMILRRegistrationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMILRRegistrationRequest: %+v", err) + } + return out, nil + } + + type RawILRRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawILRRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_ilrrequestresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_ilrrequestresource.go new file mode 100644 index 00000000000..b9b0865a658 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/model_ilrrequestresource.go @@ -0,0 +1,50 @@ +package itemlevelrecoveryconnections + +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 ILRRequestResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ILRRequest `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ILRRequestResource{} + +func (s *ILRRequestResource) UnmarshalJSON(bytes []byte) error { + type alias ILRRequestResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ILRRequestResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ILRRequestResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalILRRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ILRRequestResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/version.go new file mode 100644 index 00000000000..c913f2f5cfd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/itemlevelrecoveryconnections/version.go @@ -0,0 +1,12 @@ +package itemlevelrecoveryconnections + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/itemlevelrecoveryconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/client.go new file mode 100644 index 00000000000..00a3fc2ea01 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/client.go @@ -0,0 +1,18 @@ +package jobcancellations + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobCancellationsClient struct { + Client autorest.Client + baseUri string +} + +func NewJobCancellationsClientWithBaseURI(endpoint string) JobCancellationsClient { + return JobCancellationsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/id_backupjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/id_backupjob.go new file mode 100644 index 00000000000..0267b662949 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/id_backupjob.go @@ -0,0 +1,140 @@ +package jobcancellations + +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 + VaultName string + BackupJobName string +} + +// NewBackupJobID returns a new BackupJobId struct +func NewBackupJobID(subscriptionId string, resourceGroupName string, vaultName string, backupJobName string) BackupJobId { + return BackupJobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupJobName: backupJobName, + } +} + +// 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) + } + + var ok bool + id := BackupJobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupJobName, ok = parsed.Parsed["backupJobName"]; !ok { + return nil, fmt.Errorf("the segment 'backupJobName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := BackupJobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupJobName, ok = parsed.Parsed["backupJobName"]; !ok { + return nil, fmt.Errorf("the segment 'backupJobName' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupJobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupJobName) +} + +// 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupJobs", "backupJobs", "backupJobs"), + resourceids.UserSpecifiedSegment("backupJobName", "backupJobValue"), + } +} + +// 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Job Name: %q", id.BackupJobName), + } + return fmt.Sprintf("Backup Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/id_backupjob_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/id_backupjob_test.go new file mode 100644 index 00000000000..852e463244e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/id_backupjob_test.go @@ -0,0 +1,327 @@ +package jobcancellations + +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", "vaultValue", "backupJobValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupJobName != "backupJobValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupJobName'", id.BackupJobName, "backupJobValue") + } +} + +func TestFormatBackupJobID(t *testing.T) { + actual := NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupJobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue" + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupJobName: "backupJobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupJobName != v.Expected.BackupJobName { + t.Fatalf("Expected %q but got %q for BackupJobName", v.Expected.BackupJobName, actual.BackupJobName) + } + + } +} + +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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPjObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupJobName: "backupJobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPjObS/bAcKuPjObVaLuE", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupJobName: "bAcKuPjObVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPjObS/bAcKuPjObVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupJobName != v.Expected.BackupJobName { + t.Fatalf("Expected %q but got %q for BackupJobName", v.Expected.BackupJobName, actual.BackupJobName) + } + + } +} + +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/recoveryservicesbackup/2023-02-01/jobcancellations/method_trigger_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/method_trigger_autorest.go new file mode 100644 index 00000000000..9159d1476cb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/method_trigger_autorest.go @@ -0,0 +1,67 @@ +package jobcancellations + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerOperationResponse struct { + HttpResponse *http.Response +} + +// Trigger ... +func (c JobCancellationsClient) Trigger(ctx context.Context, id BackupJobId) (result TriggerOperationResponse, err error) { + req, err := c.preparerForTrigger(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "jobcancellations.JobCancellationsClient", "Trigger", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "jobcancellations.JobCancellationsClient", "Trigger", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForTrigger(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "jobcancellations.JobCancellationsClient", "Trigger", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForTrigger prepares the Trigger request. +func (c JobCancellationsClient) preparerForTrigger(ctx context.Context, id BackupJobId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/cancel", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForTrigger handles the response to the Trigger request. The method always +// closes the http.Response Body. +func (c JobCancellationsClient) responderForTrigger(resp *http.Response) (result TriggerOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/version.go new file mode 100644 index 00000000000..84b22964dc1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobcancellations/version.go @@ -0,0 +1,12 @@ +package jobcancellations + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobcancellations/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/README.md new file mode 100644 index 00000000000..8903da4aeee --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails` Documentation + +The `jobdetails` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/jobdetails" +``` + + +### Client Initialization + +```go +client := jobdetails.NewJobDetailsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobDetailsClient.Get` + +```go +ctx := context.TODO() +id := jobdetails.NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupJobValue") + +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 +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/client.go new file mode 100644 index 00000000000..465d9e82eba --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/client.go @@ -0,0 +1,18 @@ +package jobdetails + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobDetailsClient struct { + Client autorest.Client + baseUri string +} + +func NewJobDetailsClientWithBaseURI(endpoint string) JobDetailsClient { + return JobDetailsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/constants.go new file mode 100644 index 00000000000..a94046a0140 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/constants.go @@ -0,0 +1,223 @@ +package jobdetails + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type JobSupportedAction string + +const ( + JobSupportedActionCancellable JobSupportedAction = "Cancellable" + JobSupportedActionInvalid JobSupportedAction = "Invalid" + JobSupportedActionRetriable JobSupportedAction = "Retriable" +) + +func PossibleValuesForJobSupportedAction() []string { + return []string{ + string(JobSupportedActionCancellable), + string(JobSupportedActionInvalid), + string(JobSupportedActionRetriable), + } +} + +func parseJobSupportedAction(input string) (*JobSupportedAction, error) { + vals := map[string]JobSupportedAction{ + "cancellable": JobSupportedActionCancellable, + "invalid": JobSupportedActionInvalid, + "retriable": JobSupportedActionRetriable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobSupportedAction(input) + return &out, nil +} + +type MabServerType string + +const ( + MabServerTypeAzureBackupServerContainer MabServerType = "AzureBackupServerContainer" + MabServerTypeAzureSqlContainer MabServerType = "AzureSqlContainer" + MabServerTypeCluster MabServerType = "Cluster" + MabServerTypeDPMContainer MabServerType = "DPMContainer" + MabServerTypeGenericContainer MabServerType = "GenericContainer" + MabServerTypeIaasVMContainer MabServerType = "IaasVMContainer" + MabServerTypeIaasVMServiceContainer MabServerType = "IaasVMServiceContainer" + MabServerTypeInvalid MabServerType = "Invalid" + MabServerTypeMABContainer MabServerType = "MABContainer" + MabServerTypeSQLAGWorkLoadContainer MabServerType = "SQLAGWorkLoadContainer" + MabServerTypeStorageContainer MabServerType = "StorageContainer" + MabServerTypeUnknown MabServerType = "Unknown" + MabServerTypeVCenter MabServerType = "VCenter" + MabServerTypeVMAppContainer MabServerType = "VMAppContainer" + MabServerTypeWindows MabServerType = "Windows" +) + +func PossibleValuesForMabServerType() []string { + return []string{ + string(MabServerTypeAzureBackupServerContainer), + string(MabServerTypeAzureSqlContainer), + string(MabServerTypeCluster), + string(MabServerTypeDPMContainer), + string(MabServerTypeGenericContainer), + string(MabServerTypeIaasVMContainer), + string(MabServerTypeIaasVMServiceContainer), + string(MabServerTypeInvalid), + string(MabServerTypeMABContainer), + string(MabServerTypeSQLAGWorkLoadContainer), + string(MabServerTypeStorageContainer), + string(MabServerTypeUnknown), + string(MabServerTypeVCenter), + string(MabServerTypeVMAppContainer), + string(MabServerTypeWindows), + } +} + +func parseMabServerType(input string) (*MabServerType, error) { + vals := map[string]MabServerType{ + "azurebackupservercontainer": MabServerTypeAzureBackupServerContainer, + "azuresqlcontainer": MabServerTypeAzureSqlContainer, + "cluster": MabServerTypeCluster, + "dpmcontainer": MabServerTypeDPMContainer, + "genericcontainer": MabServerTypeGenericContainer, + "iaasvmcontainer": MabServerTypeIaasVMContainer, + "iaasvmservicecontainer": MabServerTypeIaasVMServiceContainer, + "invalid": MabServerTypeInvalid, + "mabcontainer": MabServerTypeMABContainer, + "sqlagworkloadcontainer": MabServerTypeSQLAGWorkLoadContainer, + "storagecontainer": MabServerTypeStorageContainer, + "unknown": MabServerTypeUnknown, + "vcenter": MabServerTypeVCenter, + "vmappcontainer": MabServerTypeVMAppContainer, + "windows": MabServerTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MabServerType(input) + return &out, nil +} + +type WorkloadType string + +const ( + WorkloadTypeAzureFileShare WorkloadType = "AzureFileShare" + WorkloadTypeAzureSqlDb WorkloadType = "AzureSqlDb" + WorkloadTypeClient WorkloadType = "Client" + WorkloadTypeExchange WorkloadType = "Exchange" + WorkloadTypeFileFolder WorkloadType = "FileFolder" + WorkloadTypeGenericDataSource WorkloadType = "GenericDataSource" + WorkloadTypeInvalid WorkloadType = "Invalid" + WorkloadTypeSAPAseDatabase WorkloadType = "SAPAseDatabase" + WorkloadTypeSAPHanaDBInstance WorkloadType = "SAPHanaDBInstance" + WorkloadTypeSAPHanaDatabase WorkloadType = "SAPHanaDatabase" + WorkloadTypeSQLDB WorkloadType = "SQLDB" + WorkloadTypeSQLDataBase WorkloadType = "SQLDataBase" + WorkloadTypeSharepoint WorkloadType = "Sharepoint" + WorkloadTypeSystemState WorkloadType = "SystemState" + WorkloadTypeVM WorkloadType = "VM" + WorkloadTypeVMwareVM WorkloadType = "VMwareVM" +) + +func PossibleValuesForWorkloadType() []string { + return []string{ + string(WorkloadTypeAzureFileShare), + string(WorkloadTypeAzureSqlDb), + string(WorkloadTypeClient), + string(WorkloadTypeExchange), + string(WorkloadTypeFileFolder), + string(WorkloadTypeGenericDataSource), + string(WorkloadTypeInvalid), + string(WorkloadTypeSAPAseDatabase), + string(WorkloadTypeSAPHanaDBInstance), + string(WorkloadTypeSAPHanaDatabase), + string(WorkloadTypeSQLDB), + string(WorkloadTypeSQLDataBase), + string(WorkloadTypeSharepoint), + string(WorkloadTypeSystemState), + string(WorkloadTypeVM), + string(WorkloadTypeVMwareVM), + } +} + +func parseWorkloadType(input string) (*WorkloadType, error) { + vals := map[string]WorkloadType{ + "azurefileshare": WorkloadTypeAzureFileShare, + "azuresqldb": WorkloadTypeAzureSqlDb, + "client": WorkloadTypeClient, + "exchange": WorkloadTypeExchange, + "filefolder": WorkloadTypeFileFolder, + "genericdatasource": WorkloadTypeGenericDataSource, + "invalid": WorkloadTypeInvalid, + "sapasedatabase": WorkloadTypeSAPAseDatabase, + "saphanadbinstance": WorkloadTypeSAPHanaDBInstance, + "saphanadatabase": WorkloadTypeSAPHanaDatabase, + "sqldb": WorkloadTypeSQLDB, + "sqldatabase": WorkloadTypeSQLDataBase, + "sharepoint": WorkloadTypeSharepoint, + "systemstate": WorkloadTypeSystemState, + "vm": WorkloadTypeVM, + "vmwarevm": WorkloadTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkloadType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/id_backupjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/id_backupjob.go new file mode 100644 index 00000000000..2e12ae5818c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/id_backupjob.go @@ -0,0 +1,140 @@ +package jobdetails + +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 + VaultName string + BackupJobName string +} + +// NewBackupJobID returns a new BackupJobId struct +func NewBackupJobID(subscriptionId string, resourceGroupName string, vaultName string, backupJobName string) BackupJobId { + return BackupJobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupJobName: backupJobName, + } +} + +// 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) + } + + var ok bool + id := BackupJobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupJobName, ok = parsed.Parsed["backupJobName"]; !ok { + return nil, fmt.Errorf("the segment 'backupJobName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := BackupJobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupJobName, ok = parsed.Parsed["backupJobName"]; !ok { + return nil, fmt.Errorf("the segment 'backupJobName' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupJobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupJobName) +} + +// 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupJobs", "backupJobs", "backupJobs"), + resourceids.UserSpecifiedSegment("backupJobName", "backupJobValue"), + } +} + +// 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Job Name: %q", id.BackupJobName), + } + return fmt.Sprintf("Backup Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/id_backupjob_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/id_backupjob_test.go new file mode 100644 index 00000000000..a2a02c72f92 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/id_backupjob_test.go @@ -0,0 +1,327 @@ +package jobdetails + +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", "vaultValue", "backupJobValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupJobName != "backupJobValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupJobName'", id.BackupJobName, "backupJobValue") + } +} + +func TestFormatBackupJobID(t *testing.T) { + actual := NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupJobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue" + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupJobName: "backupJobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupJobName != v.Expected.BackupJobName { + t.Fatalf("Expected %q but got %q for BackupJobName", v.Expected.BackupJobName, actual.BackupJobName) + } + + } +} + +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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPjObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupJobName: "backupJobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupJobs/backupJobValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPjObS/bAcKuPjObVaLuE", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupJobName: "bAcKuPjObVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPjObS/bAcKuPjObVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupJobName != v.Expected.BackupJobName { + t.Fatalf("Expected %q but got %q for BackupJobName", v.Expected.BackupJobName, actual.BackupJobName) + } + + } +} + +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/recoveryservicesbackup/2023-02-01/jobdetails/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/method_get_autorest.go new file mode 100644 index 00000000000..aa3589e2635 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/method_get_autorest.go @@ -0,0 +1,68 @@ +package jobdetails + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *JobResource +} + +// Get ... +func (c JobDetailsClient) Get(ctx context.Context, id BackupJobId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "jobdetails.JobDetailsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "jobdetails.JobDetailsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "jobdetails.JobDetailsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c JobDetailsClient) preparerForGet(ctx context.Context, id BackupJobId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c JobDetailsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmerrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmerrorinfo.go new file mode 100644 index 00000000000..47de469765b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmerrorinfo.go @@ -0,0 +1,11 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureIaaSVMErrorInfo struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + ErrorTitle *string `json:"errorTitle,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjob.go new file mode 100644 index 00000000000..fd829774cff --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjob.go @@ -0,0 +1,81 @@ +package jobdetails + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureIaaSVMJob{} + +type AzureIaaSVMJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureIaaSVMErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureIaaSVMJobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered *bool `json:"isUserTriggered,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureIaaSVMJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureIaaSVMJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureIaaSVMJob{} + +func (s AzureIaaSVMJob) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMJob: %+v", err) + } + decoded["jobType"] = "AzureIaaSVMJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobextendedinfo.go new file mode 100644 index 00000000000..4dba88ce53a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobextendedinfo.go @@ -0,0 +1,13 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureIaaSVMJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + EstimatedRemainingDuration *string `json:"estimatedRemainingDuration,omitempty"` + InternalPropertyBag *map[string]string `json:"internalPropertyBag,omitempty"` + ProgressPercentage *float64 `json:"progressPercentage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]AzureIaaSVMJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobtaskdetails.go new file mode 100644 index 00000000000..ae1cc624792 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobtaskdetails.go @@ -0,0 +1,45 @@ +package jobdetails + +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 AzureIaaSVMJobTaskDetails struct { + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + InstanceId *string `json:"instanceId,omitempty"` + ProgressPercentage *float64 `json:"progressPercentage,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + TaskExecutionDetails *string `json:"taskExecutionDetails,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} + +func (o *AzureIaaSVMJobTaskDetails) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobTaskDetails) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureIaaSVMJobTaskDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobTaskDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobv2.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobv2.go new file mode 100644 index 00000000000..e1c8f8a8d74 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureiaasvmjobv2.go @@ -0,0 +1,80 @@ +package jobdetails + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureIaaSVMJobV2{} + +type AzureIaaSVMJobV2 struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureIaaSVMErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureIaaSVMJobExtendedInfo `json:"extendedInfo,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureIaaSVMJobV2) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobV2) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureIaaSVMJobV2) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMJobV2) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureIaaSVMJobV2{} + +func (s AzureIaaSVMJobV2) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMJobV2 + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMJobV2: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMJobV2: %+v", err) + } + decoded["jobType"] = "AzureIaaSVMJobV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMJobV2: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestorageerrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestorageerrorinfo.go new file mode 100644 index 00000000000..28cf64eae5f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestorageerrorinfo.go @@ -0,0 +1,10 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStorageErrorInfo struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejob.go new file mode 100644 index 00000000000..ae1214a2ed0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejob.go @@ -0,0 +1,81 @@ +package jobdetails + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureStorageJob{} + +type AzureStorageJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureStorageErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureStorageJobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered *bool `json:"isUserTriggered,omitempty"` + StorageAccountName *string `json:"storageAccountName,omitempty"` + StorageAccountVersion *string `json:"storageAccountVersion,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureStorageJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureStorageJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureStorageJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureStorageJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureStorageJob{} + +func (s AzureStorageJob) MarshalJSON() ([]byte, error) { + type wrapper AzureStorageJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureStorageJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureStorageJob: %+v", err) + } + decoded["jobType"] = "AzureStorageJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureStorageJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejobextendedinfo.go new file mode 100644 index 00000000000..b687b944e42 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejobextendedinfo.go @@ -0,0 +1,10 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStorageJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]AzureStorageJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejobtaskdetails.go new file mode 100644 index 00000000000..9cc5cb916c9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azurestoragejobtaskdetails.go @@ -0,0 +1,9 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStorageJobTaskDetails struct { + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloaderrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloaderrorinfo.go new file mode 100644 index 00000000000..d54f4b2217f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloaderrorinfo.go @@ -0,0 +1,12 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadErrorInfo struct { + AdditionalDetails *string `json:"additionalDetails,omitempty"` + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + ErrorTitle *string `json:"errorTitle,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjob.go new file mode 100644 index 00000000000..90c833a0b9e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjob.go @@ -0,0 +1,79 @@ +package jobdetails + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = AzureWorkloadJob{} + +type AzureWorkloadJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]AzureWorkloadErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *AzureWorkloadJobExtendedInfo `json:"extendedInfo,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *AzureWorkloadJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureWorkloadJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureWorkloadJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureWorkloadJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = AzureWorkloadJob{} + +func (s AzureWorkloadJob) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadJob: %+v", err) + } + decoded["jobType"] = "AzureWorkloadJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjobextendedinfo.go new file mode 100644 index 00000000000..b086f0ffee5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjobextendedinfo.go @@ -0,0 +1,10 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]AzureWorkloadJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjobtaskdetails.go new file mode 100644 index 00000000000..b6d9349f0c6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_azureworkloadjobtaskdetails.go @@ -0,0 +1,9 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadJobTaskDetails struct { + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmerrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmerrorinfo.go new file mode 100644 index 00000000000..987eb3a7bcb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmerrorinfo.go @@ -0,0 +1,9 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpmErrorInfo struct { + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjob.go new file mode 100644 index 00000000000..7a18a1855d9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjob.go @@ -0,0 +1,82 @@ +package jobdetails + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = DpmJob{} + +type DpmJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + ContainerType *string `json:"containerType,omitempty"` + DpmServerName *string `json:"dpmServerName,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]DpmErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *DpmJobExtendedInfo `json:"extendedInfo,omitempty"` + WorkloadType *string `json:"workloadType,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *DpmJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *DpmJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = DpmJob{} + +func (s DpmJob) MarshalJSON() ([]byte, error) { + type wrapper DpmJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DpmJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DpmJob: %+v", err) + } + decoded["jobType"] = "DpmJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DpmJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjobextendedinfo.go new file mode 100644 index 00000000000..e06f6f2aa5e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjobextendedinfo.go @@ -0,0 +1,10 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpmJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]DpmJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjobtaskdetails.go new file mode 100644 index 00000000000..9b8583d9233 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_dpmjobtaskdetails.go @@ -0,0 +1,42 @@ +package jobdetails + +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 DpmJobTaskDetails struct { + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} + +func (o *DpmJobTaskDetails) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJobTaskDetails) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *DpmJobTaskDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DpmJobTaskDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_job.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_job.go new file mode 100644 index 00000000000..4d43300ce4e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_job.go @@ -0,0 +1,96 @@ +package jobdetails + +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 Job interface { +} + +func unmarshalJobImplementation(input []byte) (Job, 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 Job into map[string]interface: %+v", err) + } + + value, ok := temp["jobType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureIaaSVMJob") { + var out AzureIaaSVMJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureIaaSVMJobV2") { + var out AzureIaaSVMJobV2 + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMJobV2: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureStorageJob") { + var out AzureStorageJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureStorageJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadJob") { + var out AzureWorkloadJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DpmJob") { + var out DpmJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DpmJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MabJob") { + var out MabJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabJob: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VaultJob") { + var out VaultJob + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VaultJob: %+v", err) + } + return out, nil + } + + type RawJobImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawJobImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_jobresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_jobresource.go new file mode 100644 index 00000000000..5a450efbfbd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_jobresource.go @@ -0,0 +1,50 @@ +package jobdetails + +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 JobResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties Job `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &JobResource{} + +func (s *JobResource) UnmarshalJSON(bytes []byte) error { + type alias JobResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalJobImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'JobResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_maberrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_maberrorinfo.go new file mode 100644 index 00000000000..d12afd9a026 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_maberrorinfo.go @@ -0,0 +1,9 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MabErrorInfo struct { + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjob.go new file mode 100644 index 00000000000..b39dc7f470f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjob.go @@ -0,0 +1,81 @@ +package jobdetails + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = MabJob{} + +type MabJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]MabErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *MabJobExtendedInfo `json:"extendedInfo,omitempty"` + MabServerName *string `json:"mabServerName,omitempty"` + MabServerType *MabServerType `json:"mabServerType,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *MabJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *MabJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = MabJob{} + +func (s MabJob) MarshalJSON() ([]byte, error) { + type wrapper MabJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabJob: %+v", err) + } + decoded["jobType"] = "MabJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjobextendedinfo.go new file mode 100644 index 00000000000..b08829e160a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjobextendedinfo.go @@ -0,0 +1,10 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MabJobExtendedInfo struct { + DynamicErrorMessage *string `json:"dynamicErrorMessage,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + TasksList *[]MabJobTaskDetails `json:"tasksList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjobtaskdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjobtaskdetails.go new file mode 100644 index 00000000000..c923d5d3282 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_mabjobtaskdetails.go @@ -0,0 +1,42 @@ +package jobdetails + +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 MabJobTaskDetails struct { + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} + +func (o *MabJobTaskDetails) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJobTaskDetails) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *MabJobTaskDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabJobTaskDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjob.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjob.go new file mode 100644 index 00000000000..e5aef51bd7b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjob.go @@ -0,0 +1,78 @@ +package jobdetails + +import ( + "encoding/json" + "fmt" + "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. + +var _ Job = VaultJob{} + +type VaultJob struct { + ActionsInfo *[]JobSupportedAction `json:"actionsInfo,omitempty"` + Duration *string `json:"duration,omitempty"` + ErrorDetails *[]VaultJobErrorInfo `json:"errorDetails,omitempty"` + ExtendedInfo *VaultJobExtendedInfo `json:"extendedInfo,omitempty"` + + // Fields inherited from Job + ActivityId *string `json:"activityId,omitempty"` + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + EndTime *string `json:"endTime,omitempty"` + EntityFriendlyName *string `json:"entityFriendlyName,omitempty"` + Operation *string `json:"operation,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *VaultJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VaultJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *VaultJob) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VaultJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Marshaler = VaultJob{} + +func (s VaultJob) MarshalJSON() ([]byte, error) { + type wrapper VaultJob + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VaultJob: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VaultJob: %+v", err) + } + decoded["jobType"] = "VaultJob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VaultJob: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjoberrorinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjoberrorinfo.go new file mode 100644 index 00000000000..8369add63df --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjoberrorinfo.go @@ -0,0 +1,10 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultJobErrorInfo struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorString *string `json:"errorString,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjobextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjobextendedinfo.go new file mode 100644 index 00000000000..78248901487 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/model_vaultjobextendedinfo.go @@ -0,0 +1,8 @@ +package jobdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultJobExtendedInfo struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/version.go new file mode 100644 index 00000000000..7491853f927 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobdetails/version.go @@ -0,0 +1,12 @@ +package jobdetails + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobdetails/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobs/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/client.go new file mode 100644 index 00000000000..fd4e7899bb5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/client.go @@ -0,0 +1,18 @@ +package jobs + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobsClient struct { + Client autorest.Client + baseUri string +} + +func NewJobsClientWithBaseURI(endpoint string) JobsClient { + return JobsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobs/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/id_vault.go new file mode 100644 index 00000000000..e8fed4b7246 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/id_vault.go @@ -0,0 +1,127 @@ +package jobs + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobs/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/id_vault_test.go new file mode 100644 index 00000000000..89bc25cf73d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/id_vault_test.go @@ -0,0 +1,282 @@ +package jobs + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/jobs/method_export_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/method_export_autorest.go new file mode 100644 index 00000000000..d6662857fa9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/method_export_autorest.go @@ -0,0 +1,96 @@ +package jobs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportOperationResponse struct { + HttpResponse *http.Response +} + +type ExportOperationOptions struct { + Filter *string +} + +func DefaultExportOperationOptions() ExportOperationOptions { + return ExportOperationOptions{} +} + +func (o ExportOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ExportOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// Export ... +func (c JobsClient) Export(ctx context.Context, id VaultId, options ExportOperationOptions) (result ExportOperationResponse, err error) { + req, err := c.preparerForExport(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "jobs.JobsClient", "Export", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "jobs.JobsClient", "Export", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForExport(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "jobs.JobsClient", "Export", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForExport prepares the Export request. +func (c JobsClient) preparerForExport(ctx context.Context, id VaultId, options ExportOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupJobsExport", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForExport handles the response to the Export request. The method always +// closes the http.Response Body. +func (c JobsClient) responderForExport(resp *http.Response) (result ExportOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/jobs/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/version.go new file mode 100644 index 00000000000..b2ed32f52e8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/jobs/version.go @@ -0,0 +1,12 @@ +package jobs + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobs/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/operation/README.md new file mode 100644 index 00000000000..da071426845 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/operation` Documentation + +The `operation` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/operation" +``` + + +### Client Initialization + +```go +client := operation.NewOperationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OperationClient.Validate` + +```go +ctx := context.TODO() +id := operation.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := operation.ValidateOperationRequest{ + // ... +} + + +read, err := client.Validate(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/recoveryservicesbackup/2023-02-01/operation/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/client.go new file mode 100644 index 00000000000..3a57d0e0d4c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/client.go @@ -0,0 +1,18 @@ +package operation + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationClient struct { + Client autorest.Client + baseUri string +} + +func NewOperationClientWithBaseURI(endpoint string) OperationClient { + return OperationClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/constants.go new file mode 100644 index 00000000000..fe9c03dc6bf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/constants.go @@ -0,0 +1,263 @@ +package operation + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CopyOptions string + +const ( + CopyOptionsCreateCopy CopyOptions = "CreateCopy" + CopyOptionsFailOnConflict CopyOptions = "FailOnConflict" + CopyOptionsInvalid CopyOptions = "Invalid" + CopyOptionsOverwrite CopyOptions = "Overwrite" + CopyOptionsSkip CopyOptions = "Skip" +) + +func PossibleValuesForCopyOptions() []string { + return []string{ + string(CopyOptionsCreateCopy), + string(CopyOptionsFailOnConflict), + string(CopyOptionsInvalid), + string(CopyOptionsOverwrite), + string(CopyOptionsSkip), + } +} + +func parseCopyOptions(input string) (*CopyOptions, error) { + vals := map[string]CopyOptions{ + "createcopy": CopyOptionsCreateCopy, + "failonconflict": CopyOptionsFailOnConflict, + "invalid": CopyOptionsInvalid, + "overwrite": CopyOptionsOverwrite, + "skip": CopyOptionsSkip, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CopyOptions(input) + return &out, nil +} + +type OverwriteOptions string + +const ( + OverwriteOptionsFailOnConflict OverwriteOptions = "FailOnConflict" + OverwriteOptionsInvalid OverwriteOptions = "Invalid" + OverwriteOptionsOverwrite OverwriteOptions = "Overwrite" +) + +func PossibleValuesForOverwriteOptions() []string { + return []string{ + string(OverwriteOptionsFailOnConflict), + string(OverwriteOptionsInvalid), + string(OverwriteOptionsOverwrite), + } +} + +func parseOverwriteOptions(input string) (*OverwriteOptions, error) { + vals := map[string]OverwriteOptions{ + "failonconflict": OverwriteOptionsFailOnConflict, + "invalid": OverwriteOptionsInvalid, + "overwrite": OverwriteOptionsOverwrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OverwriteOptions(input) + return &out, nil +} + +type RecoveryMode string + +const ( + RecoveryModeFileRecovery RecoveryMode = "FileRecovery" + RecoveryModeInvalid RecoveryMode = "Invalid" + RecoveryModeWorkloadRecovery RecoveryMode = "WorkloadRecovery" +) + +func PossibleValuesForRecoveryMode() []string { + return []string{ + string(RecoveryModeFileRecovery), + string(RecoveryModeInvalid), + string(RecoveryModeWorkloadRecovery), + } +} + +func parseRecoveryMode(input string) (*RecoveryMode, error) { + vals := map[string]RecoveryMode{ + "filerecovery": RecoveryModeFileRecovery, + "invalid": RecoveryModeInvalid, + "workloadrecovery": RecoveryModeWorkloadRecovery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryMode(input) + return &out, nil +} + +type RecoveryType string + +const ( + RecoveryTypeAlternateLocation RecoveryType = "AlternateLocation" + RecoveryTypeInvalid RecoveryType = "Invalid" + RecoveryTypeOffline RecoveryType = "Offline" + RecoveryTypeOriginalLocation RecoveryType = "OriginalLocation" + RecoveryTypeRestoreDisks RecoveryType = "RestoreDisks" +) + +func PossibleValuesForRecoveryType() []string { + return []string{ + string(RecoveryTypeAlternateLocation), + string(RecoveryTypeInvalid), + string(RecoveryTypeOffline), + string(RecoveryTypeOriginalLocation), + string(RecoveryTypeRestoreDisks), + } +} + +func parseRecoveryType(input string) (*RecoveryType, error) { + vals := map[string]RecoveryType{ + "alternatelocation": RecoveryTypeAlternateLocation, + "invalid": RecoveryTypeInvalid, + "offline": RecoveryTypeOffline, + "originallocation": RecoveryTypeOriginalLocation, + "restoredisks": RecoveryTypeRestoreDisks, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryType(input) + return &out, nil +} + +type RehydrationPriority string + +const ( + RehydrationPriorityHigh RehydrationPriority = "High" + RehydrationPriorityStandard RehydrationPriority = "Standard" +) + +func PossibleValuesForRehydrationPriority() []string { + return []string{ + string(RehydrationPriorityHigh), + string(RehydrationPriorityStandard), + } +} + +func parseRehydrationPriority(input string) (*RehydrationPriority, error) { + vals := map[string]RehydrationPriority{ + "high": RehydrationPriorityHigh, + "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 RestoreRequestType string + +const ( + RestoreRequestTypeFullShareRestore RestoreRequestType = "FullShareRestore" + RestoreRequestTypeInvalid RestoreRequestType = "Invalid" + RestoreRequestTypeItemLevelRestore RestoreRequestType = "ItemLevelRestore" +) + +func PossibleValuesForRestoreRequestType() []string { + return []string{ + string(RestoreRequestTypeFullShareRestore), + string(RestoreRequestTypeInvalid), + string(RestoreRequestTypeItemLevelRestore), + } +} + +func parseRestoreRequestType(input string) (*RestoreRequestType, error) { + vals := map[string]RestoreRequestType{ + "fullsharerestore": RestoreRequestTypeFullShareRestore, + "invalid": RestoreRequestTypeInvalid, + "itemlevelrestore": RestoreRequestTypeItemLevelRestore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestoreRequestType(input) + return &out, nil +} + +type SQLDataDirectoryType string + +const ( + SQLDataDirectoryTypeData SQLDataDirectoryType = "Data" + SQLDataDirectoryTypeInvalid SQLDataDirectoryType = "Invalid" + SQLDataDirectoryTypeLog SQLDataDirectoryType = "Log" +) + +func PossibleValuesForSQLDataDirectoryType() []string { + return []string{ + string(SQLDataDirectoryTypeData), + string(SQLDataDirectoryTypeInvalid), + string(SQLDataDirectoryTypeLog), + } +} + +func parseSQLDataDirectoryType(input string) (*SQLDataDirectoryType, error) { + vals := map[string]SQLDataDirectoryType{ + "data": SQLDataDirectoryTypeData, + "invalid": SQLDataDirectoryTypeInvalid, + "log": SQLDataDirectoryTypeLog, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SQLDataDirectoryType(input) + return &out, nil +} + +type TargetDiskNetworkAccessOption string + +const ( + TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks TargetDiskNetworkAccessOption = "EnablePrivateAccessForAllDisks" + TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks TargetDiskNetworkAccessOption = "EnablePublicAccessForAllDisks" + TargetDiskNetworkAccessOptionSameAsOnSourceDisks TargetDiskNetworkAccessOption = "SameAsOnSourceDisks" +) + +func PossibleValuesForTargetDiskNetworkAccessOption() []string { + return []string{ + string(TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks), + string(TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks), + string(TargetDiskNetworkAccessOptionSameAsOnSourceDisks), + } +} + +func parseTargetDiskNetworkAccessOption(input string) (*TargetDiskNetworkAccessOption, error) { + vals := map[string]TargetDiskNetworkAccessOption{ + "enableprivateaccessforalldisks": TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks, + "enablepublicaccessforalldisks": TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks, + "sameasonsourcedisks": TargetDiskNetworkAccessOptionSameAsOnSourceDisks, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TargetDiskNetworkAccessOption(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/id_vault.go new file mode 100644 index 00000000000..7d72e96d995 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/id_vault.go @@ -0,0 +1,127 @@ +package operation + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/id_vault_test.go new file mode 100644 index 00000000000..f5fe55c20c9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/id_vault_test.go @@ -0,0 +1,282 @@ +package operation + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/operation/method_validate_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/method_validate_autorest.go new file mode 100644 index 00000000000..6924adebc11 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/method_validate_autorest.go @@ -0,0 +1,70 @@ +package operation + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateOperationApiResponse struct { + HttpResponse *http.Response + Model *ValidateOperationsResponse +} + +// Validate ... +func (c OperationClient) Validate(ctx context.Context, id VaultId, input ValidateOperationRequest) (result ValidateOperationApiResponse, err error) { + req, err := c.preparerForValidate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "operation.OperationClient", "Validate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operation.OperationClient", "Validate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForValidate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operation.OperationClient", "Validate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForValidate prepares the Validate request. +func (c OperationClient) preparerForValidate(ctx context.Context, id VaultId, input ValidateOperationRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupValidateOperation", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForValidate handles the response to the Validate request. The method always +// closes the http.Response Body. +func (c OperationClient) responderForValidate(resp *http.Response) (result ValidateOperationApiResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azurefilesharerestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azurefilesharerestorerequest.go new file mode 100644 index 00000000000..514f189931b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azurefilesharerestorerequest.go @@ -0,0 +1,46 @@ +package operation + +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 _ RestoreRequest = AzureFileShareRestoreRequest{} + +type AzureFileShareRestoreRequest struct { + CopyOptions *CopyOptions `json:"copyOptions,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + RestoreFileSpecs *[]RestoreFileSpecs `json:"restoreFileSpecs,omitempty"` + RestoreRequestType *RestoreRequestType `json:"restoreRequestType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetDetails *TargetAFSRestoreInfo `json:"targetDetails,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureFileShareRestoreRequest{} + +func (s AzureFileShareRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureFileShareRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadpointintimerestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadpointintimerestorerequest.go new file mode 100644 index 00000000000..4970924f286 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadpointintimerestorerequest.go @@ -0,0 +1,47 @@ +package operation + +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 _ RestoreRequest = AzureWorkloadPointInTimeRestoreRequest{} + +type AzureWorkloadPointInTimeRestoreRequest struct { + PointInTime *string `json:"pointInTime,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadPointInTimeRestoreRequest{} + +func (s AzureWorkloadPointInTimeRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadPointInTimeRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadPointInTimeRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadrestorerequest.go new file mode 100644 index 00000000000..ca703e2ebf7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadrestorerequest.go @@ -0,0 +1,46 @@ +package operation + +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 _ RestoreRequest = AzureWorkloadRestoreRequest{} + +type AzureWorkloadRestoreRequest struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadRestoreRequest{} + +func (s AzureWorkloadRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadsaphanarestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadsaphanarestorerequest.go new file mode 100644 index 00000000000..fc7e9075434 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadsaphanarestorerequest.go @@ -0,0 +1,46 @@ +package operation + +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 _ RestoreRequest = AzureWorkloadSAPHanaRestoreRequest{} + +type AzureWorkloadSAPHanaRestoreRequest struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadSAPHanaRestoreRequest{} + +func (s AzureWorkloadSAPHanaRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSAPHanaRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSAPHanaRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadsqlrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadsqlrestorerequest.go new file mode 100644 index 00000000000..58b60d6a325 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_azureworkloadsqlrestorerequest.go @@ -0,0 +1,49 @@ +package operation + +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 _ RestoreRequest = AzureWorkloadSQLRestoreRequest{} + +type AzureWorkloadSQLRestoreRequest struct { + AlternateDirectoryPaths *[]SQLDataDirectoryMapping `json:"alternateDirectoryPaths,omitempty"` + IsNonRecoverable *bool `json:"isNonRecoverable,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + ShouldUseAlternateTargetLocation *bool `json:"shouldUseAlternateTargetLocation,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadSQLRestoreRequest{} + +func (s AzureWorkloadSQLRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSQLRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSQLRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_encryptiondetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_encryptiondetails.go new file mode 100644 index 00000000000..64f3372dbd2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_encryptiondetails.go @@ -0,0 +1,12 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionDetails struct { + EncryptionEnabled *bool `json:"encryptionEnabled,omitempty"` + KekUrl *string `json:"kekUrl,omitempty"` + KekVaultId *string `json:"kekVaultId,omitempty"` + SecretKeyUrl *string `json:"secretKeyUrl,omitempty"` + SecretKeyVaultId *string `json:"secretKeyVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_errordetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_errordetail.go new file mode 100644 index 00000000000..2c609c87024 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_errordetail.go @@ -0,0 +1,10 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_extendedlocation.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_extendedlocation.go new file mode 100644 index 00000000000..42ab6a6a9d4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_extendedlocation.go @@ -0,0 +1,9 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_iaasvmrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_iaasvmrestorerequest.go new file mode 100644 index 00000000000..373a26215f3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_iaasvmrestorerequest.go @@ -0,0 +1,65 @@ +package operation + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreRequest = IaasVMRestoreRequest{} + +type IaasVMRestoreRequest struct { + AffinityGroup *string `json:"affinityGroup,omitempty"` + CreateNewCloudService *bool `json:"createNewCloudService,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + EncryptionDetails *EncryptionDetails `json:"encryptionDetails,omitempty"` + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + IdentityBasedRestoreDetails *IdentityBasedRestoreDetails `json:"identityBasedRestoreDetails,omitempty"` + IdentityInfo *IdentityInfo `json:"identityInfo,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + Region *string `json:"region,omitempty"` + RestoreDiskLunList *[]int64 `json:"restoreDiskLunList,omitempty"` + RestoreWithManagedDisks *bool `json:"restoreWithManagedDisks,omitempty"` + SecuredVMDetails *SecuredVMDetails `json:"securedVMDetails,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TargetDiskNetworkAccessSettings *TargetDiskNetworkAccessSettings `json:"targetDiskNetworkAccessSettings,omitempty"` + TargetDomainNameId *string `json:"targetDomainNameId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + VirtualNetworkId *string `json:"virtualNetworkId,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = IaasVMRestoreRequest{} + +func (s IaasVMRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRestoreRequest: %+v", err) + } + decoded["objectType"] = "IaasVMRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_iaasvmrestorewithrehydrationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_iaasvmrestorewithrehydrationrequest.go new file mode 100644 index 00000000000..88a76804099 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_iaasvmrestorewithrehydrationrequest.go @@ -0,0 +1,66 @@ +package operation + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreRequest = IaasVMRestoreWithRehydrationRequest{} + +type IaasVMRestoreWithRehydrationRequest struct { + AffinityGroup *string `json:"affinityGroup,omitempty"` + CreateNewCloudService *bool `json:"createNewCloudService,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + EncryptionDetails *EncryptionDetails `json:"encryptionDetails,omitempty"` + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + IdentityBasedRestoreDetails *IdentityBasedRestoreDetails `json:"identityBasedRestoreDetails,omitempty"` + IdentityInfo *IdentityInfo `json:"identityInfo,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointRehydrationInfo *RecoveryPointRehydrationInfo `json:"recoveryPointRehydrationInfo,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + Region *string `json:"region,omitempty"` + RestoreDiskLunList *[]int64 `json:"restoreDiskLunList,omitempty"` + RestoreWithManagedDisks *bool `json:"restoreWithManagedDisks,omitempty"` + SecuredVMDetails *SecuredVMDetails `json:"securedVMDetails,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TargetDiskNetworkAccessSettings *TargetDiskNetworkAccessSettings `json:"targetDiskNetworkAccessSettings,omitempty"` + TargetDomainNameId *string `json:"targetDomainNameId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + VirtualNetworkId *string `json:"virtualNetworkId,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = IaasVMRestoreWithRehydrationRequest{} + +func (s IaasVMRestoreWithRehydrationRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRestoreWithRehydrationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + decoded["objectType"] = "IaasVMRestoreWithRehydrationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_identitybasedrestoredetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_identitybasedrestoredetails.go new file mode 100644 index 00000000000..dd5d66a7e1c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_identitybasedrestoredetails.go @@ -0,0 +1,9 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityBasedRestoreDetails struct { + ObjectType *string `json:"objectType,omitempty"` + TargetStorageAccountId *string `json:"targetStorageAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_identityinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_identityinfo.go new file mode 100644 index 00000000000..e6971151557 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_identityinfo.go @@ -0,0 +1,9 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityInfo struct { + IsSystemAssignedIdentity *bool `json:"isSystemAssignedIdentity,omitempty"` + ManagedIdentityResourceId *string `json:"managedIdentityResourceId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_recoverypointrehydrationinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_recoverypointrehydrationinfo.go new file mode 100644 index 00000000000..d5d028a3fe7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_recoverypointrehydrationinfo.go @@ -0,0 +1,9 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointRehydrationInfo struct { + RehydrationPriority *RehydrationPriority `json:"rehydrationPriority,omitempty"` + RehydrationRetentionDuration *string `json:"rehydrationRetentionDuration,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_restorefilespecs.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_restorefilespecs.go new file mode 100644 index 00000000000..74e8852a5f7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_restorefilespecs.go @@ -0,0 +1,10 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestoreFileSpecs struct { + FileSpecType *string `json:"fileSpecType,omitempty"` + Path *string `json:"path,omitempty"` + TargetFolderPath *string `json:"targetFolderPath,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_restorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_restorerequest.go new file mode 100644 index 00000000000..f4fae05a325 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_restorerequest.go @@ -0,0 +1,96 @@ +package operation + +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 RestoreRequest interface { +} + +func unmarshalRestoreRequestImplementation(input []byte) (RestoreRequest, 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 RestoreRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareRestoreRequest") { + var out AzureFileShareRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadPointInTimeRestoreRequest") { + var out AzureWorkloadPointInTimeRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadRestoreRequest") { + var out AzureWorkloadRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSAPHanaRestoreRequest") { + var out AzureWorkloadSAPHanaRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSQLRestoreRequest") { + var out AzureWorkloadSQLRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSQLRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRestoreRequest") { + var out IaasVMRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRestoreWithRehydrationRequest") { + var out IaasVMRestoreWithRehydrationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRestoreWithRehydrationRequest: %+v", err) + } + return out, nil + } + + type RawRestoreRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRestoreRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_securedvmdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_securedvmdetails.go new file mode 100644 index 00000000000..3f5c4c4f17a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_securedvmdetails.go @@ -0,0 +1,8 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecuredVMDetails struct { + SecuredVMOsDiskEncryptionSetId *string `json:"securedVMOsDiskEncryptionSetId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_sqldatadirectorymapping.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_sqldatadirectorymapping.go new file mode 100644 index 00000000000..9de6dd3d184 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_sqldatadirectorymapping.go @@ -0,0 +1,11 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SQLDataDirectoryMapping struct { + MappingType *SQLDataDirectoryType `json:"mappingType,omitempty"` + SourceLogicalName *string `json:"sourceLogicalName,omitempty"` + SourcePath *string `json:"sourcePath,omitempty"` + TargetPath *string `json:"targetPath,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetafsrestoreinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetafsrestoreinfo.go new file mode 100644 index 00000000000..56b7218e6de --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetafsrestoreinfo.go @@ -0,0 +1,9 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetAFSRestoreInfo struct { + Name *string `json:"name,omitempty"` + TargetResourceId *string `json:"targetResourceId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetdisknetworkaccesssettings.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetdisknetworkaccesssettings.go new file mode 100644 index 00000000000..a900401068b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetdisknetworkaccesssettings.go @@ -0,0 +1,9 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetDiskNetworkAccessSettings struct { + TargetDiskAccessId *string `json:"targetDiskAccessId,omitempty"` + TargetDiskNetworkAccessOption *TargetDiskNetworkAccessOption `json:"targetDiskNetworkAccessOption,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetrestoreinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetrestoreinfo.go new file mode 100644 index 00000000000..4d4171906ed --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_targetrestoreinfo.go @@ -0,0 +1,11 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetRestoreInfo struct { + ContainerId *string `json:"containerId,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + OverwriteOption *OverwriteOptions `json:"overwriteOption,omitempty"` + TargetDirectoryForFileRestore *string `json:"targetDirectoryForFileRestore,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateiaasvmrestoreoperationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateiaasvmrestoreoperationrequest.go new file mode 100644 index 00000000000..1e08498a231 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateiaasvmrestoreoperationrequest.go @@ -0,0 +1,60 @@ +package operation + +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 _ ValidateOperationRequest = ValidateIaasVMRestoreOperationRequest{} + +type ValidateIaasVMRestoreOperationRequest struct { + RestoreRequest RestoreRequest `json:"restoreRequest"` + + // Fields inherited from ValidateOperationRequest +} + +var _ json.Marshaler = ValidateIaasVMRestoreOperationRequest{} + +func (s ValidateIaasVMRestoreOperationRequest) MarshalJSON() ([]byte, error) { + type wrapper ValidateIaasVMRestoreOperationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ValidateIaasVMRestoreOperationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ValidateIaasVMRestoreOperationRequest: %+v", err) + } + decoded["objectType"] = "ValidateIaasVMRestoreOperationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ValidateIaasVMRestoreOperationRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &ValidateIaasVMRestoreOperationRequest{} + +func (s *ValidateIaasVMRestoreOperationRequest) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateIaasVMRestoreOperationRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequest"]; ok { + impl, err := unmarshalRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequest' for 'ValidateIaasVMRestoreOperationRequest': %+v", err) + } + s.RestoreRequest = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationrequest.go new file mode 100644 index 00000000000..83d08840b13 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationrequest.go @@ -0,0 +1,56 @@ +package operation + +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 ValidateOperationRequest interface { +} + +func unmarshalValidateOperationRequestImplementation(input []byte) (ValidateOperationRequest, 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 ValidateOperationRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ValidateIaasVMRestoreOperationRequest") { + var out ValidateIaasVMRestoreOperationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ValidateIaasVMRestoreOperationRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ValidateRestoreOperationRequest") { + var out ValidateRestoreOperationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ValidateRestoreOperationRequest: %+v", err) + } + return out, nil + } + + type RawValidateOperationRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawValidateOperationRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationresponse.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationresponse.go new file mode 100644 index 00000000000..0be2ef4af18 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationresponse.go @@ -0,0 +1,8 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateOperationResponse struct { + ValidationResults *[]ErrorDetail `json:"validationResults,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationsresponse.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationsresponse.go new file mode 100644 index 00000000000..8b9f3991c07 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validateoperationsresponse.go @@ -0,0 +1,8 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateOperationsResponse struct { + ValidateOperationResponse *ValidateOperationResponse `json:"validateOperationResponse,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validaterestoreoperationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validaterestoreoperationrequest.go new file mode 100644 index 00000000000..5fe10835e45 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/model_validaterestoreoperationrequest.go @@ -0,0 +1,60 @@ +package operation + +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 _ ValidateOperationRequest = ValidateRestoreOperationRequest{} + +type ValidateRestoreOperationRequest struct { + RestoreRequest RestoreRequest `json:"restoreRequest"` + + // Fields inherited from ValidateOperationRequest +} + +var _ json.Marshaler = ValidateRestoreOperationRequest{} + +func (s ValidateRestoreOperationRequest) MarshalJSON() ([]byte, error) { + type wrapper ValidateRestoreOperationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ValidateRestoreOperationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ValidateRestoreOperationRequest: %+v", err) + } + decoded["objectType"] = "ValidateRestoreOperationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ValidateRestoreOperationRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &ValidateRestoreOperationRequest{} + +func (s *ValidateRestoreOperationRequest) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateRestoreOperationRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequest"]; ok { + impl, err := unmarshalRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequest' for 'ValidateRestoreOperationRequest': %+v", err) + } + s.RestoreRequest = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/operation/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/operation/version.go new file mode 100644 index 00000000000..b4693a785cd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/operation/version.go @@ -0,0 +1,12 @@ +package operation + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/operation/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/README.md new file mode 100644 index 00000000000..d26fe304aa4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/README.md @@ -0,0 +1,65 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection` Documentation + +The `privateendpointconnection` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/privateendpointconnection" +``` + + +### Client Initialization + +```go +client := privateendpointconnection.NewPrivateEndpointConnectionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnection.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "privateEndpointConnectionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnection.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "privateEndpointConnectionValue") + +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: `PrivateEndpointConnectionClient.Put` + +```go +ctx := context.TODO() +id := privateendpointconnection.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "privateEndpointConnectionValue") + +payload := privateendpointconnection.PrivateEndpointConnectionResource{ + // ... +} + + +if err := client.PutThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/client.go new file mode 100644 index 00000000000..6acd77b913c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/client.go @@ -0,0 +1,18 @@ +package privateendpointconnection + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionClient struct { + Client autorest.Client + baseUri string +} + +func NewPrivateEndpointConnectionClientWithBaseURI(endpoint string) PrivateEndpointConnectionClient { + return PrivateEndpointConnectionClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/constants.go new file mode 100644 index 00000000000..b46bbc28be1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/constants.go @@ -0,0 +1,74 @@ +package privateendpointconnection + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionStatus string + +const ( + PrivateEndpointConnectionStatusApproved PrivateEndpointConnectionStatus = "Approved" + PrivateEndpointConnectionStatusDisconnected PrivateEndpointConnectionStatus = "Disconnected" + PrivateEndpointConnectionStatusPending PrivateEndpointConnectionStatus = "Pending" + PrivateEndpointConnectionStatusRejected PrivateEndpointConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointConnectionStatus() []string { + return []string{ + string(PrivateEndpointConnectionStatusApproved), + string(PrivateEndpointConnectionStatusDisconnected), + string(PrivateEndpointConnectionStatusPending), + string(PrivateEndpointConnectionStatusRejected), + } +} + +func parsePrivateEndpointConnectionStatus(input string) (*PrivateEndpointConnectionStatus, error) { + vals := map[string]PrivateEndpointConnectionStatus{ + "approved": PrivateEndpointConnectionStatusApproved, + "disconnected": PrivateEndpointConnectionStatusDisconnected, + "pending": PrivateEndpointConnectionStatusPending, + "rejected": PrivateEndpointConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStatePending ProvisioningState = "Pending" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStatePending), + string(ProvisioningStateSucceeded), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "pending": ProvisioningStatePending, + "succeeded": ProvisioningStateSucceeded, + } + 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/recoveryservicesbackup/2023-02-01/privateendpointconnection/id_privateendpointconnection.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/id_privateendpointconnection.go new file mode 100644 index 00000000000..9e8cb3fd3db --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/id_privateendpointconnection.go @@ -0,0 +1,140 @@ +package privateendpointconnection + +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 = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, vaultName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/id_privateendpointconnection_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..abea03c0a2d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnection + +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 = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_delete_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_delete_autorest.go new file mode 100644 index 00000000000..7e8532d71b7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_delete_autorest.go @@ -0,0 +1,78 @@ +package privateendpointconnection + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c PrivateEndpointConnectionClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnection.PrivateEndpointConnectionClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnection.PrivateEndpointConnectionClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c PrivateEndpointConnectionClient) preparerForDelete(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c PrivateEndpointConnectionClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_get_autorest.go new file mode 100644 index 00000000000..d5309175155 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_get_autorest.go @@ -0,0 +1,68 @@ +package privateendpointconnection + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnectionResource +} + +// Get ... +func (c PrivateEndpointConnectionClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnection.PrivateEndpointConnectionClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnection.PrivateEndpointConnectionClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnection.PrivateEndpointConnectionClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c PrivateEndpointConnectionClient) preparerForGet(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c PrivateEndpointConnectionClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_put_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_put_autorest.go new file mode 100644 index 00000000000..d7894bcd3a4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/method_put_autorest.go @@ -0,0 +1,79 @@ +package privateendpointconnection + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Put ... +func (c PrivateEndpointConnectionClient) Put(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnectionResource) (result PutOperationResponse, err error) { + req, err := c.preparerForPut(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnection.PrivateEndpointConnectionClient", "Put", nil, "Failure preparing request") + return + } + + result, err = c.senderForPut(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "privateendpointconnection.PrivateEndpointConnectionClient", "Put", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PutThenPoll performs Put then polls until it's completed +func (c PrivateEndpointConnectionClient) PutThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnectionResource) error { + result, err := c.Put(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Put: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Put: %+v", err) + } + + return nil +} + +// preparerForPut prepares the Put request. +func (c PrivateEndpointConnectionClient) preparerForPut(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnectionResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPut sends the Put request. The method will close the +// http.Response Body if it receives an error. +func (c PrivateEndpointConnectionClient) senderForPut(ctx context.Context, req *http.Request) (future PutOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpoint.go new file mode 100644 index 00000000000..36d044c72d1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpointconnection.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpointconnection.go new file mode 100644 index 00000000000..d39d931a8d9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpointconnection.go @@ -0,0 +1,10 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpointconnectionresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpointconnectionresource.go new file mode 100644 index 00000000000..e3f0f4f5c74 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privateendpointconnectionresource.go @@ -0,0 +1,14 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnection `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privatelinkserviceconnectionstate.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..20a7c794589 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionRequired *string `json:"actionRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/version.go new file mode 100644 index 00000000000..c62d89a5601 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/privateendpointconnection/version.go @@ -0,0 +1,12 @@ +package privateendpointconnection + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnection/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/README.md new file mode 100644 index 00000000000..eaf10373a7b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers` Documentation + +The `protectablecontainers` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/protectablecontainers" +``` + + +### Client Initialization + +```go +client := protectablecontainers.NewProtectableContainersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProtectableContainersClient.List` + +```go +ctx := context.TODO() +id := protectablecontainers.NewBackupFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue") + +// alternatively `client.List(ctx, id, protectablecontainers.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, protectablecontainers.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/client.go new file mode 100644 index 00000000000..3d5274d457a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/client.go @@ -0,0 +1,18 @@ +package protectablecontainers + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectableContainersClient struct { + Client autorest.Client + baseUri string +} + +func NewProtectableContainersClientWithBaseURI(endpoint string) ProtectableContainersClient { + return ProtectableContainersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/constants.go new file mode 100644 index 00000000000..7d347c78755 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/constants.go @@ -0,0 +1,131 @@ +package protectablecontainers + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type ProtectableContainerType string + +const ( + ProtectableContainerTypeAzureBackupServerContainer ProtectableContainerType = "AzureBackupServerContainer" + ProtectableContainerTypeAzureSqlContainer ProtectableContainerType = "AzureSqlContainer" + ProtectableContainerTypeAzureWorkloadContainer ProtectableContainerType = "AzureWorkloadContainer" + ProtectableContainerTypeCluster ProtectableContainerType = "Cluster" + ProtectableContainerTypeDPMContainer ProtectableContainerType = "DPMContainer" + ProtectableContainerTypeGenericContainer ProtectableContainerType = "GenericContainer" + ProtectableContainerTypeIaasVMContainer ProtectableContainerType = "IaasVMContainer" + ProtectableContainerTypeIaasVMServiceContainer ProtectableContainerType = "IaasVMServiceContainer" + ProtectableContainerTypeInvalid ProtectableContainerType = "Invalid" + ProtectableContainerTypeMABContainer ProtectableContainerType = "MABContainer" + ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines ProtectableContainerType = "Microsoft.ClassicCompute/virtualMachines" + ProtectableContainerTypeMicrosoftPointComputeVirtualMachines ProtectableContainerType = "Microsoft.Compute/virtualMachines" + ProtectableContainerTypeSQLAGWorkLoadContainer ProtectableContainerType = "SQLAGWorkLoadContainer" + ProtectableContainerTypeStorageContainer ProtectableContainerType = "StorageContainer" + ProtectableContainerTypeUnknown ProtectableContainerType = "Unknown" + ProtectableContainerTypeVCenter ProtectableContainerType = "VCenter" + ProtectableContainerTypeVMAppContainer ProtectableContainerType = "VMAppContainer" + ProtectableContainerTypeWindows ProtectableContainerType = "Windows" +) + +func PossibleValuesForProtectableContainerType() []string { + return []string{ + string(ProtectableContainerTypeAzureBackupServerContainer), + string(ProtectableContainerTypeAzureSqlContainer), + string(ProtectableContainerTypeAzureWorkloadContainer), + string(ProtectableContainerTypeCluster), + string(ProtectableContainerTypeDPMContainer), + string(ProtectableContainerTypeGenericContainer), + string(ProtectableContainerTypeIaasVMContainer), + string(ProtectableContainerTypeIaasVMServiceContainer), + string(ProtectableContainerTypeInvalid), + string(ProtectableContainerTypeMABContainer), + string(ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines), + string(ProtectableContainerTypeMicrosoftPointComputeVirtualMachines), + string(ProtectableContainerTypeSQLAGWorkLoadContainer), + string(ProtectableContainerTypeStorageContainer), + string(ProtectableContainerTypeUnknown), + string(ProtectableContainerTypeVCenter), + string(ProtectableContainerTypeVMAppContainer), + string(ProtectableContainerTypeWindows), + } +} + +func parseProtectableContainerType(input string) (*ProtectableContainerType, error) { + vals := map[string]ProtectableContainerType{ + "azurebackupservercontainer": ProtectableContainerTypeAzureBackupServerContainer, + "azuresqlcontainer": ProtectableContainerTypeAzureSqlContainer, + "azureworkloadcontainer": ProtectableContainerTypeAzureWorkloadContainer, + "cluster": ProtectableContainerTypeCluster, + "dpmcontainer": ProtectableContainerTypeDPMContainer, + "genericcontainer": ProtectableContainerTypeGenericContainer, + "iaasvmcontainer": ProtectableContainerTypeIaasVMContainer, + "iaasvmservicecontainer": ProtectableContainerTypeIaasVMServiceContainer, + "invalid": ProtectableContainerTypeInvalid, + "mabcontainer": ProtectableContainerTypeMABContainer, + "microsoft.classiccompute/virtualmachines": ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines, + "microsoft.compute/virtualmachines": ProtectableContainerTypeMicrosoftPointComputeVirtualMachines, + "sqlagworkloadcontainer": ProtectableContainerTypeSQLAGWorkLoadContainer, + "storagecontainer": ProtectableContainerTypeStorageContainer, + "unknown": ProtectableContainerTypeUnknown, + "vcenter": ProtectableContainerTypeVCenter, + "vmappcontainer": ProtectableContainerTypeVMAppContainer, + "windows": ProtectableContainerTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectableContainerType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/id_backupfabric.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/id_backupfabric.go new file mode 100644 index 00000000000..37267a4ca9f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/id_backupfabric.go @@ -0,0 +1,140 @@ +package protectablecontainers + +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 = BackupFabricId{} + +// BackupFabricId is a struct representing the Resource ID for a Backup Fabric +type BackupFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string +} + +// NewBackupFabricID returns a new BackupFabricId struct +func NewBackupFabricID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string) BackupFabricId { + return BackupFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + } +} + +// ParseBackupFabricID parses 'input' into a BackupFabricId +func ParseBackupFabricID(input string) (*BackupFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseBackupFabricIDInsensitively parses 'input' case-insensitively into a BackupFabricId +// note: this method should only be used for API response data and not user input +func ParseBackupFabricIDInsensitively(input string) (*BackupFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateBackupFabricID checks that 'input' can be parsed as a Backup Fabric ID +func ValidateBackupFabricID(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 := ParseBackupFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Fabric ID +func (id BackupFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Fabric ID +func (id BackupFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + } +} + +// String returns a human-readable description of this Backup Fabric ID +func (id BackupFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + } + return fmt.Sprintf("Backup Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/id_backupfabric_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/id_backupfabric_test.go new file mode 100644 index 00000000000..3683affb4b8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/id_backupfabric_test.go @@ -0,0 +1,327 @@ +package protectablecontainers + +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 = BackupFabricId{} + +func TestNewBackupFabricID(t *testing.T) { + id := NewBackupFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } +} + +func TestFormatBackupFabricID(t *testing.T) { + actual := NewBackupFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Expected: &BackupFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + } +} + +func TestParseBackupFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Expected: &BackupFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Expected: &BackupFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + } +} + +func TestSegmentsForBackupFabricId(t *testing.T) { + segments := BackupFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupFabricId 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/recoveryservicesbackup/2023-02-01/protectablecontainers/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/method_list_autorest.go new file mode 100644 index 00000000000..bdea7c60f0c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/method_list_autorest.go @@ -0,0 +1,215 @@ +package protectablecontainers + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectableContainerResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ProtectableContainerResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c ProtectableContainersClient) List(ctx context.Context, id BackupFabricId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "protectablecontainers.ProtectableContainersClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectablecontainers.ProtectableContainersClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectablecontainers.ProtectableContainersClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ProtectableContainersClient) preparerForList(ctx context.Context, id BackupFabricId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/protectableContainers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ProtectableContainersClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ProtectableContainersClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ProtectableContainerResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "protectablecontainers.ProtectableContainersClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectablecontainers.ProtectableContainersClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectablecontainers.ProtectableContainersClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ProtectableContainersClient) ListComplete(ctx context.Context, id BackupFabricId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ProtectableContainerResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ProtectableContainersClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupFabricId, options ListOperationOptions, predicate ProtectableContainerResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ProtectableContainerResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_azurestorageprotectablecontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_azurestorageprotectablecontainer.go new file mode 100644 index 00000000000..138e03f203a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_azurestorageprotectablecontainer.go @@ -0,0 +1,44 @@ +package protectablecontainers + +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 _ ProtectableContainer = AzureStorageProtectableContainer{} + +type AzureStorageProtectableContainer struct { + + // Fields inherited from ProtectableContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` +} + +var _ json.Marshaler = AzureStorageProtectableContainer{} + +func (s AzureStorageProtectableContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureStorageProtectableContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureStorageProtectableContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureStorageProtectableContainer: %+v", err) + } + decoded["protectableContainerType"] = "StorageContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureStorageProtectableContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_azurevmappcontainerprotectablecontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_azurevmappcontainerprotectablecontainer.go new file mode 100644 index 00000000000..ea902c91b28 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_azurevmappcontainerprotectablecontainer.go @@ -0,0 +1,44 @@ +package protectablecontainers + +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 _ ProtectableContainer = AzureVMAppContainerProtectableContainer{} + +type AzureVMAppContainerProtectableContainer struct { + + // Fields inherited from ProtectableContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` +} + +var _ json.Marshaler = AzureVMAppContainerProtectableContainer{} + +func (s AzureVMAppContainerProtectableContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureVMAppContainerProtectableContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMAppContainerProtectableContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMAppContainerProtectableContainer: %+v", err) + } + decoded["protectableContainerType"] = "VMAppContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMAppContainerProtectableContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_protectablecontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_protectablecontainer.go new file mode 100644 index 00000000000..421a8f62359 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_protectablecontainer.go @@ -0,0 +1,56 @@ +package protectablecontainers + +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 ProtectableContainer interface { +} + +func unmarshalProtectableContainerImplementation(input []byte) (ProtectableContainer, 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 ProtectableContainer into map[string]interface: %+v", err) + } + + value, ok := temp["protectableContainerType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "StorageContainer") { + var out AzureStorageProtectableContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureStorageProtectableContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMAppContainer") { + var out AzureVMAppContainerProtectableContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMAppContainerProtectableContainer: %+v", err) + } + return out, nil + } + + type RawProtectableContainerImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectableContainerImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_protectablecontainerresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_protectablecontainerresource.go new file mode 100644 index 00000000000..c4d67d07b27 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/model_protectablecontainerresource.go @@ -0,0 +1,50 @@ +package protectablecontainers + +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 ProtectableContainerResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectableContainer `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectableContainerResource{} + +func (s *ProtectableContainerResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectableContainerResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectableContainerResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectableContainerResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectableContainerImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectableContainerResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/predicates.go new file mode 100644 index 00000000000..d2037b961f0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/predicates.go @@ -0,0 +1,37 @@ +package protectablecontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectableContainerResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectableContainerResourceOperationPredicate) Matches(input ProtectableContainerResource) 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/recoveryservicesbackup/2023-02-01/protectablecontainers/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/version.go new file mode 100644 index 00000000000..f46a0d0994f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectablecontainers/version.go @@ -0,0 +1,12 @@ +package protectablecontainers + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/protectablecontainers/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/README.md new file mode 100644 index 00000000000..5ce098bf9dc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems` Documentation + +The `protecteditems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/protecteditems" +``` + + +### Client Initialization + +```go +client := protecteditems.NewProtectedItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProtectedItemsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := protecteditems.NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + +payload := protecteditems.ProtectedItemResource{ + // ... +} + + +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: `ProtectedItemsClient.Delete` + +```go +ctx := context.TODO() +id := protecteditems.NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + +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: `ProtectedItemsClient.Get` + +```go +ctx := context.TODO() +id := protecteditems.NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + +read, err := client.Get(ctx, id, protecteditems.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/client.go new file mode 100644 index 00000000000..6843a00f823 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/client.go @@ -0,0 +1,18 @@ +package protecteditems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectedItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewProtectedItemsClientWithBaseURI(endpoint string) ProtectedItemsClient { + return ProtectedItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/constants.go new file mode 100644 index 00000000000..622b31da48b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/constants.go @@ -0,0 +1,387 @@ +package protecteditems + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type CreateMode string + +const ( + CreateModeDefault CreateMode = "Default" + CreateModeInvalid CreateMode = "Invalid" + CreateModeRecover CreateMode = "Recover" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeDefault), + string(CreateModeInvalid), + string(CreateModeRecover), + } +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "default": CreateModeDefault, + "invalid": CreateModeInvalid, + "recover": CreateModeRecover, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreateMode(input) + return &out, nil +} + +type DataSourceType string + +const ( + DataSourceTypeAzureFileShare DataSourceType = "AzureFileShare" + DataSourceTypeAzureSqlDb DataSourceType = "AzureSqlDb" + DataSourceTypeClient DataSourceType = "Client" + DataSourceTypeExchange DataSourceType = "Exchange" + DataSourceTypeFileFolder DataSourceType = "FileFolder" + DataSourceTypeGenericDataSource DataSourceType = "GenericDataSource" + DataSourceTypeInvalid DataSourceType = "Invalid" + DataSourceTypeSAPAseDatabase DataSourceType = "SAPAseDatabase" + DataSourceTypeSAPHanaDBInstance DataSourceType = "SAPHanaDBInstance" + DataSourceTypeSAPHanaDatabase DataSourceType = "SAPHanaDatabase" + DataSourceTypeSQLDB DataSourceType = "SQLDB" + DataSourceTypeSQLDataBase DataSourceType = "SQLDataBase" + DataSourceTypeSharepoint DataSourceType = "Sharepoint" + DataSourceTypeSystemState DataSourceType = "SystemState" + DataSourceTypeVM DataSourceType = "VM" + DataSourceTypeVMwareVM DataSourceType = "VMwareVM" +) + +func PossibleValuesForDataSourceType() []string { + return []string{ + string(DataSourceTypeAzureFileShare), + string(DataSourceTypeAzureSqlDb), + string(DataSourceTypeClient), + string(DataSourceTypeExchange), + string(DataSourceTypeFileFolder), + string(DataSourceTypeGenericDataSource), + string(DataSourceTypeInvalid), + string(DataSourceTypeSAPAseDatabase), + string(DataSourceTypeSAPHanaDBInstance), + string(DataSourceTypeSAPHanaDatabase), + string(DataSourceTypeSQLDB), + string(DataSourceTypeSQLDataBase), + string(DataSourceTypeSharepoint), + string(DataSourceTypeSystemState), + string(DataSourceTypeVM), + string(DataSourceTypeVMwareVM), + } +} + +func parseDataSourceType(input string) (*DataSourceType, error) { + vals := map[string]DataSourceType{ + "azurefileshare": DataSourceTypeAzureFileShare, + "azuresqldb": DataSourceTypeAzureSqlDb, + "client": DataSourceTypeClient, + "exchange": DataSourceTypeExchange, + "filefolder": DataSourceTypeFileFolder, + "genericdatasource": DataSourceTypeGenericDataSource, + "invalid": DataSourceTypeInvalid, + "sapasedatabase": DataSourceTypeSAPAseDatabase, + "saphanadbinstance": DataSourceTypeSAPHanaDBInstance, + "saphanadatabase": DataSourceTypeSAPHanaDatabase, + "sqldb": DataSourceTypeSQLDB, + "sqldatabase": DataSourceTypeSQLDataBase, + "sharepoint": DataSourceTypeSharepoint, + "systemstate": DataSourceTypeSystemState, + "vm": DataSourceTypeVM, + "vmwarevm": DataSourceTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataSourceType(input) + return &out, nil +} + +type HealthStatus string + +const ( + HealthStatusActionRequired HealthStatus = "ActionRequired" + HealthStatusActionSuggested HealthStatus = "ActionSuggested" + HealthStatusInvalid HealthStatus = "Invalid" + HealthStatusPassed HealthStatus = "Passed" +) + +func PossibleValuesForHealthStatus() []string { + return []string{ + string(HealthStatusActionRequired), + string(HealthStatusActionSuggested), + string(HealthStatusInvalid), + string(HealthStatusPassed), + } +} + +func parseHealthStatus(input string) (*HealthStatus, error) { + vals := map[string]HealthStatus{ + "actionrequired": HealthStatusActionRequired, + "actionsuggested": HealthStatusActionSuggested, + "invalid": HealthStatusInvalid, + "passed": HealthStatusPassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthStatus(input) + return &out, nil +} + +type LastBackupStatus string + +const ( + LastBackupStatusHealthy LastBackupStatus = "Healthy" + LastBackupStatusIRPending LastBackupStatus = "IRPending" + LastBackupStatusInvalid LastBackupStatus = "Invalid" + LastBackupStatusUnhealthy LastBackupStatus = "Unhealthy" +) + +func PossibleValuesForLastBackupStatus() []string { + return []string{ + string(LastBackupStatusHealthy), + string(LastBackupStatusIRPending), + string(LastBackupStatusInvalid), + string(LastBackupStatusUnhealthy), + } +} + +func parseLastBackupStatus(input string) (*LastBackupStatus, error) { + vals := map[string]LastBackupStatus{ + "healthy": LastBackupStatusHealthy, + "irpending": LastBackupStatusIRPending, + "invalid": LastBackupStatusInvalid, + "unhealthy": LastBackupStatusUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LastBackupStatus(input) + return &out, nil +} + +type ProtectedItemHealthStatus string + +const ( + ProtectedItemHealthStatusHealthy ProtectedItemHealthStatus = "Healthy" + ProtectedItemHealthStatusIRPending ProtectedItemHealthStatus = "IRPending" + ProtectedItemHealthStatusInvalid ProtectedItemHealthStatus = "Invalid" + ProtectedItemHealthStatusNotReachable ProtectedItemHealthStatus = "NotReachable" + ProtectedItemHealthStatusUnhealthy ProtectedItemHealthStatus = "Unhealthy" +) + +func PossibleValuesForProtectedItemHealthStatus() []string { + return []string{ + string(ProtectedItemHealthStatusHealthy), + string(ProtectedItemHealthStatusIRPending), + string(ProtectedItemHealthStatusInvalid), + string(ProtectedItemHealthStatusNotReachable), + string(ProtectedItemHealthStatusUnhealthy), + } +} + +func parseProtectedItemHealthStatus(input string) (*ProtectedItemHealthStatus, error) { + vals := map[string]ProtectedItemHealthStatus{ + "healthy": ProtectedItemHealthStatusHealthy, + "irpending": ProtectedItemHealthStatusIRPending, + "invalid": ProtectedItemHealthStatusInvalid, + "notreachable": ProtectedItemHealthStatusNotReachable, + "unhealthy": ProtectedItemHealthStatusUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectedItemHealthStatus(input) + return &out, nil +} + +type ProtectedItemState string + +const ( + ProtectedItemStateBackupsSuspended ProtectedItemState = "BackupsSuspended" + ProtectedItemStateIRPending ProtectedItemState = "IRPending" + ProtectedItemStateInvalid ProtectedItemState = "Invalid" + ProtectedItemStateProtected ProtectedItemState = "Protected" + ProtectedItemStateProtectionError ProtectedItemState = "ProtectionError" + ProtectedItemStateProtectionPaused ProtectedItemState = "ProtectionPaused" + ProtectedItemStateProtectionStopped ProtectedItemState = "ProtectionStopped" +) + +func PossibleValuesForProtectedItemState() []string { + return []string{ + string(ProtectedItemStateBackupsSuspended), + string(ProtectedItemStateIRPending), + string(ProtectedItemStateInvalid), + string(ProtectedItemStateProtected), + string(ProtectedItemStateProtectionError), + string(ProtectedItemStateProtectionPaused), + string(ProtectedItemStateProtectionStopped), + } +} + +func parseProtectedItemState(input string) (*ProtectedItemState, error) { + vals := map[string]ProtectedItemState{ + "backupssuspended": ProtectedItemStateBackupsSuspended, + "irpending": ProtectedItemStateIRPending, + "invalid": ProtectedItemStateInvalid, + "protected": ProtectedItemStateProtected, + "protectionerror": ProtectedItemStateProtectionError, + "protectionpaused": ProtectedItemStateProtectionPaused, + "protectionstopped": ProtectedItemStateProtectionStopped, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectedItemState(input) + return &out, nil +} + +type ProtectionState string + +const ( + ProtectionStateBackupsSuspended ProtectionState = "BackupsSuspended" + ProtectionStateIRPending ProtectionState = "IRPending" + ProtectionStateInvalid ProtectionState = "Invalid" + ProtectionStateProtected ProtectionState = "Protected" + ProtectionStateProtectionError ProtectionState = "ProtectionError" + ProtectionStateProtectionPaused ProtectionState = "ProtectionPaused" + ProtectionStateProtectionStopped ProtectionState = "ProtectionStopped" +) + +func PossibleValuesForProtectionState() []string { + return []string{ + string(ProtectionStateBackupsSuspended), + string(ProtectionStateIRPending), + string(ProtectionStateInvalid), + string(ProtectionStateProtected), + string(ProtectionStateProtectionError), + string(ProtectionStateProtectionPaused), + string(ProtectionStateProtectionStopped), + } +} + +func parseProtectionState(input string) (*ProtectionState, error) { + vals := map[string]ProtectionState{ + "backupssuspended": ProtectionStateBackupsSuspended, + "irpending": ProtectionStateIRPending, + "invalid": ProtectionStateInvalid, + "protected": ProtectionStateProtected, + "protectionerror": ProtectionStateProtectionError, + "protectionpaused": ProtectionStateProtectionPaused, + "protectionstopped": ProtectionStateProtectionStopped, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionState(input) + return &out, nil +} + +type ResourceHealthStatus string + +const ( + ResourceHealthStatusHealthy ResourceHealthStatus = "Healthy" + ResourceHealthStatusInvalid ResourceHealthStatus = "Invalid" + ResourceHealthStatusPersistentDegraded ResourceHealthStatus = "PersistentDegraded" + ResourceHealthStatusPersistentUnhealthy ResourceHealthStatus = "PersistentUnhealthy" + ResourceHealthStatusTransientDegraded ResourceHealthStatus = "TransientDegraded" + ResourceHealthStatusTransientUnhealthy ResourceHealthStatus = "TransientUnhealthy" +) + +func PossibleValuesForResourceHealthStatus() []string { + return []string{ + string(ResourceHealthStatusHealthy), + string(ResourceHealthStatusInvalid), + string(ResourceHealthStatusPersistentDegraded), + string(ResourceHealthStatusPersistentUnhealthy), + string(ResourceHealthStatusTransientDegraded), + string(ResourceHealthStatusTransientUnhealthy), + } +} + +func parseResourceHealthStatus(input string) (*ResourceHealthStatus, error) { + vals := map[string]ResourceHealthStatus{ + "healthy": ResourceHealthStatusHealthy, + "invalid": ResourceHealthStatusInvalid, + "persistentdegraded": ResourceHealthStatusPersistentDegraded, + "persistentunhealthy": ResourceHealthStatusPersistentUnhealthy, + "transientdegraded": ResourceHealthStatusTransientDegraded, + "transientunhealthy": ResourceHealthStatusTransientUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceHealthStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/id_protecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/id_protecteditem.go new file mode 100644 index 00000000000..998386b144a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/id_protecteditem.go @@ -0,0 +1,166 @@ +package protecteditems + +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 = ProtectedItemId{} + +// ProtectedItemId is a struct representing the Resource ID for a Protected Item +type ProtectedItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string +} + +// NewProtectedItemID returns a new ProtectedItemId struct +func NewProtectedItemID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string) ProtectedItemId { + return ProtectedItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + } +} + +// ParseProtectedItemID parses 'input' into a ProtectedItemId +func ParseProtectedItemID(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProtectedItemIDInsensitively parses 'input' case-insensitively into a ProtectedItemId +// note: this method should only be used for API response data and not user input +func ParseProtectedItemIDInsensitively(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProtectedItemID checks that 'input' can be parsed as a Protected Item ID +func ValidateProtectedItemID(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 := ParseProtectedItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Protected Item ID +func (id ProtectedItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Protected Item ID +func (id ProtectedItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + } +} + +// String returns a human-readable description of this Protected Item ID +func (id ProtectedItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + } + return fmt.Sprintf("Protected Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/id_protecteditem_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/id_protecteditem_test.go new file mode 100644 index 00000000000..a03fcfcdb6f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/id_protecteditem_test.go @@ -0,0 +1,417 @@ +package protecteditems + +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 = ProtectedItemId{} + +func TestNewProtectedItemID(t *testing.T) { + id := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } +} + +func TestFormatProtectedItemID(t *testing.T) { + actual := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProtectedItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestParseProtectedItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestSegmentsForProtectedItemId(t *testing.T) { + segments := ProtectedItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProtectedItemId 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/recoveryservicesbackup/2023-02-01/protecteditems/method_createorupdate_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_createorupdate_autorest.go new file mode 100644 index 00000000000..22eeaf22b56 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_createorupdate_autorest.go @@ -0,0 +1,69 @@ +package protecteditems + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *ProtectedItemResource +} + +// CreateOrUpdate ... +func (c ProtectedItemsClient) CreateOrUpdate(ctx context.Context, id ProtectedItemId, input ProtectedItemResource) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ProtectedItemsClient) preparerForCreateOrUpdate(ctx context.Context, id ProtectedItemId, input ProtectedItemResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ProtectedItemsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_delete_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_delete_autorest.go new file mode 100644 index 00000000000..ed0ba3ec7a7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_delete_autorest.go @@ -0,0 +1,66 @@ +package protecteditems + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ProtectedItemsClient) Delete(ctx context.Context, id ProtectedItemId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ProtectedItemsClient) preparerForDelete(ctx context.Context, id ProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c ProtectedItemsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted, http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_get_autorest.go new file mode 100644 index 00000000000..feb41aa7dcb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/method_get_autorest.go @@ -0,0 +1,97 @@ +package protecteditems + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ProtectedItemResource +} + +type GetOperationOptions struct { + Filter *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o GetOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// Get ... +func (c ProtectedItemsClient) Get(ctx context.Context, id ProtectedItemId, options GetOperationOptions) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protecteditems.ProtectedItemsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ProtectedItemsClient) preparerForGet(ctx context.Context, id ProtectedItemId, options GetOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ProtectedItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurefileshareprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurefileshareprotecteditem.go new file mode 100644 index 00000000000..ae65be7f54d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurefileshareprotecteditem.go @@ -0,0 +1,91 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureFileshareProtectedItem{} + +type AzureFileshareProtectedItem struct { + ExtendedInfo *AzureFileshareProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureFileshareProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureFileshareProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureFileshareProtectedItem{} + +func (s AzureFileshareProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureFileshareProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileshareProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileshareProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureFileShareProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileshareProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurefileshareprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurefileshareprotecteditemextendedinfo.go new file mode 100644 index 00000000000..f3ee3ce37c0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurefileshareprotecteditemextendedinfo.go @@ -0,0 +1,42 @@ +package protecteditems + +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 AzureFileshareProtectedItemExtendedInfo struct { + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` + ResourceState *string `json:"resourceState,omitempty"` + ResourceStateSyncTime *string `json:"resourceStateSyncTime,omitempty"` +} + +func (o *AzureFileshareProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *AzureFileshareProtectedItemExtendedInfo) GetResourceStateSyncTimeAsTime() (*time.Time, error) { + if o.ResourceStateSyncTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResourceStateSyncTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureFileshareProtectedItemExtendedInfo) SetResourceStateSyncTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResourceStateSyncTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasclassiccomputevmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasclassiccomputevmprotecteditem.go new file mode 100644 index 00000000000..e8ecd7765b4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasclassiccomputevmprotecteditem.go @@ -0,0 +1,96 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureIaaSClassicComputeVMProtectedItem{} + +type AzureIaaSClassicComputeVMProtectedItem struct { + ExtendedInfo *AzureIaaSVMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ExtendedProperties *ExtendedProperties `json:"extendedProperties,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthDetails *[]ResourceHealthDetails `json:"healthDetails,omitempty"` + HealthStatus *HealthStatus `json:"healthStatus,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSClassicComputeVMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureIaaSClassicComputeVMProtectedItem{} + +func (s AzureIaaSClassicComputeVMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSClassicComputeVMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "Microsoft.ClassicCompute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaascomputevmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaascomputevmprotecteditem.go new file mode 100644 index 00000000000..a95186ef6d2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaascomputevmprotecteditem.go @@ -0,0 +1,96 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureIaaSComputeVMProtectedItem{} + +type AzureIaaSComputeVMProtectedItem struct { + ExtendedInfo *AzureIaaSVMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ExtendedProperties *ExtendedProperties `json:"extendedProperties,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthDetails *[]ResourceHealthDetails `json:"healthDetails,omitempty"` + HealthStatus *HealthStatus `json:"healthStatus,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureIaaSComputeVMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSComputeVMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureIaaSComputeVMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSComputeVMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureIaaSComputeVMProtectedItem{} + +func (s AzureIaaSComputeVMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSComputeVMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSComputeVMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSComputeVMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "Microsoft.Compute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSComputeVMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasvmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasvmprotecteditem.go new file mode 100644 index 00000000000..159ec8ffe50 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasvmprotecteditem.go @@ -0,0 +1,96 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureIaaSVMProtectedItem{} + +type AzureIaaSVMProtectedItem struct { + ExtendedInfo *AzureIaaSVMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ExtendedProperties *ExtendedProperties `json:"extendedProperties,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthDetails *[]ResourceHealthDetails `json:"healthDetails,omitempty"` + HealthStatus *HealthStatus `json:"healthStatus,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureIaaSVMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureIaaSVMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureIaaSVMProtectedItem{} + +func (s AzureIaaSVMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureIaaSVMProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasvmprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasvmprotecteditemextendedinfo.go new file mode 100644 index 00000000000..36c092fb410 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azureiaasvmprotecteditemextendedinfo.go @@ -0,0 +1,67 @@ +package protecteditems + +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 AzureIaaSVMProtectedItemExtendedInfo struct { + NewestRecoveryPointInArchive *string `json:"newestRecoveryPointInArchive,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + OldestRecoveryPointInArchive *string `json:"oldestRecoveryPointInArchive,omitempty"` + OldestRecoveryPointInVault *string `json:"oldestRecoveryPointInVault,omitempty"` + PolicyInconsistent *bool `json:"policyInconsistent,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetNewestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.NewestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NewestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetNewestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NewestRecoveryPointInArchive = &formatted +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetOldestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetOldestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInArchive = &formatted +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) GetOldestRecoveryPointInVaultAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInVault == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInVault, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureIaaSVMProtectedItemExtendedInfo) SetOldestRecoveryPointInVaultAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInVault = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azuresqlprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azuresqlprotecteditem.go new file mode 100644 index 00000000000..64dd42ea1dc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azuresqlprotecteditem.go @@ -0,0 +1,87 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureSqlProtectedItem{} + +type AzureSqlProtectedItem struct { + ExtendedInfo *AzureSqlProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemDataId *string `json:"protectedItemDataId,omitempty"` + ProtectionState *ProtectedItemState `json:"protectionState,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureSqlProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureSqlProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureSqlProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureSqlProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureSqlProtectedItem{} + +func (s AzureSqlProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureSqlProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSqlProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSqlProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "Microsoft.Sql/servers/databases" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSqlProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azuresqlprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azuresqlprotecteditemextendedinfo.go new file mode 100644 index 00000000000..3b6ba503042 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azuresqlprotecteditemextendedinfo.go @@ -0,0 +1,28 @@ +package protecteditems + +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 AzureSqlProtectedItemExtendedInfo struct { + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *AzureSqlProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureSqlProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadprotecteditem.go new file mode 100644 index 00000000000..b1258778cec --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadprotecteditem.go @@ -0,0 +1,97 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadProtectedItem{} + +type AzureVMWorkloadProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadProtectedItem{} + +func (s AzureVMWorkloadProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadprotecteditemextendedinfo.go new file mode 100644 index 00000000000..e51960b91cf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadprotecteditemextendedinfo.go @@ -0,0 +1,68 @@ +package protecteditems + +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 AzureVMWorkloadProtectedItemExtendedInfo struct { + NewestRecoveryPointInArchive *string `json:"newestRecoveryPointInArchive,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + OldestRecoveryPointInArchive *string `json:"oldestRecoveryPointInArchive,omitempty"` + OldestRecoveryPointInVault *string `json:"oldestRecoveryPointInVault,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + RecoveryModel *string `json:"recoveryModel,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetNewestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.NewestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NewestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetNewestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NewestRecoveryPointInArchive = &formatted +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetOldestRecoveryPointInArchiveAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInArchive == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInArchive, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetOldestRecoveryPointInArchiveAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInArchive = &formatted +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) GetOldestRecoveryPointInVaultAsTime() (*time.Time, error) { + if o.OldestRecoveryPointInVault == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPointInVault, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadProtectedItemExtendedInfo) SetOldestRecoveryPointInVaultAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPointInVault = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsapasedatabaseprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsapasedatabaseprotecteditem.go new file mode 100644 index 00000000000..66fb2059407 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsapasedatabaseprotecteditem.go @@ -0,0 +1,97 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSAPAseDatabaseProtectedItem{} + +type AzureVMWorkloadSAPAseDatabaseProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPAseDatabaseProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSAPAseDatabaseProtectedItem{} + +func (s AzureVMWorkloadSAPAseDatabaseProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPAseDatabaseProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSAPAseDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsaphanadatabaseprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsaphanadatabaseprotecteditem.go new file mode 100644 index 00000000000..9dc78e8d611 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsaphanadatabaseprotecteditem.go @@ -0,0 +1,97 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSAPHanaDatabaseProtectedItem{} + +type AzureVMWorkloadSAPHanaDatabaseProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDatabaseProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaDatabaseProtectedItem{} + +func (s AzureVMWorkloadSAPHanaDatabaseProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaDatabaseProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSAPHanaDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsaphanadbinstanceprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsaphanadbinstanceprotecteditem.go new file mode 100644 index 00000000000..e40ba95b01f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsaphanadbinstanceprotecteditem.go @@ -0,0 +1,97 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSAPHanaDBInstanceProtectedItem{} + +type AzureVMWorkloadSAPHanaDBInstanceProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSAPHanaDBInstanceProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSAPHanaDBInstanceProtectedItem{} + +func (s AzureVMWorkloadSAPHanaDBInstanceProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSAPHanaDBInstanceProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSAPHanaDBInstance" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsqldatabaseprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsqldatabaseprotecteditem.go new file mode 100644 index 00000000000..dc8e9d9fa96 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_azurevmworkloadsqldatabaseprotecteditem.go @@ -0,0 +1,97 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = AzureVMWorkloadSQLDatabaseProtectedItem{} + +type AzureVMWorkloadSQLDatabaseProtectedItem struct { + ExtendedInfo *AzureVMWorkloadProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KpisHealths *map[string]KPIResourceHealthDetails `json:"kpisHealths,omitempty"` + LastBackupErrorDetail *ErrorDetail `json:"lastBackupErrorDetail,omitempty"` + LastBackupStatus *LastBackupStatus `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ParentName *string `json:"parentName,omitempty"` + ParentType *string `json:"parentType,omitempty"` + ProtectedItemDataSourceId *string `json:"protectedItemDataSourceId,omitempty"` + ProtectedItemHealthStatus *ProtectedItemHealthStatus `json:"protectedItemHealthStatus,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + ServerName *string `json:"serverName,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureVMWorkloadSQLDatabaseProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = AzureVMWorkloadSQLDatabaseProtectedItem{} + +func (s AzureVMWorkloadSQLDatabaseProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadSQLDatabaseProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "AzureVmWorkloadSQLDatabase" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_diskexclusionproperties.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_diskexclusionproperties.go new file mode 100644 index 00000000000..17d722bc609 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_diskexclusionproperties.go @@ -0,0 +1,9 @@ +package protecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskExclusionProperties struct { + DiskLunList *[]int64 `json:"diskLunList,omitempty"` + IsInclusionList *bool `json:"isInclusionList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_dpmprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_dpmprotecteditem.go new file mode 100644 index 00000000000..3094ac02303 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_dpmprotecteditem.go @@ -0,0 +1,88 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = DPMProtectedItem{} + +type DPMProtectedItem struct { + BackupEngineName *string `json:"backupEngineName,omitempty"` + ExtendedInfo *DPMProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionState *ProtectedItemState `json:"protectionState,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *DPMProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *DPMProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = DPMProtectedItem{} + +func (s DPMProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper DPMProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DPMProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DPMProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "DPMProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DPMProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_dpmprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_dpmprotecteditemextendedinfo.go new file mode 100644 index 00000000000..fc6f9e8cd52 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_dpmprotecteditemextendedinfo.go @@ -0,0 +1,75 @@ +package protecteditems + +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 DPMProtectedItemExtendedInfo struct { + DiskStorageUsedInBytes *string `json:"diskStorageUsedInBytes,omitempty"` + IsCollocated *bool `json:"isCollocated,omitempty"` + IsPresentOnCloud *bool `json:"isPresentOnCloud,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + OnPremiseLatestRecoveryPoint *string `json:"onPremiseLatestRecoveryPoint,omitempty"` + OnPremiseOldestRecoveryPoint *string `json:"onPremiseOldestRecoveryPoint,omitempty"` + OnPremiseRecoveryPointCount *int64 `json:"onPremiseRecoveryPointCount,omitempty"` + ProtectableObjectLoadPath *map[string]string `json:"protectableObjectLoadPath,omitempty"` + Protected *bool `json:"protected,omitempty"` + ProtectionGroupName *string `json:"protectionGroupName,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` + TotalDiskStorageSizeInBytes *string `json:"totalDiskStorageSizeInBytes,omitempty"` +} + +func (o *DPMProtectedItemExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} + +func (o *DPMProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} + +func (o *DPMProtectedItemExtendedInfo) GetOnPremiseLatestRecoveryPointAsTime() (*time.Time, error) { + if o.OnPremiseLatestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OnPremiseLatestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetOnPremiseLatestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OnPremiseLatestRecoveryPoint = &formatted +} + +func (o *DPMProtectedItemExtendedInfo) GetOnPremiseOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OnPremiseOldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OnPremiseOldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMProtectedItemExtendedInfo) SetOnPremiseOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OnPremiseOldestRecoveryPoint = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_errordetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_errordetail.go new file mode 100644 index 00000000000..e3fa04c50a3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_errordetail.go @@ -0,0 +1,10 @@ +package protecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_extendedproperties.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_extendedproperties.go new file mode 100644 index 00000000000..fe926ccaa09 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_extendedproperties.go @@ -0,0 +1,9 @@ +package protecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedProperties struct { + DiskExclusionProperties *DiskExclusionProperties `json:"diskExclusionProperties,omitempty"` + LinuxVMApplicationName *string `json:"linuxVmApplicationName,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_genericprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_genericprotecteditem.go new file mode 100644 index 00000000000..3a58311b49b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_genericprotecteditem.go @@ -0,0 +1,90 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = GenericProtectedItem{} + +type GenericProtectedItem struct { + FabricName *string `json:"fabricName,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PolicyState *string `json:"policyState,omitempty"` + ProtectedItemId *int64 `json:"protectedItemId,omitempty"` + ProtectionState *ProtectionState `json:"protectionState,omitempty"` + SourceAssociations *map[string]string `json:"sourceAssociations,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *GenericProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *GenericProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = GenericProtectedItem{} + +func (s GenericProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper GenericProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "GenericProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_kpiresourcehealthdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_kpiresourcehealthdetails.go new file mode 100644 index 00000000000..6cef5da3613 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_kpiresourcehealthdetails.go @@ -0,0 +1,9 @@ +package protecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KPIResourceHealthDetails struct { + ResourceHealthDetails *[]ResourceHealthDetails `json:"resourceHealthDetails,omitempty"` + ResourceHealthStatus *ResourceHealthStatus `json:"resourceHealthStatus,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_mabfilefolderprotecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_mabfilefolderprotecteditem.go new file mode 100644 index 00000000000..9865843e14f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_mabfilefolderprotecteditem.go @@ -0,0 +1,91 @@ +package protecteditems + +import ( + "encoding/json" + "fmt" + "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. + +var _ ProtectedItem = MabFileFolderProtectedItem{} + +type MabFileFolderProtectedItem struct { + ComputerName *string `json:"computerName,omitempty"` + DeferredDeleteSyncTimeInUTC *int64 `json:"deferredDeleteSyncTimeInUTC,omitempty"` + ExtendedInfo *MabFileFolderProtectedItemExtendedInfo `json:"extendedInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + ProtectionState *string `json:"protectionState,omitempty"` + + // Fields inherited from ProtectedItem + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + BackupSetName *string `json:"backupSetName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + DeferredDeleteTimeInUTC *string `json:"deferredDeleteTimeInUTC,omitempty"` + DeferredDeleteTimeRemaining *string `json:"deferredDeleteTimeRemaining,omitempty"` + IsArchiveEnabled *bool `json:"isArchiveEnabled,omitempty"` + IsDeferredDeleteScheduleUpcoming *bool `json:"isDeferredDeleteScheduleUpcoming,omitempty"` + IsRehydrate *bool `json:"isRehydrate,omitempty"` + IsScheduledForDeferredDelete *bool `json:"isScheduledForDeferredDelete,omitempty"` + LastRecoveryPoint *string `json:"lastRecoveryPoint,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SoftDeleteRetentionPeriod *int64 `json:"softDeleteRetentionPeriod,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *DataSourceType `json:"workloadType,omitempty"` +} + +func (o *MabFileFolderProtectedItem) GetDeferredDeleteTimeInUTCAsTime() (*time.Time, error) { + if o.DeferredDeleteTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeferredDeleteTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItem) SetDeferredDeleteTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeferredDeleteTimeInUTC = &formatted +} + +func (o *MabFileFolderProtectedItem) GetLastRecoveryPointAsTime() (*time.Time, error) { + if o.LastRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItem) SetLastRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRecoveryPoint = &formatted +} + +var _ json.Marshaler = MabFileFolderProtectedItem{} + +func (s MabFileFolderProtectedItem) MarshalJSON() ([]byte, error) { + type wrapper MabFileFolderProtectedItem + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabFileFolderProtectedItem: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabFileFolderProtectedItem: %+v", err) + } + decoded["protectedItemType"] = "MabFileFolderProtectedItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabFileFolderProtectedItem: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_mabfilefolderprotecteditemextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_mabfilefolderprotecteditemextendedinfo.go new file mode 100644 index 00000000000..fbb9afca971 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_mabfilefolderprotecteditemextendedinfo.go @@ -0,0 +1,40 @@ +package protecteditems + +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 MabFileFolderProtectedItemExtendedInfo struct { + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` + OldestRecoveryPoint *string `json:"oldestRecoveryPoint,omitempty"` + RecoveryPointCount *int64 `json:"recoveryPointCount,omitempty"` +} + +func (o *MabFileFolderProtectedItemExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItemExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} + +func (o *MabFileFolderProtectedItemExtendedInfo) GetOldestRecoveryPointAsTime() (*time.Time, error) { + if o.OldestRecoveryPoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.OldestRecoveryPoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabFileFolderProtectedItemExtendedInfo) SetOldestRecoveryPointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.OldestRecoveryPoint = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_protecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_protecteditem.go new file mode 100644 index 00000000000..ff6e0bde380 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_protecteditem.go @@ -0,0 +1,144 @@ +package protecteditems + +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 ProtectedItem interface { +} + +func unmarshalProtectedItemImplementation(input []byte) (ProtectedItem, 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 ProtectedItem into map[string]interface: %+v", err) + } + + value, ok := temp["protectedItemType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareProtectedItem") { + var out AzureFileshareProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileshareProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.ClassicCompute/virtualMachines") { + var out AzureIaaSClassicComputeVMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSClassicComputeVMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Compute/virtualMachines") { + var out AzureIaaSComputeVMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSComputeVMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureIaaSVMProtectedItem") { + var out AzureIaaSVMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Sql/servers/databases") { + var out AzureSqlProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSqlProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadProtectedItem") { + var out AzureVMWorkloadProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSAPAseDatabase") { + var out AzureVMWorkloadSAPAseDatabaseProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPAseDatabaseProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSAPHanaDBInstance") { + var out AzureVMWorkloadSAPHanaDBInstanceProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaDBInstanceProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSAPHanaDatabase") { + var out AzureVMWorkloadSAPHanaDatabaseProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSAPHanaDatabaseProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureVmWorkloadSQLDatabase") { + var out AzureVMWorkloadSQLDatabaseProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadSQLDatabaseProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DPMProtectedItem") { + var out DPMProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DPMProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericProtectedItem") { + var out GenericProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericProtectedItem: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MabFileFolderProtectedItem") { + var out MabFileFolderProtectedItem + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabFileFolderProtectedItem: %+v", err) + } + return out, nil + } + + type RawProtectedItemImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectedItemImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_protecteditemresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_protecteditemresource.go new file mode 100644 index 00000000000..0541c1a67ba --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_protecteditemresource.go @@ -0,0 +1,50 @@ +package protecteditems + +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 ProtectedItemResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectedItem `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectedItemResource{} + +func (s *ProtectedItemResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectedItemResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectedItemResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectedItemResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectedItemImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectedItemResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_resourcehealthdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_resourcehealthdetails.go new file mode 100644 index 00000000000..86710207857 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/model_resourcehealthdetails.go @@ -0,0 +1,11 @@ +package protecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceHealthDetails struct { + Code *int64 `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/version.go new file mode 100644 index 00000000000..0deccdcd05a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protecteditems/version.go @@ -0,0 +1,12 @@ +package protecteditems + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/protecteditems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/README.md new file mode 100644 index 00000000000..19ddfaf1a1b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/README.md @@ -0,0 +1,105 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers` Documentation + +The `protectioncontainers` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/protectioncontainers" +``` + + +### Client Initialization + +```go +client := protectioncontainers.NewProtectionContainersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProtectionContainersClient.Get` + +```go +ctx := context.TODO() +id := protectioncontainers.NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue") + +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: `ProtectionContainersClient.Inquire` + +```go +ctx := context.TODO() +id := protectioncontainers.NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue") + +read, err := client.Inquire(ctx, id, protectioncontainers.DefaultInquireOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProtectionContainersClient.Refresh` + +```go +ctx := context.TODO() +id := protectioncontainers.NewBackupFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue") + +read, err := client.Refresh(ctx, id, protectioncontainers.DefaultRefreshOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProtectionContainersClient.Register` + +```go +ctx := context.TODO() +id := protectioncontainers.NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue") + +payload := protectioncontainers.ProtectionContainerResource{ + // ... +} + + +read, err := client.Register(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProtectionContainersClient.Unregister` + +```go +ctx := context.TODO() +id := protectioncontainers.NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue") + +read, err := client.Unregister(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/recoveryservicesbackup/2023-02-01/protectioncontainers/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/client.go new file mode 100644 index 00000000000..a3766493d9d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/client.go @@ -0,0 +1,18 @@ +package protectioncontainers + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainersClient struct { + Client autorest.Client + baseUri string +} + +func NewProtectionContainersClientWithBaseURI(endpoint string) ProtectionContainersClient { + return ProtectionContainersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/constants.go new file mode 100644 index 00000000000..db706b5bd09 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/constants.go @@ -0,0 +1,330 @@ +package protectioncontainers + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AcquireStorageAccountLock string + +const ( + AcquireStorageAccountLockAcquire AcquireStorageAccountLock = "Acquire" + AcquireStorageAccountLockNotAcquire AcquireStorageAccountLock = "NotAcquire" +) + +func PossibleValuesForAcquireStorageAccountLock() []string { + return []string{ + string(AcquireStorageAccountLockAcquire), + string(AcquireStorageAccountLockNotAcquire), + } +} + +func parseAcquireStorageAccountLock(input string) (*AcquireStorageAccountLock, error) { + vals := map[string]AcquireStorageAccountLock{ + "acquire": AcquireStorageAccountLockAcquire, + "notacquire": AcquireStorageAccountLockNotAcquire, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AcquireStorageAccountLock(input) + return &out, nil +} + +type BackupItemType string + +const ( + BackupItemTypeAzureFileShare BackupItemType = "AzureFileShare" + BackupItemTypeAzureSqlDb BackupItemType = "AzureSqlDb" + BackupItemTypeClient BackupItemType = "Client" + BackupItemTypeExchange BackupItemType = "Exchange" + BackupItemTypeFileFolder BackupItemType = "FileFolder" + BackupItemTypeGenericDataSource BackupItemType = "GenericDataSource" + BackupItemTypeInvalid BackupItemType = "Invalid" + BackupItemTypeSAPAseDatabase BackupItemType = "SAPAseDatabase" + BackupItemTypeSAPHanaDBInstance BackupItemType = "SAPHanaDBInstance" + BackupItemTypeSAPHanaDatabase BackupItemType = "SAPHanaDatabase" + BackupItemTypeSQLDB BackupItemType = "SQLDB" + BackupItemTypeSQLDataBase BackupItemType = "SQLDataBase" + BackupItemTypeSharepoint BackupItemType = "Sharepoint" + BackupItemTypeSystemState BackupItemType = "SystemState" + BackupItemTypeVM BackupItemType = "VM" + BackupItemTypeVMwareVM BackupItemType = "VMwareVM" +) + +func PossibleValuesForBackupItemType() []string { + return []string{ + string(BackupItemTypeAzureFileShare), + string(BackupItemTypeAzureSqlDb), + string(BackupItemTypeClient), + string(BackupItemTypeExchange), + string(BackupItemTypeFileFolder), + string(BackupItemTypeGenericDataSource), + string(BackupItemTypeInvalid), + string(BackupItemTypeSAPAseDatabase), + string(BackupItemTypeSAPHanaDBInstance), + string(BackupItemTypeSAPHanaDatabase), + string(BackupItemTypeSQLDB), + string(BackupItemTypeSQLDataBase), + string(BackupItemTypeSharepoint), + string(BackupItemTypeSystemState), + string(BackupItemTypeVM), + string(BackupItemTypeVMwareVM), + } +} + +func parseBackupItemType(input string) (*BackupItemType, error) { + vals := map[string]BackupItemType{ + "azurefileshare": BackupItemTypeAzureFileShare, + "azuresqldb": BackupItemTypeAzureSqlDb, + "client": BackupItemTypeClient, + "exchange": BackupItemTypeExchange, + "filefolder": BackupItemTypeFileFolder, + "genericdatasource": BackupItemTypeGenericDataSource, + "invalid": BackupItemTypeInvalid, + "sapasedatabase": BackupItemTypeSAPAseDatabase, + "saphanadbinstance": BackupItemTypeSAPHanaDBInstance, + "saphanadatabase": BackupItemTypeSAPHanaDatabase, + "sqldb": BackupItemTypeSQLDB, + "sqldatabase": BackupItemTypeSQLDataBase, + "sharepoint": BackupItemTypeSharepoint, + "systemstate": BackupItemTypeSystemState, + "vm": BackupItemTypeVM, + "vmwarevm": BackupItemTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupItemType(input) + return &out, nil +} + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type OperationType string + +const ( + OperationTypeInvalid OperationType = "Invalid" + OperationTypeRegister OperationType = "Register" + OperationTypeReregister OperationType = "Reregister" +) + +func PossibleValuesForOperationType() []string { + return []string{ + string(OperationTypeInvalid), + string(OperationTypeRegister), + string(OperationTypeReregister), + } +} + +func parseOperationType(input string) (*OperationType, error) { + vals := map[string]OperationType{ + "invalid": OperationTypeInvalid, + "register": OperationTypeRegister, + "reregister": OperationTypeReregister, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationType(input) + return &out, nil +} + +type ProtectableContainerType string + +const ( + ProtectableContainerTypeAzureBackupServerContainer ProtectableContainerType = "AzureBackupServerContainer" + ProtectableContainerTypeAzureSqlContainer ProtectableContainerType = "AzureSqlContainer" + ProtectableContainerTypeAzureWorkloadContainer ProtectableContainerType = "AzureWorkloadContainer" + ProtectableContainerTypeCluster ProtectableContainerType = "Cluster" + ProtectableContainerTypeDPMContainer ProtectableContainerType = "DPMContainer" + ProtectableContainerTypeGenericContainer ProtectableContainerType = "GenericContainer" + ProtectableContainerTypeIaasVMContainer ProtectableContainerType = "IaasVMContainer" + ProtectableContainerTypeIaasVMServiceContainer ProtectableContainerType = "IaasVMServiceContainer" + ProtectableContainerTypeInvalid ProtectableContainerType = "Invalid" + ProtectableContainerTypeMABContainer ProtectableContainerType = "MABContainer" + ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines ProtectableContainerType = "Microsoft.ClassicCompute/virtualMachines" + ProtectableContainerTypeMicrosoftPointComputeVirtualMachines ProtectableContainerType = "Microsoft.Compute/virtualMachines" + ProtectableContainerTypeSQLAGWorkLoadContainer ProtectableContainerType = "SQLAGWorkLoadContainer" + ProtectableContainerTypeStorageContainer ProtectableContainerType = "StorageContainer" + ProtectableContainerTypeUnknown ProtectableContainerType = "Unknown" + ProtectableContainerTypeVCenter ProtectableContainerType = "VCenter" + ProtectableContainerTypeVMAppContainer ProtectableContainerType = "VMAppContainer" + ProtectableContainerTypeWindows ProtectableContainerType = "Windows" +) + +func PossibleValuesForProtectableContainerType() []string { + return []string{ + string(ProtectableContainerTypeAzureBackupServerContainer), + string(ProtectableContainerTypeAzureSqlContainer), + string(ProtectableContainerTypeAzureWorkloadContainer), + string(ProtectableContainerTypeCluster), + string(ProtectableContainerTypeDPMContainer), + string(ProtectableContainerTypeGenericContainer), + string(ProtectableContainerTypeIaasVMContainer), + string(ProtectableContainerTypeIaasVMServiceContainer), + string(ProtectableContainerTypeInvalid), + string(ProtectableContainerTypeMABContainer), + string(ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines), + string(ProtectableContainerTypeMicrosoftPointComputeVirtualMachines), + string(ProtectableContainerTypeSQLAGWorkLoadContainer), + string(ProtectableContainerTypeStorageContainer), + string(ProtectableContainerTypeUnknown), + string(ProtectableContainerTypeVCenter), + string(ProtectableContainerTypeVMAppContainer), + string(ProtectableContainerTypeWindows), + } +} + +func parseProtectableContainerType(input string) (*ProtectableContainerType, error) { + vals := map[string]ProtectableContainerType{ + "azurebackupservercontainer": ProtectableContainerTypeAzureBackupServerContainer, + "azuresqlcontainer": ProtectableContainerTypeAzureSqlContainer, + "azureworkloadcontainer": ProtectableContainerTypeAzureWorkloadContainer, + "cluster": ProtectableContainerTypeCluster, + "dpmcontainer": ProtectableContainerTypeDPMContainer, + "genericcontainer": ProtectableContainerTypeGenericContainer, + "iaasvmcontainer": ProtectableContainerTypeIaasVMContainer, + "iaasvmservicecontainer": ProtectableContainerTypeIaasVMServiceContainer, + "invalid": ProtectableContainerTypeInvalid, + "mabcontainer": ProtectableContainerTypeMABContainer, + "microsoft.classiccompute/virtualmachines": ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines, + "microsoft.compute/virtualmachines": ProtectableContainerTypeMicrosoftPointComputeVirtualMachines, + "sqlagworkloadcontainer": ProtectableContainerTypeSQLAGWorkLoadContainer, + "storagecontainer": ProtectableContainerTypeStorageContainer, + "unknown": ProtectableContainerTypeUnknown, + "vcenter": ProtectableContainerTypeVCenter, + "vmappcontainer": ProtectableContainerTypeVMAppContainer, + "windows": ProtectableContainerTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectableContainerType(input) + return &out, nil +} + +type WorkloadType string + +const ( + WorkloadTypeAzureFileShare WorkloadType = "AzureFileShare" + WorkloadTypeAzureSqlDb WorkloadType = "AzureSqlDb" + WorkloadTypeClient WorkloadType = "Client" + WorkloadTypeExchange WorkloadType = "Exchange" + WorkloadTypeFileFolder WorkloadType = "FileFolder" + WorkloadTypeGenericDataSource WorkloadType = "GenericDataSource" + WorkloadTypeInvalid WorkloadType = "Invalid" + WorkloadTypeSAPAseDatabase WorkloadType = "SAPAseDatabase" + WorkloadTypeSAPHanaDBInstance WorkloadType = "SAPHanaDBInstance" + WorkloadTypeSAPHanaDatabase WorkloadType = "SAPHanaDatabase" + WorkloadTypeSQLDB WorkloadType = "SQLDB" + WorkloadTypeSQLDataBase WorkloadType = "SQLDataBase" + WorkloadTypeSharepoint WorkloadType = "Sharepoint" + WorkloadTypeSystemState WorkloadType = "SystemState" + WorkloadTypeVM WorkloadType = "VM" + WorkloadTypeVMwareVM WorkloadType = "VMwareVM" +) + +func PossibleValuesForWorkloadType() []string { + return []string{ + string(WorkloadTypeAzureFileShare), + string(WorkloadTypeAzureSqlDb), + string(WorkloadTypeClient), + string(WorkloadTypeExchange), + string(WorkloadTypeFileFolder), + string(WorkloadTypeGenericDataSource), + string(WorkloadTypeInvalid), + string(WorkloadTypeSAPAseDatabase), + string(WorkloadTypeSAPHanaDBInstance), + string(WorkloadTypeSAPHanaDatabase), + string(WorkloadTypeSQLDB), + string(WorkloadTypeSQLDataBase), + string(WorkloadTypeSharepoint), + string(WorkloadTypeSystemState), + string(WorkloadTypeVM), + string(WorkloadTypeVMwareVM), + } +} + +func parseWorkloadType(input string) (*WorkloadType, error) { + vals := map[string]WorkloadType{ + "azurefileshare": WorkloadTypeAzureFileShare, + "azuresqldb": WorkloadTypeAzureSqlDb, + "client": WorkloadTypeClient, + "exchange": WorkloadTypeExchange, + "filefolder": WorkloadTypeFileFolder, + "genericdatasource": WorkloadTypeGenericDataSource, + "invalid": WorkloadTypeInvalid, + "sapasedatabase": WorkloadTypeSAPAseDatabase, + "saphanadbinstance": WorkloadTypeSAPHanaDBInstance, + "saphanadatabase": WorkloadTypeSAPHanaDatabase, + "sqldb": WorkloadTypeSQLDB, + "sqldatabase": WorkloadTypeSQLDataBase, + "sharepoint": WorkloadTypeSharepoint, + "systemstate": WorkloadTypeSystemState, + "vm": WorkloadTypeVM, + "vmwarevm": WorkloadTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkloadType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_backupfabric.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_backupfabric.go new file mode 100644 index 00000000000..4ff2c3ffd69 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_backupfabric.go @@ -0,0 +1,140 @@ +package protectioncontainers + +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 = BackupFabricId{} + +// BackupFabricId is a struct representing the Resource ID for a Backup Fabric +type BackupFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string +} + +// NewBackupFabricID returns a new BackupFabricId struct +func NewBackupFabricID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string) BackupFabricId { + return BackupFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + } +} + +// ParseBackupFabricID parses 'input' into a BackupFabricId +func ParseBackupFabricID(input string) (*BackupFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseBackupFabricIDInsensitively parses 'input' case-insensitively into a BackupFabricId +// note: this method should only be used for API response data and not user input +func ParseBackupFabricIDInsensitively(input string) (*BackupFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateBackupFabricID checks that 'input' can be parsed as a Backup Fabric ID +func ValidateBackupFabricID(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 := ParseBackupFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Fabric ID +func (id BackupFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Fabric ID +func (id BackupFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + } +} + +// String returns a human-readable description of this Backup Fabric ID +func (id BackupFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + } + return fmt.Sprintf("Backup Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_backupfabric_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_backupfabric_test.go new file mode 100644 index 00000000000..89bc092cec1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_backupfabric_test.go @@ -0,0 +1,327 @@ +package protectioncontainers + +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 = BackupFabricId{} + +func TestNewBackupFabricID(t *testing.T) { + id := NewBackupFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } +} + +func TestFormatBackupFabricID(t *testing.T) { + actual := NewBackupFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Expected: &BackupFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + } +} + +func TestParseBackupFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Expected: &BackupFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Expected: &BackupFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + } +} + +func TestSegmentsForBackupFabricId(t *testing.T) { + segments := BackupFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupFabricId 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/recoveryservicesbackup/2023-02-01/protectioncontainers/id_protectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_protectioncontainer.go new file mode 100644 index 00000000000..aed7a37ee36 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_protectioncontainer.go @@ -0,0 +1,153 @@ +package protectioncontainers + +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 = ProtectionContainerId{} + +// ProtectionContainerId is a struct representing the Resource ID for a Protection Container +type ProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string + ProtectionContainerName string +} + +// NewProtectionContainerID returns a new ProtectionContainerId struct +func NewProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string) ProtectionContainerId { + return ProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + } +} + +// ParseProtectionContainerID parses 'input' into a ProtectionContainerId +func ParseProtectionContainerID(input string) (*ProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProtectionContainerIDInsensitively parses 'input' case-insensitively into a ProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseProtectionContainerIDInsensitively(input string) (*ProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProtectionContainerID checks that 'input' can be parsed as a Protection Container ID +func ValidateProtectionContainerID(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 := ParseProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Protection Container ID +func (id ProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Protection Container ID +func (id ProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + } +} + +// String returns a human-readable description of this Protection Container ID +func (id ProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + } + return fmt.Sprintf("Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_protectioncontainer_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_protectioncontainer_test.go new file mode 100644 index 00000000000..5ae5077a787 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/id_protectioncontainer_test.go @@ -0,0 +1,372 @@ +package protectioncontainers + +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 = ProtectionContainerId{} + +func TestNewProtectionContainerID(t *testing.T) { + id := NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } +} + +func TestFormatProtectionContainerID(t *testing.T) { + actual := NewProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProtectionContainerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Expected: &ProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectionContainerID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + } +} + +func TestParseProtectionContainerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Expected: &ProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Expected: &ProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectionContainerIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + } +} + +func TestSegmentsForProtectionContainerId(t *testing.T) { + segments := ProtectionContainerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProtectionContainerId 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/recoveryservicesbackup/2023-02-01/protectioncontainers/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_get_autorest.go new file mode 100644 index 00000000000..07d4c710143 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_get_autorest.go @@ -0,0 +1,68 @@ +package protectioncontainers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionContainerResource +} + +// Get ... +func (c ProtectionContainersClient) Get(ctx context.Context, id ProtectionContainerId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ProtectionContainersClient) preparerForGet(ctx context.Context, id ProtectionContainerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ProtectionContainersClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_inquire_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_inquire_autorest.go new file mode 100644 index 00000000000..fb85971bffd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_inquire_autorest.go @@ -0,0 +1,96 @@ +package protectioncontainers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InquireOperationResponse struct { + HttpResponse *http.Response +} + +type InquireOperationOptions struct { + Filter *string +} + +func DefaultInquireOperationOptions() InquireOperationOptions { + return InquireOperationOptions{} +} + +func (o InquireOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o InquireOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// Inquire ... +func (c ProtectionContainersClient) Inquire(ctx context.Context, id ProtectionContainerId, options InquireOperationOptions) (result InquireOperationResponse, err error) { + req, err := c.preparerForInquire(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Inquire", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Inquire", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForInquire(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Inquire", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForInquire prepares the Inquire request. +func (c ProtectionContainersClient) preparerForInquire(ctx context.Context, id ProtectionContainerId, options InquireOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/inquire", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForInquire handles the response to the Inquire request. The method always +// closes the http.Response Body. +func (c ProtectionContainersClient) responderForInquire(resp *http.Response) (result InquireOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_refresh_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_refresh_autorest.go new file mode 100644 index 00000000000..2b4984af995 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_refresh_autorest.go @@ -0,0 +1,96 @@ +package protectioncontainers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshOperationResponse struct { + HttpResponse *http.Response +} + +type RefreshOperationOptions struct { + Filter *string +} + +func DefaultRefreshOperationOptions() RefreshOperationOptions { + return RefreshOperationOptions{} +} + +func (o RefreshOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o RefreshOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// Refresh ... +func (c ProtectionContainersClient) Refresh(ctx context.Context, id BackupFabricId, options RefreshOperationOptions) (result RefreshOperationResponse, err error) { + req, err := c.preparerForRefresh(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Refresh", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Refresh", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForRefresh(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Refresh", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForRefresh prepares the Refresh request. +func (c ProtectionContainersClient) preparerForRefresh(ctx context.Context, id BackupFabricId, options RefreshOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/refreshContainers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForRefresh handles the response to the Refresh request. The method always +// closes the http.Response Body. +func (c ProtectionContainersClient) responderForRefresh(resp *http.Response) (result RefreshOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_register_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_register_autorest.go new file mode 100644 index 00000000000..30b79c94a5e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_register_autorest.go @@ -0,0 +1,69 @@ +package protectioncontainers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegisterOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionContainerResource +} + +// Register ... +func (c ProtectionContainersClient) Register(ctx context.Context, id ProtectionContainerId, input ProtectionContainerResource) (result RegisterOperationResponse, err error) { + req, err := c.preparerForRegister(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Register", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Register", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForRegister(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Register", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForRegister prepares the Register request. +func (c ProtectionContainersClient) preparerForRegister(ctx context.Context, id ProtectionContainerId, input ProtectionContainerResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForRegister handles the response to the Register request. The method always +// closes the http.Response Body. +func (c ProtectionContainersClient) responderForRegister(resp *http.Response) (result RegisterOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_unregister_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_unregister_autorest.go new file mode 100644 index 00000000000..cf4fbebe128 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/method_unregister_autorest.go @@ -0,0 +1,66 @@ +package protectioncontainers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnregisterOperationResponse struct { + HttpResponse *http.Response +} + +// Unregister ... +func (c ProtectionContainersClient) Unregister(ctx context.Context, id ProtectionContainerId) (result UnregisterOperationResponse, err error) { + req, err := c.preparerForUnregister(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Unregister", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Unregister", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUnregister(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectioncontainers.ProtectionContainersClient", "Unregister", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUnregister prepares the Unregister request. +func (c ProtectionContainersClient) preparerForUnregister(ctx context.Context, id ProtectionContainerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUnregister handles the response to the Unregister request. The method always +// closes the http.Response Body. +func (c ProtectionContainersClient) responderForUnregister(resp *http.Response) (result UnregisterOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted, http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurebackupservercontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurebackupservercontainer.go new file mode 100644 index 00000000000..1c21d8906f9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurebackupservercontainer.go @@ -0,0 +1,53 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureBackupServerContainer{} + +type AzureBackupServerContainer struct { + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + DpmAgentVersion *string `json:"dpmAgentVersion,omitempty"` + DpmServers *[]string `json:"dpmServers,omitempty"` + ExtendedInfo *DPMContainerExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + UpgradeAvailable *bool `json:"upgradeAvailable,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureBackupServerContainer{} + +func (s AzureBackupServerContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupServerContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupServerContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupServerContainer: %+v", err) + } + decoded["containerType"] = "AzureBackupServerContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupServerContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureiaasclassiccomputevmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureiaasclassiccomputevmcontainer.go new file mode 100644 index 00000000000..b8a8c17717e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureiaasclassiccomputevmcontainer.go @@ -0,0 +1,48 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureIaaSClassicComputeVMContainer{} + +type AzureIaaSClassicComputeVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureIaaSClassicComputeVMContainer{} + +func (s AzureIaaSClassicComputeVMContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSClassicComputeVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + decoded["containerType"] = "Microsoft.ClassicCompute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureiaascomputevmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureiaascomputevmcontainer.go new file mode 100644 index 00000000000..c66beff2ce0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureiaascomputevmcontainer.go @@ -0,0 +1,48 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureIaaSComputeVMContainer{} + +type AzureIaaSComputeVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureIaaSComputeVMContainer{} + +func (s AzureIaaSComputeVMContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSComputeVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSComputeVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSComputeVMContainer: %+v", err) + } + decoded["containerType"] = "Microsoft.Compute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSComputeVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go new file mode 100644 index 00000000000..7e0a1ed3e94 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go @@ -0,0 +1,50 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureSQLAGWorkloadContainerProtectionContainer{} + +type AzureSQLAGWorkloadContainerProtectionContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureSQLAGWorkloadContainerProtectionContainer{} + +func (s AzureSQLAGWorkloadContainerProtectionContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureSQLAGWorkloadContainerProtectionContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + decoded["containerType"] = "SQLAGWorkLoadContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azuresqlcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azuresqlcontainer.go new file mode 100644 index 00000000000..cd29b673055 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azuresqlcontainer.go @@ -0,0 +1,45 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureSqlContainer{} + +type AzureSqlContainer struct { + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureSqlContainer{} + +func (s AzureSqlContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureSqlContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSqlContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSqlContainer: %+v", err) + } + decoded["containerType"] = "AzureSqlContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSqlContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurestoragecontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurestoragecontainer.go new file mode 100644 index 00000000000..fc4de5fe940 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurestoragecontainer.go @@ -0,0 +1,50 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureStorageContainer{} + +type AzureStorageContainer struct { + AcquireStorageAccountLock *AcquireStorageAccountLock `json:"acquireStorageAccountLock,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ResourceGroup *string `json:"resourceGroup,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountVersion *string `json:"storageAccountVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureStorageContainer{} + +func (s AzureStorageContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureStorageContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureStorageContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureStorageContainer: %+v", err) + } + decoded["containerType"] = "StorageContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureStorageContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurevmappcontainerprotectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurevmappcontainerprotectioncontainer.go new file mode 100644 index 00000000000..97d2dbf49f8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azurevmappcontainerprotectioncontainer.go @@ -0,0 +1,50 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureVMAppContainerProtectionContainer{} + +type AzureVMAppContainerProtectionContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureVMAppContainerProtectionContainer{} + +func (s AzureVMAppContainerProtectionContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureVMAppContainerProtectionContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + decoded["containerType"] = "VMAppContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureworkloadcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureworkloadcontainer.go new file mode 100644 index 00000000000..79290339156 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureworkloadcontainer.go @@ -0,0 +1,50 @@ +package protectioncontainers + +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 _ ProtectionContainer = AzureWorkloadContainer{} + +type AzureWorkloadContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureWorkloadContainer{} + +func (s AzureWorkloadContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadContainer: %+v", err) + } + decoded["containerType"] = "AzureWorkloadContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureworkloadcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureworkloadcontainerextendedinfo.go new file mode 100644 index 00000000000..3306d7014ef --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_azureworkloadcontainerextendedinfo.go @@ -0,0 +1,10 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadContainerExtendedInfo struct { + HostServerName *string `json:"hostServerName,omitempty"` + InquiryInfo *InquiryInfo `json:"inquiryInfo,omitempty"` + NodesList *[]DistributedNodesInfo `json:"nodesList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_containeridentityinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_containeridentityinfo.go new file mode 100644 index 00000000000..2a757b599d6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_containeridentityinfo.go @@ -0,0 +1,11 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerIdentityInfo struct { + AadTenantId *string `json:"aadTenantId,omitempty"` + Audience *string `json:"audience,omitempty"` + ServicePrincipalClientId *string `json:"servicePrincipalClientId,omitempty"` + UniqueName *string `json:"uniqueName,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_distributednodesinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_distributednodesinfo.go new file mode 100644 index 00000000000..96186902d6a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_distributednodesinfo.go @@ -0,0 +1,10 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedNodesInfo struct { + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + NodeName *string `json:"nodeName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_dpmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_dpmcontainer.go new file mode 100644 index 00000000000..d35b9a9844d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_dpmcontainer.go @@ -0,0 +1,53 @@ +package protectioncontainers + +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 _ ProtectionContainer = DpmContainer{} + +type DpmContainer struct { + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + DpmAgentVersion *string `json:"dpmAgentVersion,omitempty"` + DpmServers *[]string `json:"dpmServers,omitempty"` + ExtendedInfo *DPMContainerExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + UpgradeAvailable *bool `json:"upgradeAvailable,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = DpmContainer{} + +func (s DpmContainer) MarshalJSON() ([]byte, error) { + type wrapper DpmContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DpmContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DpmContainer: %+v", err) + } + decoded["containerType"] = "DPMContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DpmContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_dpmcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_dpmcontainerextendedinfo.go new file mode 100644 index 00000000000..608a1ba48f9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_dpmcontainerextendedinfo.go @@ -0,0 +1,26 @@ +package protectioncontainers + +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 DPMContainerExtendedInfo struct { + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` +} + +func (o *DPMContainerExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMContainerExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_errordetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_errordetail.go new file mode 100644 index 00000000000..6eac856c404 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_errordetail.go @@ -0,0 +1,10 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_genericcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_genericcontainer.go new file mode 100644 index 00000000000..45b661347c1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_genericcontainer.go @@ -0,0 +1,47 @@ +package protectioncontainers + +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 _ ProtectionContainer = GenericContainer{} + +type GenericContainer struct { + ExtendedInformation *GenericContainerExtendedInfo `json:"extendedInformation,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = GenericContainer{} + +func (s GenericContainer) MarshalJSON() ([]byte, error) { + type wrapper GenericContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericContainer: %+v", err) + } + decoded["containerType"] = "GenericContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_genericcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_genericcontainerextendedinfo.go new file mode 100644 index 00000000000..6d1b2f49b6b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_genericcontainerextendedinfo.go @@ -0,0 +1,10 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericContainerExtendedInfo struct { + ContainerIdentityInfo *ContainerIdentityInfo `json:"containerIdentityInfo,omitempty"` + RawCertData *string `json:"rawCertData,omitempty"` + ServiceEndpoints *map[string]string `json:"serviceEndpoints,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_iaasvmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_iaasvmcontainer.go new file mode 100644 index 00000000000..e0a2bd35149 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_iaasvmcontainer.go @@ -0,0 +1,48 @@ +package protectioncontainers + +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 _ ProtectionContainer = IaaSVMContainer{} + +type IaaSVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = IaaSVMContainer{} + +func (s IaaSVMContainer) MarshalJSON() ([]byte, error) { + type wrapper IaaSVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaaSVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaaSVMContainer: %+v", err) + } + decoded["containerType"] = "IaasVMContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaaSVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_inquiryinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_inquiryinfo.go new file mode 100644 index 00000000000..53bfc1db911 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_inquiryinfo.go @@ -0,0 +1,10 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InquiryInfo struct { + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + InquiryDetails *[]WorkloadInquiryDetails `json:"inquiryDetails,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_inquiryvalidation.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_inquiryvalidation.go new file mode 100644 index 00000000000..ab89a15d5ec --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_inquiryvalidation.go @@ -0,0 +1,10 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InquiryValidation struct { + AdditionalDetail *string `json:"additionalDetail,omitempty"` + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainer.go new file mode 100644 index 00000000000..b2d5eb97307 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainer.go @@ -0,0 +1,52 @@ +package protectioncontainers + +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 _ ProtectionContainer = MabContainer{} + +type MabContainer struct { + AgentVersion *string `json:"agentVersion,omitempty"` + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerHealthState *string `json:"containerHealthState,omitempty"` + ContainerId *int64 `json:"containerId,omitempty"` + ExtendedInfo *MabContainerExtendedInfo `json:"extendedInfo,omitempty"` + MabContainerHealthDetails *[]MABContainerHealthDetails `json:"mabContainerHealthDetails,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = MabContainer{} + +func (s MabContainer) MarshalJSON() ([]byte, error) { + type wrapper MabContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabContainer: %+v", err) + } + decoded["containerType"] = "Windows" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainerextendedinfo.go new file mode 100644 index 00000000000..82aeca609c6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainerextendedinfo.go @@ -0,0 +1,30 @@ +package protectioncontainers + +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 MabContainerExtendedInfo struct { + BackupItemType *BackupItemType `json:"backupItemType,omitempty"` + BackupItems *[]string `json:"backupItems,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` + PolicyName *string `json:"policyName,omitempty"` +} + +func (o *MabContainerExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabContainerExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainerhealthdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainerhealthdetails.go new file mode 100644 index 00000000000..1bc3a807285 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_mabcontainerhealthdetails.go @@ -0,0 +1,11 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MABContainerHealthDetails struct { + Code *int64 `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_protectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_protectioncontainer.go new file mode 100644 index 00000000000..b7edc7f494d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_protectioncontainer.go @@ -0,0 +1,136 @@ +package protectioncontainers + +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 ProtectionContainer interface { +} + +func unmarshalProtectionContainerImplementation(input []byte) (ProtectionContainer, 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 ProtectionContainer into map[string]interface: %+v", err) + } + + value, ok := temp["containerType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupServerContainer") { + var out AzureBackupServerContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupServerContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.ClassicCompute/virtualMachines") { + var out AzureIaaSClassicComputeVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSClassicComputeVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Compute/virtualMachines") { + var out AzureIaaSComputeVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSComputeVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLAGWorkLoadContainer") { + var out AzureSQLAGWorkloadContainerProtectionContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureSqlContainer") { + var out AzureSqlContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSqlContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StorageContainer") { + var out AzureStorageContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureStorageContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMAppContainer") { + var out AzureVMAppContainerProtectionContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMAppContainerProtectionContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadContainer") { + var out AzureWorkloadContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DPMContainer") { + var out DpmContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DpmContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericContainer") { + var out GenericContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMContainer") { + var out IaaSVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaaSVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Windows") { + var out MabContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabContainer: %+v", err) + } + return out, nil + } + + type RawProtectionContainerImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionContainerImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_protectioncontainerresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_protectioncontainerresource.go new file mode 100644 index 00000000000..4de75e08602 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_protectioncontainerresource.go @@ -0,0 +1,50 @@ +package protectioncontainers + +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 ProtectionContainerResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectionContainer `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionContainerResource{} + +func (s *ProtectionContainerResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectionContainerResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionContainerResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionContainerResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectionContainerImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectionContainerResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_workloadinquirydetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_workloadinquirydetails.go new file mode 100644 index 00000000000..1e9d1413743 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/model_workloadinquirydetails.go @@ -0,0 +1,10 @@ +package protectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadInquiryDetails struct { + InquiryValidation *InquiryValidation `json:"inquiryValidation,omitempty"` + ItemCount *int64 `json:"itemCount,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/version.go new file mode 100644 index 00000000000..5d75369eaaf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectioncontainers/version.go @@ -0,0 +1,12 @@ +package protectioncontainers + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/protectioncontainers/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/README.md new file mode 100644 index 00000000000..677d2139d73 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/README.md @@ -0,0 +1,94 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent` Documentation + +The `protectionintent` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/protectionintent" +``` + + +### Client Initialization + +```go +client := protectionintent.NewProtectionIntentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProtectionIntentClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := protectionintent.NewBackupProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "backupProtectionIntentValue") + +payload := protectionintent.ProtectionIntentResource{ + // ... +} + + +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: `ProtectionIntentClient.Delete` + +```go +ctx := context.TODO() +id := protectionintent.NewBackupProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "backupProtectionIntentValue") + +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: `ProtectionIntentClient.Get` + +```go +ctx := context.TODO() +id := protectionintent.NewBackupProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "backupProtectionIntentValue") + +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: `ProtectionIntentClient.Validate` + +```go +ctx := context.TODO() +id := protectionintent.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := protectionintent.PreValidateEnableBackupRequest{ + // ... +} + + +read, err := client.Validate(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/recoveryservicesbackup/2023-02-01/protectionintent/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/client.go new file mode 100644 index 00000000000..0ffe385d61d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/client.go @@ -0,0 +1,18 @@ +package protectionintent + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionIntentClient struct { + Client autorest.Client + baseUri string +} + +func NewProtectionIntentClientWithBaseURI(endpoint string) ProtectionIntentClient { + return ProtectionIntentClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/constants.go new file mode 100644 index 00000000000..0632d6a13ce --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/constants.go @@ -0,0 +1,233 @@ +package protectionintent + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type DataSourceType string + +const ( + DataSourceTypeAzureFileShare DataSourceType = "AzureFileShare" + DataSourceTypeAzureSqlDb DataSourceType = "AzureSqlDb" + DataSourceTypeClient DataSourceType = "Client" + DataSourceTypeExchange DataSourceType = "Exchange" + DataSourceTypeFileFolder DataSourceType = "FileFolder" + DataSourceTypeGenericDataSource DataSourceType = "GenericDataSource" + DataSourceTypeInvalid DataSourceType = "Invalid" + DataSourceTypeSAPAseDatabase DataSourceType = "SAPAseDatabase" + DataSourceTypeSAPHanaDBInstance DataSourceType = "SAPHanaDBInstance" + DataSourceTypeSAPHanaDatabase DataSourceType = "SAPHanaDatabase" + DataSourceTypeSQLDB DataSourceType = "SQLDB" + DataSourceTypeSQLDataBase DataSourceType = "SQLDataBase" + DataSourceTypeSharepoint DataSourceType = "Sharepoint" + DataSourceTypeSystemState DataSourceType = "SystemState" + DataSourceTypeVM DataSourceType = "VM" + DataSourceTypeVMwareVM DataSourceType = "VMwareVM" +) + +func PossibleValuesForDataSourceType() []string { + return []string{ + string(DataSourceTypeAzureFileShare), + string(DataSourceTypeAzureSqlDb), + string(DataSourceTypeClient), + string(DataSourceTypeExchange), + string(DataSourceTypeFileFolder), + string(DataSourceTypeGenericDataSource), + string(DataSourceTypeInvalid), + string(DataSourceTypeSAPAseDatabase), + string(DataSourceTypeSAPHanaDBInstance), + string(DataSourceTypeSAPHanaDatabase), + string(DataSourceTypeSQLDB), + string(DataSourceTypeSQLDataBase), + string(DataSourceTypeSharepoint), + string(DataSourceTypeSystemState), + string(DataSourceTypeVM), + string(DataSourceTypeVMwareVM), + } +} + +func parseDataSourceType(input string) (*DataSourceType, error) { + vals := map[string]DataSourceType{ + "azurefileshare": DataSourceTypeAzureFileShare, + "azuresqldb": DataSourceTypeAzureSqlDb, + "client": DataSourceTypeClient, + "exchange": DataSourceTypeExchange, + "filefolder": DataSourceTypeFileFolder, + "genericdatasource": DataSourceTypeGenericDataSource, + "invalid": DataSourceTypeInvalid, + "sapasedatabase": DataSourceTypeSAPAseDatabase, + "saphanadbinstance": DataSourceTypeSAPHanaDBInstance, + "saphanadatabase": DataSourceTypeSAPHanaDatabase, + "sqldb": DataSourceTypeSQLDB, + "sqldatabase": DataSourceTypeSQLDataBase, + "sharepoint": DataSourceTypeSharepoint, + "systemstate": DataSourceTypeSystemState, + "vm": DataSourceTypeVM, + "vmwarevm": DataSourceTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataSourceType(input) + return &out, nil +} + +type ProtectionIntentItemType string + +const ( + ProtectionIntentItemTypeAzureResourceItem ProtectionIntentItemType = "AzureResourceItem" + ProtectionIntentItemTypeAzureWorkloadAutoProtectionIntent ProtectionIntentItemType = "AzureWorkloadAutoProtectionIntent" + ProtectionIntentItemTypeAzureWorkloadContainerAutoProtectionIntent ProtectionIntentItemType = "AzureWorkloadContainerAutoProtectionIntent" + ProtectionIntentItemTypeAzureWorkloadSQLAutoProtectionIntent ProtectionIntentItemType = "AzureWorkloadSQLAutoProtectionIntent" + ProtectionIntentItemTypeInvalid ProtectionIntentItemType = "Invalid" + ProtectionIntentItemTypeRecoveryServiceVaultItem ProtectionIntentItemType = "RecoveryServiceVaultItem" +) + +func PossibleValuesForProtectionIntentItemType() []string { + return []string{ + string(ProtectionIntentItemTypeAzureResourceItem), + string(ProtectionIntentItemTypeAzureWorkloadAutoProtectionIntent), + string(ProtectionIntentItemTypeAzureWorkloadContainerAutoProtectionIntent), + string(ProtectionIntentItemTypeAzureWorkloadSQLAutoProtectionIntent), + string(ProtectionIntentItemTypeInvalid), + string(ProtectionIntentItemTypeRecoveryServiceVaultItem), + } +} + +func parseProtectionIntentItemType(input string) (*ProtectionIntentItemType, error) { + vals := map[string]ProtectionIntentItemType{ + "azureresourceitem": ProtectionIntentItemTypeAzureResourceItem, + "azureworkloadautoprotectionintent": ProtectionIntentItemTypeAzureWorkloadAutoProtectionIntent, + "azureworkloadcontainerautoprotectionintent": ProtectionIntentItemTypeAzureWorkloadContainerAutoProtectionIntent, + "azureworkloadsqlautoprotectionintent": ProtectionIntentItemTypeAzureWorkloadSQLAutoProtectionIntent, + "invalid": ProtectionIntentItemTypeInvalid, + "recoveryservicevaultitem": ProtectionIntentItemTypeRecoveryServiceVaultItem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionIntentItemType(input) + return &out, nil +} + +type ProtectionStatus string + +const ( + ProtectionStatusInvalid ProtectionStatus = "Invalid" + ProtectionStatusNotProtected ProtectionStatus = "NotProtected" + ProtectionStatusProtected ProtectionStatus = "Protected" + ProtectionStatusProtecting ProtectionStatus = "Protecting" + ProtectionStatusProtectionFailed ProtectionStatus = "ProtectionFailed" +) + +func PossibleValuesForProtectionStatus() []string { + return []string{ + string(ProtectionStatusInvalid), + string(ProtectionStatusNotProtected), + string(ProtectionStatusProtected), + string(ProtectionStatusProtecting), + string(ProtectionStatusProtectionFailed), + } +} + +func parseProtectionStatus(input string) (*ProtectionStatus, error) { + vals := map[string]ProtectionStatus{ + "invalid": ProtectionStatusInvalid, + "notprotected": ProtectionStatusNotProtected, + "protected": ProtectionStatusProtected, + "protecting": ProtectionStatusProtecting, + "protectionfailed": ProtectionStatusProtectionFailed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionStatus(input) + return &out, nil +} + +type ValidationStatus string + +const ( + ValidationStatusFailed ValidationStatus = "Failed" + ValidationStatusInvalid ValidationStatus = "Invalid" + ValidationStatusSucceeded ValidationStatus = "Succeeded" +) + +func PossibleValuesForValidationStatus() []string { + return []string{ + string(ValidationStatusFailed), + string(ValidationStatusInvalid), + string(ValidationStatusSucceeded), + } +} + +func parseValidationStatus(input string) (*ValidationStatus, error) { + vals := map[string]ValidationStatus{ + "failed": ValidationStatusFailed, + "invalid": ValidationStatusInvalid, + "succeeded": ValidationStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ValidationStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_backupprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_backupprotectionintent.go new file mode 100644 index 00000000000..c684b983634 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_backupprotectionintent.go @@ -0,0 +1,153 @@ +package protectionintent + +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 = BackupProtectionIntentId{} + +// BackupProtectionIntentId is a struct representing the Resource ID for a Backup Protection Intent +type BackupProtectionIntentId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string + BackupProtectionIntentName string +} + +// NewBackupProtectionIntentID returns a new BackupProtectionIntentId struct +func NewBackupProtectionIntentID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, backupProtectionIntentName string) BackupProtectionIntentId { + return BackupProtectionIntentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + BackupProtectionIntentName: backupProtectionIntentName, + } +} + +// ParseBackupProtectionIntentID parses 'input' into a BackupProtectionIntentId +func ParseBackupProtectionIntentID(input string) (*BackupProtectionIntentId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupProtectionIntentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupProtectionIntentId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.BackupProtectionIntentName, ok = parsed.Parsed["backupProtectionIntentName"]; !ok { + return nil, fmt.Errorf("the segment 'backupProtectionIntentName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseBackupProtectionIntentIDInsensitively parses 'input' case-insensitively into a BackupProtectionIntentId +// note: this method should only be used for API response data and not user input +func ParseBackupProtectionIntentIDInsensitively(input string) (*BackupProtectionIntentId, error) { + parser := resourceids.NewParserFromResourceIdType(BackupProtectionIntentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BackupProtectionIntentId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.BackupProtectionIntentName, ok = parsed.Parsed["backupProtectionIntentName"]; !ok { + return nil, fmt.Errorf("the segment 'backupProtectionIntentName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateBackupProtectionIntentID checks that 'input' can be parsed as a Backup Protection Intent ID +func ValidateBackupProtectionIntentID(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 := ParseBackupProtectionIntentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Protection Intent ID +func (id BackupProtectionIntentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s/backupProtectionIntent/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.BackupProtectionIntentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Protection Intent ID +func (id BackupProtectionIntentId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticBackupProtectionIntent", "backupProtectionIntent", "backupProtectionIntent"), + resourceids.UserSpecifiedSegment("backupProtectionIntentName", "backupProtectionIntentValue"), + } +} + +// String returns a human-readable description of this Backup Protection Intent ID +func (id BackupProtectionIntentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Backup Protection Intent Name: %q", id.BackupProtectionIntentName), + } + return fmt.Sprintf("Backup Protection Intent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_backupprotectionintent_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_backupprotectionintent_test.go new file mode 100644 index 00000000000..e99e02641ff --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_backupprotectionintent_test.go @@ -0,0 +1,372 @@ +package protectionintent + +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 = BackupProtectionIntentId{} + +func TestNewBackupProtectionIntentID(t *testing.T) { + id := NewBackupProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "backupProtectionIntentValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.BackupProtectionIntentName != "backupProtectionIntentValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupProtectionIntentName'", id.BackupProtectionIntentName, "backupProtectionIntentValue") + } +} + +func TestFormatBackupProtectionIntentID(t *testing.T) { + actual := NewBackupProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "backupProtectionIntentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/backupProtectionIntent/backupProtectionIntentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupProtectionIntentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupProtectionIntentId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/backupProtectionIntent", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/backupProtectionIntent/backupProtectionIntentValue", + Expected: &BackupProtectionIntentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + BackupProtectionIntentName: "backupProtectionIntentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/backupProtectionIntent/backupProtectionIntentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupProtectionIntentID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.BackupProtectionIntentName != v.Expected.BackupProtectionIntentName { + t.Fatalf("Expected %q but got %q for BackupProtectionIntentName", v.Expected.BackupProtectionIntentName, actual.BackupProtectionIntentName) + } + + } +} + +func TestParseBackupProtectionIntentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupProtectionIntentId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/backupProtectionIntent", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/bAcKuPpRoTeCtIoNiNtEnT", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/backupProtectionIntent/backupProtectionIntentValue", + Expected: &BackupProtectionIntentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + BackupProtectionIntentName: "backupProtectionIntentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/backupProtectionIntent/backupProtectionIntentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/bAcKuPpRoTeCtIoNiNtEnT/bAcKuPpRoTeCtIoNiNtEnTvAlUe", + Expected: &BackupProtectionIntentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + BackupProtectionIntentName: "bAcKuPpRoTeCtIoNiNtEnTvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/bAcKuPpRoTeCtIoNiNtEnT/bAcKuPpRoTeCtIoNiNtEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupProtectionIntentIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.BackupProtectionIntentName != v.Expected.BackupProtectionIntentName { + t.Fatalf("Expected %q but got %q for BackupProtectionIntentName", v.Expected.BackupProtectionIntentName, actual.BackupProtectionIntentName) + } + + } +} + +func TestSegmentsForBackupProtectionIntentId(t *testing.T) { + segments := BackupProtectionIntentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupProtectionIntentId 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/recoveryservicesbackup/2023-02-01/protectionintent/id_location.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_location.go new file mode 100644 index 00000000000..3db392d95fd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_location.go @@ -0,0 +1,114 @@ +package protectionintent + +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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, 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.RecoveryServices/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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + 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/recoveryservicesbackup/2023-02-01/protectionintent/id_location_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_location_test.go new file mode 100644 index 00000000000..02baca3753c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/id_location_test.go @@ -0,0 +1,237 @@ +package protectionintent + +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.RecoveryServices/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/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.RecoveryServices/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.RecoveryServices/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.RecoveryServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/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.rEcOvErYsErViCeS/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/recoveryservicesbackup/2023-02-01/protectionintent/method_createorupdate_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_createorupdate_autorest.go new file mode 100644 index 00000000000..119b9b9a38a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_createorupdate_autorest.go @@ -0,0 +1,69 @@ +package protectionintent + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionIntentResource +} + +// CreateOrUpdate ... +func (c ProtectionIntentClient) CreateOrUpdate(ctx context.Context, id BackupProtectionIntentId, input ProtectionIntentResource) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ProtectionIntentClient) preparerForCreateOrUpdate(ctx context.Context, id BackupProtectionIntentId, input ProtectionIntentResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ProtectionIntentClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_delete_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_delete_autorest.go new file mode 100644 index 00000000000..2ed03771624 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_delete_autorest.go @@ -0,0 +1,66 @@ +package protectionintent + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ProtectionIntentClient) Delete(ctx context.Context, id BackupProtectionIntentId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ProtectionIntentClient) preparerForDelete(ctx context.Context, id BackupProtectionIntentId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c ProtectionIntentClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_get_autorest.go new file mode 100644 index 00000000000..0875ecb9ece --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_get_autorest.go @@ -0,0 +1,68 @@ +package protectionintent + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionIntentResource +} + +// Get ... +func (c ProtectionIntentClient) Get(ctx context.Context, id BackupProtectionIntentId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ProtectionIntentClient) preparerForGet(ctx context.Context, id BackupProtectionIntentId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ProtectionIntentClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_validate_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_validate_autorest.go new file mode 100644 index 00000000000..677f74de02b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/method_validate_autorest.go @@ -0,0 +1,70 @@ +package protectionintent + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateOperationResponse struct { + HttpResponse *http.Response + Model *PreValidateEnableBackupResponse +} + +// Validate ... +func (c ProtectionIntentClient) Validate(ctx context.Context, id LocationId, input PreValidateEnableBackupRequest) (result ValidateOperationResponse, err error) { + req, err := c.preparerForValidate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Validate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Validate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForValidate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionintent.ProtectionIntentClient", "Validate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForValidate prepares the Validate request. +func (c ProtectionIntentClient) preparerForValidate(ctx context.Context, id LocationId, input PreValidateEnableBackupRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupPreValidateProtection", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForValidate handles the response to the Validate request. The method always +// closes the http.Response Body. +func (c ProtectionIntentClient) responderForValidate(resp *http.Response) (result ValidateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azurerecoveryservicevaultprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azurerecoveryservicevaultprotectionintent.go new file mode 100644 index 00000000000..06a58c50499 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azurerecoveryservicevaultprotectionintent.go @@ -0,0 +1,45 @@ +package protectionintent + +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 _ ProtectionIntent = AzureRecoveryServiceVaultProtectionIntent{} + +type AzureRecoveryServiceVaultProtectionIntent struct { + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureRecoveryServiceVaultProtectionIntent{} + +func (s AzureRecoveryServiceVaultProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureRecoveryServiceVaultProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "RecoveryServiceVaultItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureresourceprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureresourceprotectionintent.go new file mode 100644 index 00000000000..6a274d6f965 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureresourceprotectionintent.go @@ -0,0 +1,46 @@ +package protectionintent + +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 _ ProtectionIntent = AzureResourceProtectionIntent{} + +type AzureResourceProtectionIntent struct { + FriendlyName *string `json:"friendlyName,omitempty"` + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureResourceProtectionIntent{} + +func (s AzureResourceProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureResourceProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureResourceProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureResourceProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "AzureResourceItem" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureResourceProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureworkloadautoprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureworkloadautoprotectionintent.go new file mode 100644 index 00000000000..c3bd647eb31 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureworkloadautoprotectionintent.go @@ -0,0 +1,45 @@ +package protectionintent + +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 _ ProtectionIntent = AzureWorkloadAutoProtectionIntent{} + +type AzureWorkloadAutoProtectionIntent struct { + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureWorkloadAutoProtectionIntent{} + +func (s AzureWorkloadAutoProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadAutoProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadAutoProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadAutoProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "AzureWorkloadAutoProtectionIntent" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadAutoProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureworkloadcontainerautoprotectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureworkloadcontainerautoprotectionintent.go new file mode 100644 index 00000000000..392bf620c14 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_azureworkloadcontainerautoprotectionintent.go @@ -0,0 +1,45 @@ +package protectionintent + +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 _ ProtectionIntent = AzureWorkloadContainerAutoProtectionIntent{} + +type AzureWorkloadContainerAutoProtectionIntent struct { + + // Fields inherited from ProtectionIntent + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + ItemId *string `json:"itemId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProtectionState *ProtectionStatus `json:"protectionState,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +var _ json.Marshaler = AzureWorkloadContainerAutoProtectionIntent{} + +func (s AzureWorkloadContainerAutoProtectionIntent) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadContainerAutoProtectionIntent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + decoded["protectionIntentItemType"] = "AzureWorkloadContainerAutoProtectionIntent" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_prevalidateenablebackuprequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_prevalidateenablebackuprequest.go new file mode 100644 index 00000000000..58ac0096b74 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_prevalidateenablebackuprequest.go @@ -0,0 +1,11 @@ +package protectionintent + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PreValidateEnableBackupRequest struct { + Properties *string `json:"properties,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + ResourceType *DataSourceType `json:"resourceType,omitempty"` + VaultId *string `json:"vaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_prevalidateenablebackupresponse.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_prevalidateenablebackupresponse.go new file mode 100644 index 00000000000..456761b757d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_prevalidateenablebackupresponse.go @@ -0,0 +1,13 @@ +package protectionintent + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PreValidateEnableBackupResponse struct { + ContainerName *string `json:"containerName,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ProtectedItemName *string `json:"protectedItemName,omitempty"` + Recommendation *string `json:"recommendation,omitempty"` + Status *ValidationStatus `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_protectionintent.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_protectionintent.go new file mode 100644 index 00000000000..46eb8d6248f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_protectionintent.go @@ -0,0 +1,72 @@ +package protectionintent + +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 ProtectionIntent interface { +} + +func unmarshalProtectionIntentImplementation(input []byte) (ProtectionIntent, 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 ProtectionIntent into map[string]interface: %+v", err) + } + + value, ok := temp["protectionIntentItemType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "RecoveryServiceVaultItem") { + var out AzureRecoveryServiceVaultProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureRecoveryServiceVaultProtectionIntent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureResourceItem") { + var out AzureResourceProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureResourceProtectionIntent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadAutoProtectionIntent") { + var out AzureWorkloadAutoProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadAutoProtectionIntent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadContainerAutoProtectionIntent") { + var out AzureWorkloadContainerAutoProtectionIntent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadContainerAutoProtectionIntent: %+v", err) + } + return out, nil + } + + type RawProtectionIntentImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionIntentImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_protectionintentresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_protectionintentresource.go new file mode 100644 index 00000000000..bff822af9f5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/model_protectionintentresource.go @@ -0,0 +1,50 @@ +package protectionintent + +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 ProtectionIntentResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectionIntent `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionIntentResource{} + +func (s *ProtectionIntentResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectionIntentResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionIntentResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionIntentResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectionIntentImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectionIntentResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/version.go new file mode 100644 index 00000000000..007e4148829 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionintent/version.go @@ -0,0 +1,12 @@ +package protectionintent + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/protectionintent/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/README.md new file mode 100644 index 00000000000..f06383c8ca9 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/README.md @@ -0,0 +1,69 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies` Documentation + +The `protectionpolicies` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/protectionpolicies" +``` + + +### Client Initialization + +```go +client := protectionpolicies.NewProtectionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProtectionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := protectionpolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupPolicyValue") + +payload := protectionpolicies.ProtectionPolicyResource{ + // ... +} + + +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: `ProtectionPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := protectionpolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupPolicyValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProtectionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := protectionpolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "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 +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/client.go new file mode 100644 index 00000000000..af96d5ee4b7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/client.go @@ -0,0 +1,18 @@ +package protectionpolicies + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionPoliciesClient struct { + Client autorest.Client + baseUri string +} + +func NewProtectionPoliciesClientWithBaseURI(endpoint string) ProtectionPoliciesClient { + return ProtectionPoliciesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/constants.go new file mode 100644 index 00000000000..37695869fe8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/constants.go @@ -0,0 +1,433 @@ +package protectionpolicies + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} + +type IAASVMPolicyType string + +const ( + IAASVMPolicyTypeInvalid IAASVMPolicyType = "Invalid" + IAASVMPolicyTypeVOne IAASVMPolicyType = "V1" + IAASVMPolicyTypeVTwo IAASVMPolicyType = "V2" +) + +func PossibleValuesForIAASVMPolicyType() []string { + return []string{ + string(IAASVMPolicyTypeInvalid), + string(IAASVMPolicyTypeVOne), + string(IAASVMPolicyTypeVTwo), + } +} + +func parseIAASVMPolicyType(input string) (*IAASVMPolicyType, error) { + vals := map[string]IAASVMPolicyType{ + "invalid": IAASVMPolicyTypeInvalid, + "v1": IAASVMPolicyTypeVOne, + "v2": IAASVMPolicyTypeVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IAASVMPolicyType(input) + return &out, nil +} + +type MonthOfYear string + +const ( + MonthOfYearApril MonthOfYear = "April" + MonthOfYearAugust MonthOfYear = "August" + MonthOfYearDecember MonthOfYear = "December" + MonthOfYearFebruary MonthOfYear = "February" + MonthOfYearInvalid MonthOfYear = "Invalid" + MonthOfYearJanuary MonthOfYear = "January" + MonthOfYearJuly MonthOfYear = "July" + MonthOfYearJune MonthOfYear = "June" + MonthOfYearMarch MonthOfYear = "March" + MonthOfYearMay MonthOfYear = "May" + MonthOfYearNovember MonthOfYear = "November" + MonthOfYearOctober MonthOfYear = "October" + MonthOfYearSeptember MonthOfYear = "September" +) + +func PossibleValuesForMonthOfYear() []string { + return []string{ + string(MonthOfYearApril), + string(MonthOfYearAugust), + string(MonthOfYearDecember), + string(MonthOfYearFebruary), + string(MonthOfYearInvalid), + string(MonthOfYearJanuary), + string(MonthOfYearJuly), + string(MonthOfYearJune), + string(MonthOfYearMarch), + string(MonthOfYearMay), + string(MonthOfYearNovember), + string(MonthOfYearOctober), + string(MonthOfYearSeptember), + } +} + +func parseMonthOfYear(input string) (*MonthOfYear, error) { + vals := map[string]MonthOfYear{ + "april": MonthOfYearApril, + "august": MonthOfYearAugust, + "december": MonthOfYearDecember, + "february": MonthOfYearFebruary, + "invalid": MonthOfYearInvalid, + "january": MonthOfYearJanuary, + "july": MonthOfYearJuly, + "june": MonthOfYearJune, + "march": MonthOfYearMarch, + "may": MonthOfYearMay, + "november": MonthOfYearNovember, + "october": MonthOfYearOctober, + "september": MonthOfYearSeptember, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MonthOfYear(input) + return &out, nil +} + +type PolicyType string + +const ( + PolicyTypeCopyOnlyFull PolicyType = "CopyOnlyFull" + PolicyTypeDifferential PolicyType = "Differential" + PolicyTypeFull PolicyType = "Full" + PolicyTypeIncremental PolicyType = "Incremental" + PolicyTypeInvalid PolicyType = "Invalid" + PolicyTypeLog PolicyType = "Log" + PolicyTypeSnapshotCopyOnlyFull PolicyType = "SnapshotCopyOnlyFull" + PolicyTypeSnapshotFull PolicyType = "SnapshotFull" +) + +func PossibleValuesForPolicyType() []string { + return []string{ + string(PolicyTypeCopyOnlyFull), + string(PolicyTypeDifferential), + string(PolicyTypeFull), + string(PolicyTypeIncremental), + string(PolicyTypeInvalid), + string(PolicyTypeLog), + string(PolicyTypeSnapshotCopyOnlyFull), + string(PolicyTypeSnapshotFull), + } +} + +func parsePolicyType(input string) (*PolicyType, error) { + vals := map[string]PolicyType{ + "copyonlyfull": PolicyTypeCopyOnlyFull, + "differential": PolicyTypeDifferential, + "full": PolicyTypeFull, + "incremental": PolicyTypeIncremental, + "invalid": PolicyTypeInvalid, + "log": PolicyTypeLog, + "snapshotcopyonlyfull": PolicyTypeSnapshotCopyOnlyFull, + "snapshotfull": PolicyTypeSnapshotFull, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyType(input) + return &out, nil +} + +type RetentionDurationType string + +const ( + RetentionDurationTypeDays RetentionDurationType = "Days" + RetentionDurationTypeInvalid RetentionDurationType = "Invalid" + RetentionDurationTypeMonths RetentionDurationType = "Months" + RetentionDurationTypeWeeks RetentionDurationType = "Weeks" + RetentionDurationTypeYears RetentionDurationType = "Years" +) + +func PossibleValuesForRetentionDurationType() []string { + return []string{ + string(RetentionDurationTypeDays), + string(RetentionDurationTypeInvalid), + string(RetentionDurationTypeMonths), + string(RetentionDurationTypeWeeks), + string(RetentionDurationTypeYears), + } +} + +func parseRetentionDurationType(input string) (*RetentionDurationType, error) { + vals := map[string]RetentionDurationType{ + "days": RetentionDurationTypeDays, + "invalid": RetentionDurationTypeInvalid, + "months": RetentionDurationTypeMonths, + "weeks": RetentionDurationTypeWeeks, + "years": RetentionDurationTypeYears, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RetentionDurationType(input) + return &out, nil +} + +type RetentionScheduleFormat string + +const ( + RetentionScheduleFormatDaily RetentionScheduleFormat = "Daily" + RetentionScheduleFormatInvalid RetentionScheduleFormat = "Invalid" + RetentionScheduleFormatWeekly RetentionScheduleFormat = "Weekly" +) + +func PossibleValuesForRetentionScheduleFormat() []string { + return []string{ + string(RetentionScheduleFormatDaily), + string(RetentionScheduleFormatInvalid), + string(RetentionScheduleFormatWeekly), + } +} + +func parseRetentionScheduleFormat(input string) (*RetentionScheduleFormat, error) { + vals := map[string]RetentionScheduleFormat{ + "daily": RetentionScheduleFormatDaily, + "invalid": RetentionScheduleFormatInvalid, + "weekly": RetentionScheduleFormatWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RetentionScheduleFormat(input) + return &out, nil +} + +type ScheduleRunType string + +const ( + ScheduleRunTypeDaily ScheduleRunType = "Daily" + ScheduleRunTypeHourly ScheduleRunType = "Hourly" + ScheduleRunTypeInvalid ScheduleRunType = "Invalid" + ScheduleRunTypeWeekly ScheduleRunType = "Weekly" +) + +func PossibleValuesForScheduleRunType() []string { + return []string{ + string(ScheduleRunTypeDaily), + string(ScheduleRunTypeHourly), + string(ScheduleRunTypeInvalid), + string(ScheduleRunTypeWeekly), + } +} + +func parseScheduleRunType(input string) (*ScheduleRunType, error) { + vals := map[string]ScheduleRunType{ + "daily": ScheduleRunTypeDaily, + "hourly": ScheduleRunTypeHourly, + "invalid": ScheduleRunTypeInvalid, + "weekly": ScheduleRunTypeWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduleRunType(input) + return &out, nil +} + +type TieringMode string + +const ( + TieringModeDoNotTier TieringMode = "DoNotTier" + TieringModeInvalid TieringMode = "Invalid" + TieringModeTierAfter TieringMode = "TierAfter" + TieringModeTierRecommended TieringMode = "TierRecommended" +) + +func PossibleValuesForTieringMode() []string { + return []string{ + string(TieringModeDoNotTier), + string(TieringModeInvalid), + string(TieringModeTierAfter), + string(TieringModeTierRecommended), + } +} + +func parseTieringMode(input string) (*TieringMode, error) { + vals := map[string]TieringMode{ + "donottier": TieringModeDoNotTier, + "invalid": TieringModeInvalid, + "tierafter": TieringModeTierAfter, + "tierrecommended": TieringModeTierRecommended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TieringMode(input) + return &out, nil +} + +type WeekOfMonth string + +const ( + WeekOfMonthFirst WeekOfMonth = "First" + WeekOfMonthFourth WeekOfMonth = "Fourth" + WeekOfMonthInvalid WeekOfMonth = "Invalid" + WeekOfMonthLast WeekOfMonth = "Last" + WeekOfMonthSecond WeekOfMonth = "Second" + WeekOfMonthThird WeekOfMonth = "Third" +) + +func PossibleValuesForWeekOfMonth() []string { + return []string{ + string(WeekOfMonthFirst), + string(WeekOfMonthFourth), + string(WeekOfMonthInvalid), + string(WeekOfMonthLast), + string(WeekOfMonthSecond), + string(WeekOfMonthThird), + } +} + +func parseWeekOfMonth(input string) (*WeekOfMonth, error) { + vals := map[string]WeekOfMonth{ + "first": WeekOfMonthFirst, + "fourth": WeekOfMonthFourth, + "invalid": WeekOfMonthInvalid, + "last": WeekOfMonthLast, + "second": WeekOfMonthSecond, + "third": WeekOfMonthThird, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WeekOfMonth(input) + return &out, nil +} + +type WorkloadType string + +const ( + WorkloadTypeAzureFileShare WorkloadType = "AzureFileShare" + WorkloadTypeAzureSqlDb WorkloadType = "AzureSqlDb" + WorkloadTypeClient WorkloadType = "Client" + WorkloadTypeExchange WorkloadType = "Exchange" + WorkloadTypeFileFolder WorkloadType = "FileFolder" + WorkloadTypeGenericDataSource WorkloadType = "GenericDataSource" + WorkloadTypeInvalid WorkloadType = "Invalid" + WorkloadTypeSAPAseDatabase WorkloadType = "SAPAseDatabase" + WorkloadTypeSAPHanaDBInstance WorkloadType = "SAPHanaDBInstance" + WorkloadTypeSAPHanaDatabase WorkloadType = "SAPHanaDatabase" + WorkloadTypeSQLDB WorkloadType = "SQLDB" + WorkloadTypeSQLDataBase WorkloadType = "SQLDataBase" + WorkloadTypeSharepoint WorkloadType = "Sharepoint" + WorkloadTypeSystemState WorkloadType = "SystemState" + WorkloadTypeVM WorkloadType = "VM" + WorkloadTypeVMwareVM WorkloadType = "VMwareVM" +) + +func PossibleValuesForWorkloadType() []string { + return []string{ + string(WorkloadTypeAzureFileShare), + string(WorkloadTypeAzureSqlDb), + string(WorkloadTypeClient), + string(WorkloadTypeExchange), + string(WorkloadTypeFileFolder), + string(WorkloadTypeGenericDataSource), + string(WorkloadTypeInvalid), + string(WorkloadTypeSAPAseDatabase), + string(WorkloadTypeSAPHanaDBInstance), + string(WorkloadTypeSAPHanaDatabase), + string(WorkloadTypeSQLDB), + string(WorkloadTypeSQLDataBase), + string(WorkloadTypeSharepoint), + string(WorkloadTypeSystemState), + string(WorkloadTypeVM), + string(WorkloadTypeVMwareVM), + } +} + +func parseWorkloadType(input string) (*WorkloadType, error) { + vals := map[string]WorkloadType{ + "azurefileshare": WorkloadTypeAzureFileShare, + "azuresqldb": WorkloadTypeAzureSqlDb, + "client": WorkloadTypeClient, + "exchange": WorkloadTypeExchange, + "filefolder": WorkloadTypeFileFolder, + "genericdatasource": WorkloadTypeGenericDataSource, + "invalid": WorkloadTypeInvalid, + "sapasedatabase": WorkloadTypeSAPAseDatabase, + "saphanadbinstance": WorkloadTypeSAPHanaDBInstance, + "saphanadatabase": WorkloadTypeSAPHanaDatabase, + "sqldb": WorkloadTypeSQLDB, + "sqldatabase": WorkloadTypeSQLDataBase, + "sharepoint": WorkloadTypeSharepoint, + "systemstate": WorkloadTypeSystemState, + "vm": WorkloadTypeVM, + "vmwarevm": WorkloadTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkloadType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/id_backuppolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/id_backuppolicy.go new file mode 100644 index 00000000000..550057c6100 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/id_backuppolicy.go @@ -0,0 +1,140 @@ +package protectionpolicies + +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 + VaultName string + BackupPolicyName string +} + +// NewBackupPolicyID returns a new BackupPolicyId struct +func NewBackupPolicyID(subscriptionId string, resourceGroupName string, vaultName string, backupPolicyName string) BackupPolicyId { + return BackupPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + 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) + } + + var ok bool + id := BackupPolicyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupPolicyName, ok = parsed.Parsed["backupPolicyName"]; !ok { + return nil, fmt.Errorf("the segment 'backupPolicyName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := BackupPolicyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupPolicyName, ok = parsed.Parsed["backupPolicyName"]; !ok { + return nil, fmt.Errorf("the segment 'backupPolicyName' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Policy Name: %q", id.BackupPolicyName), + } + return fmt.Sprintf("Backup Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/id_backuppolicy_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/id_backuppolicy_test.go new file mode 100644 index 00000000000..6aba915591f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/id_backuppolicy_test.go @@ -0,0 +1,327 @@ +package protectionpolicies + +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", "vaultValue", "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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + 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", "vaultValue", "backupPolicyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupPolicies/backupPolicyValue", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupPolicyName: "backupPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupPolicies/backupPolicyValue", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupPolicyName: "backupPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPpOlIcIeS/bAcKuPpOlIcYvAlUe", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + 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/recoveryservicesbackup/2023-02-01/protectionpolicies/method_createorupdate_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_createorupdate_autorest.go new file mode 100644 index 00000000000..a10287d2ffc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_createorupdate_autorest.go @@ -0,0 +1,69 @@ +package protectionpolicies + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionPolicyResource +} + +// CreateOrUpdate ... +func (c ProtectionPoliciesClient) CreateOrUpdate(ctx context.Context, id BackupPolicyId, input ProtectionPolicyResource) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ProtectionPoliciesClient) preparerForCreateOrUpdate(ctx context.Context, id BackupPolicyId, input ProtectionPolicyResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ProtectionPoliciesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusAccepted, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_delete_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_delete_autorest.go new file mode 100644 index 00000000000..d8310df327c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_delete_autorest.go @@ -0,0 +1,78 @@ +package protectionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ProtectionPoliciesClient) Delete(ctx context.Context, id BackupPolicyId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ProtectionPoliciesClient) DeleteThenPoll(ctx context.Context, id BackupPolicyId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ProtectionPoliciesClient) preparerForDelete(ctx context.Context, id BackupPolicyId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ProtectionPoliciesClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_get_autorest.go new file mode 100644 index 00000000000..bd3aabebfe7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/method_get_autorest.go @@ -0,0 +1,68 @@ +package protectionpolicies + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionPolicyResource +} + +// Get ... +func (c ProtectionPoliciesClient) Get(ctx context.Context, id BackupPolicyId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "protectionpolicies.ProtectionPoliciesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ProtectionPoliciesClient) preparerForGet(ctx context.Context, id BackupPolicyId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ProtectionPoliciesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azurefileshareprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azurefileshareprotectionpolicy.go new file mode 100644 index 00000000000..9b4b6abeea3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azurefileshareprotectionpolicy.go @@ -0,0 +1,83 @@ +package protectionpolicies + +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 _ ProtectionPolicy = AzureFileShareProtectionPolicy{} + +type AzureFileShareProtectionPolicy struct { + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + TimeZone *string `json:"timeZone,omitempty"` + WorkLoadType *WorkloadType `json:"workLoadType,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureFileShareProtectionPolicy{} + +func (s AzureFileShareProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureStorage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureFileShareProtectionPolicy{} + +func (s *AzureFileShareProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias AzureFileShareProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureFileShareProtectionPolicy: %+v", err) + } + + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.TimeZone = decoded.TimeZone + s.WorkLoadType = decoded.WorkLoadType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureFileShareProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'AzureFileShareProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'AzureFileShareProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azureiaasvmprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azureiaasvmprotectionpolicy.go new file mode 100644 index 00000000000..abea4b36410 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azureiaasvmprotectionpolicy.go @@ -0,0 +1,89 @@ +package protectionpolicies + +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 _ ProtectionPolicy = AzureIaaSVMProtectionPolicy{} + +type AzureIaaSVMProtectionPolicy struct { + InstantRPDetails *InstantRPAdditionalDetails `json:"instantRPDetails,omitempty"` + InstantRpRetentionRangeInDays *int64 `json:"instantRpRetentionRangeInDays,omitempty"` + PolicyType *IAASVMPolicyType `json:"policyType,omitempty"` + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + TieringPolicy *map[string]TieringPolicy `json:"tieringPolicy,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureIaaSVMProtectionPolicy{} + +func (s AzureIaaSVMProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSVMProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSVMProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSVMProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureIaasVM" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSVMProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureIaaSVMProtectionPolicy{} + +func (s *AzureIaaSVMProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias AzureIaaSVMProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureIaaSVMProtectionPolicy: %+v", err) + } + + s.InstantRPDetails = decoded.InstantRPDetails + s.InstantRpRetentionRangeInDays = decoded.InstantRpRetentionRangeInDays + s.PolicyType = decoded.PolicyType + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.TieringPolicy = decoded.TieringPolicy + s.TimeZone = decoded.TimeZone + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureIaaSVMProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'AzureIaaSVMProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'AzureIaaSVMProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azuresqlprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azuresqlprotectionpolicy.go new file mode 100644 index 00000000000..5a691310aaf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azuresqlprotectionpolicy.go @@ -0,0 +1,70 @@ +package protectionpolicies + +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 _ ProtectionPolicy = AzureSqlProtectionPolicy{} + +type AzureSqlProtectionPolicy struct { + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureSqlProtectionPolicy{} + +func (s AzureSqlProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureSqlProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSqlProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSqlProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureSql" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSqlProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureSqlProtectionPolicy{} + +func (s *AzureSqlProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias AzureSqlProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureSqlProtectionPolicy: %+v", err) + } + + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureSqlProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'AzureSqlProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azurevmworkloadprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azurevmworkloadprotectionpolicy.go new file mode 100644 index 00000000000..4ad1179dc7c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_azurevmworkloadprotectionpolicy.go @@ -0,0 +1,46 @@ +package protectionpolicies + +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 _ ProtectionPolicy = AzureVMWorkloadProtectionPolicy{} + +type AzureVMWorkloadProtectionPolicy struct { + MakePolicyConsistent *bool `json:"makePolicyConsistent,omitempty"` + Settings *Settings `json:"settings,omitempty"` + SubProtectionPolicy *[]SubProtectionPolicy `json:"subProtectionPolicy,omitempty"` + WorkLoadType *WorkloadType `json:"workLoadType,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = AzureVMWorkloadProtectionPolicy{} + +func (s AzureVMWorkloadProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper AzureVMWorkloadProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMWorkloadProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMWorkloadProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "AzureWorkload" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMWorkloadProtectionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyretentionformat.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyretentionformat.go new file mode 100644 index 00000000000..f2f8a9c3693 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyretentionformat.go @@ -0,0 +1,8 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DailyRetentionFormat struct { + DaysOfTheMonth *[]Day `json:"daysOfTheMonth,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyretentionschedule.go new file mode 100644 index 00000000000..40dc38fbcda --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyretentionschedule.go @@ -0,0 +1,9 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DailyRetentionSchedule struct { + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyschedule.go new file mode 100644 index 00000000000..88826749b25 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_dailyschedule.go @@ -0,0 +1,8 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DailySchedule struct { + ScheduleRunTimes *[]string `json:"scheduleRunTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_day.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_day.go new file mode 100644 index 00000000000..ca922f3cfe2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_day.go @@ -0,0 +1,9 @@ +package protectionpolicies + +// 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/recoveryservicesbackup/2023-02-01/protectionpolicies/model_genericprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_genericprotectionpolicy.go new file mode 100644 index 00000000000..c893e4e8051 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_genericprotectionpolicy.go @@ -0,0 +1,45 @@ +package protectionpolicies + +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 _ ProtectionPolicy = GenericProtectionPolicy{} + +type GenericProtectionPolicy struct { + FabricName *string `json:"fabricName,omitempty"` + SubProtectionPolicy *[]SubProtectionPolicy `json:"subProtectionPolicy,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = GenericProtectionPolicy{} + +func (s GenericProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper GenericProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "GenericProtectionPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericProtectionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_hourlyschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_hourlyschedule.go new file mode 100644 index 00000000000..8e573c02a5c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_hourlyschedule.go @@ -0,0 +1,28 @@ +package protectionpolicies + +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 HourlySchedule struct { + Interval *int64 `json:"interval,omitempty"` + ScheduleWindowDuration *int64 `json:"scheduleWindowDuration,omitempty"` + ScheduleWindowStartTime *string `json:"scheduleWindowStartTime,omitempty"` +} + +func (o *HourlySchedule) GetScheduleWindowStartTimeAsTime() (*time.Time, error) { + if o.ScheduleWindowStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ScheduleWindowStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HourlySchedule) SetScheduleWindowStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ScheduleWindowStartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_instantrpadditionaldetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_instantrpadditionaldetails.go new file mode 100644 index 00000000000..ea9cd7a24da --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_instantrpadditionaldetails.go @@ -0,0 +1,9 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstantRPAdditionalDetails struct { + AzureBackupRGNamePrefix *string `json:"azureBackupRGNamePrefix,omitempty"` + AzureBackupRGNameSuffix *string `json:"azureBackupRGNameSuffix,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_logschedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_logschedulepolicy.go new file mode 100644 index 00000000000..8f2cae11901 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_logschedulepolicy.go @@ -0,0 +1,41 @@ +package protectionpolicies + +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 _ SchedulePolicy = LogSchedulePolicy{} + +type LogSchedulePolicy struct { + ScheduleFrequencyInMins *int64 `json:"scheduleFrequencyInMins,omitempty"` + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = LogSchedulePolicy{} + +func (s LogSchedulePolicy) MarshalJSON() ([]byte, error) { + type wrapper LogSchedulePolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LogSchedulePolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LogSchedulePolicy: %+v", err) + } + decoded["schedulePolicyType"] = "LogSchedulePolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LogSchedulePolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_longtermretentionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_longtermretentionpolicy.go new file mode 100644 index 00000000000..50f80900d4e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_longtermretentionpolicy.go @@ -0,0 +1,44 @@ +package protectionpolicies + +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 _ RetentionPolicy = LongTermRetentionPolicy{} + +type LongTermRetentionPolicy struct { + DailySchedule *DailyRetentionSchedule `json:"dailySchedule,omitempty"` + MonthlySchedule *MonthlyRetentionSchedule `json:"monthlySchedule,omitempty"` + WeeklySchedule *WeeklyRetentionSchedule `json:"weeklySchedule,omitempty"` + YearlySchedule *YearlyRetentionSchedule `json:"yearlySchedule,omitempty"` + + // Fields inherited from RetentionPolicy +} + +var _ json.Marshaler = LongTermRetentionPolicy{} + +func (s LongTermRetentionPolicy) MarshalJSON() ([]byte, error) { + type wrapper LongTermRetentionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LongTermRetentionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LongTermRetentionPolicy: %+v", err) + } + decoded["retentionPolicyType"] = "LongTermRetentionPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LongTermRetentionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_longtermschedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_longtermschedulepolicy.go new file mode 100644 index 00000000000..06d19a60ab2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_longtermschedulepolicy.go @@ -0,0 +1,40 @@ +package protectionpolicies + +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 _ SchedulePolicy = LongTermSchedulePolicy{} + +type LongTermSchedulePolicy struct { + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = LongTermSchedulePolicy{} + +func (s LongTermSchedulePolicy) MarshalJSON() ([]byte, error) { + type wrapper LongTermSchedulePolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LongTermSchedulePolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LongTermSchedulePolicy: %+v", err) + } + decoded["schedulePolicyType"] = "LongTermSchedulePolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LongTermSchedulePolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_mabprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_mabprotectionpolicy.go new file mode 100644 index 00000000000..4178653c4e6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_mabprotectionpolicy.go @@ -0,0 +1,79 @@ +package protectionpolicies + +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 _ ProtectionPolicy = MabProtectionPolicy{} + +type MabProtectionPolicy struct { + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + + // Fields inherited from ProtectionPolicy + ProtectedItemsCount *int64 `json:"protectedItemsCount,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} + +var _ json.Marshaler = MabProtectionPolicy{} + +func (s MabProtectionPolicy) MarshalJSON() ([]byte, error) { + type wrapper MabProtectionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabProtectionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabProtectionPolicy: %+v", err) + } + decoded["backupManagementType"] = "MAB" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabProtectionPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &MabProtectionPolicy{} + +func (s *MabProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias MabProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into MabProtectionPolicy: %+v", err) + } + + s.ProtectedItemsCount = decoded.ProtectedItemsCount + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling MabProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'MabProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'MabProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_monthlyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_monthlyretentionschedule.go new file mode 100644 index 00000000000..4ceda36d875 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_monthlyretentionschedule.go @@ -0,0 +1,12 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonthlyRetentionSchedule struct { + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionScheduleDaily *DailyRetentionFormat `json:"retentionScheduleDaily,omitempty"` + RetentionScheduleFormatType *RetentionScheduleFormat `json:"retentionScheduleFormatType,omitempty"` + RetentionScheduleWeekly *WeeklyRetentionFormat `json:"retentionScheduleWeekly,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_protectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_protectionpolicy.go new file mode 100644 index 00000000000..67771822a93 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_protectionpolicy.go @@ -0,0 +1,88 @@ +package protectionpolicies + +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 ProtectionPolicy interface { +} + +func unmarshalProtectionPolicyImplementation(input []byte) (ProtectionPolicy, 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 ProtectionPolicy into map[string]interface: %+v", err) + } + + value, ok := temp["backupManagementType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureStorage") { + var out AzureFileShareProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureIaasVM") { + var out AzureIaaSVMProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSVMProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureSql") { + var out AzureSqlProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSqlProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkload") { + var out AzureVMWorkloadProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMWorkloadProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericProtectionPolicy") { + var out GenericProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericProtectionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MAB") { + var out MabProtectionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabProtectionPolicy: %+v", err) + } + return out, nil + } + + type RawProtectionPolicyImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionPolicyImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_protectionpolicyresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_protectionpolicyresource.go new file mode 100644 index 00000000000..03bda4d0a12 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_protectionpolicyresource.go @@ -0,0 +1,50 @@ +package protectionpolicies + +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 ProtectionPolicyResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectionPolicy `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionPolicyResource{} + +func (s *ProtectionPolicyResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectionPolicyResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionPolicyResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionPolicyResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectionPolicyResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_retentionduration.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_retentionduration.go new file mode 100644 index 00000000000..4b77b5e2f23 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_retentionduration.go @@ -0,0 +1,9 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetentionDuration struct { + Count *int64 `json:"count,omitempty"` + DurationType *RetentionDurationType `json:"durationType,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_retentionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_retentionpolicy.go new file mode 100644 index 00000000000..00c866c5775 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_retentionpolicy.go @@ -0,0 +1,56 @@ +package protectionpolicies + +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 RetentionPolicy interface { +} + +func unmarshalRetentionPolicyImplementation(input []byte) (RetentionPolicy, 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 RetentionPolicy into map[string]interface: %+v", err) + } + + value, ok := temp["retentionPolicyType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "LongTermRetentionPolicy") { + var out LongTermRetentionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LongTermRetentionPolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SimpleRetentionPolicy") { + var out SimpleRetentionPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SimpleRetentionPolicy: %+v", err) + } + return out, nil + } + + type RawRetentionPolicyImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRetentionPolicyImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_schedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_schedulepolicy.go new file mode 100644 index 00000000000..c5f32893393 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_schedulepolicy.go @@ -0,0 +1,72 @@ +package protectionpolicies + +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 SchedulePolicy interface { +} + +func unmarshalSchedulePolicyImplementation(input []byte) (SchedulePolicy, 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 SchedulePolicy into map[string]interface: %+v", err) + } + + value, ok := temp["schedulePolicyType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "LogSchedulePolicy") { + var out LogSchedulePolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LogSchedulePolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "LongTermSchedulePolicy") { + var out LongTermSchedulePolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LongTermSchedulePolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SimpleSchedulePolicy") { + var out SimpleSchedulePolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SimpleSchedulePolicy: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SimpleSchedulePolicyV2") { + var out SimpleSchedulePolicyV2 + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SimpleSchedulePolicyV2: %+v", err) + } + return out, nil + } + + type RawSchedulePolicyImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawSchedulePolicyImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_settings.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_settings.go new file mode 100644 index 00000000000..585e96708fc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_settings.go @@ -0,0 +1,10 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Settings struct { + IsCompression *bool `json:"isCompression,omitempty"` + Issqlcompression *bool `json:"issqlcompression,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleretentionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleretentionpolicy.go new file mode 100644 index 00000000000..37edb09a956 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleretentionpolicy.go @@ -0,0 +1,41 @@ +package protectionpolicies + +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 _ RetentionPolicy = SimpleRetentionPolicy{} + +type SimpleRetentionPolicy struct { + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + + // Fields inherited from RetentionPolicy +} + +var _ json.Marshaler = SimpleRetentionPolicy{} + +func (s SimpleRetentionPolicy) MarshalJSON() ([]byte, error) { + type wrapper SimpleRetentionPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SimpleRetentionPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SimpleRetentionPolicy: %+v", err) + } + decoded["retentionPolicyType"] = "SimpleRetentionPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SimpleRetentionPolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleschedulepolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleschedulepolicy.go new file mode 100644 index 00000000000..117247120b6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleschedulepolicy.go @@ -0,0 +1,45 @@ +package protectionpolicies + +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 _ SchedulePolicy = SimpleSchedulePolicy{} + +type SimpleSchedulePolicy struct { + HourlySchedule *HourlySchedule `json:"hourlySchedule,omitempty"` + ScheduleRunDays *[]DayOfWeek `json:"scheduleRunDays,omitempty"` + ScheduleRunFrequency *ScheduleRunType `json:"scheduleRunFrequency,omitempty"` + ScheduleRunTimes *[]string `json:"scheduleRunTimes,omitempty"` + ScheduleWeeklyFrequency *int64 `json:"scheduleWeeklyFrequency,omitempty"` + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = SimpleSchedulePolicy{} + +func (s SimpleSchedulePolicy) MarshalJSON() ([]byte, error) { + type wrapper SimpleSchedulePolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SimpleSchedulePolicy: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SimpleSchedulePolicy: %+v", err) + } + decoded["schedulePolicyType"] = "SimpleSchedulePolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SimpleSchedulePolicy: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleschedulepolicyv2.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleschedulepolicyv2.go new file mode 100644 index 00000000000..f522d8d7184 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_simpleschedulepolicyv2.go @@ -0,0 +1,44 @@ +package protectionpolicies + +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 _ SchedulePolicy = SimpleSchedulePolicyV2{} + +type SimpleSchedulePolicyV2 struct { + DailySchedule *DailySchedule `json:"dailySchedule,omitempty"` + HourlySchedule *HourlySchedule `json:"hourlySchedule,omitempty"` + ScheduleRunFrequency *ScheduleRunType `json:"scheduleRunFrequency,omitempty"` + WeeklySchedule *WeeklySchedule `json:"weeklySchedule,omitempty"` + + // Fields inherited from SchedulePolicy +} + +var _ json.Marshaler = SimpleSchedulePolicyV2{} + +func (s SimpleSchedulePolicyV2) MarshalJSON() ([]byte, error) { + type wrapper SimpleSchedulePolicyV2 + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SimpleSchedulePolicyV2: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SimpleSchedulePolicyV2: %+v", err) + } + decoded["schedulePolicyType"] = "SimpleSchedulePolicyV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SimpleSchedulePolicyV2: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_subprotectionpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_subprotectionpolicy.go new file mode 100644 index 00000000000..bcf1c32ee70 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_subprotectionpolicy.go @@ -0,0 +1,51 @@ +package protectionpolicies + +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 SubProtectionPolicy struct { + PolicyType *PolicyType `json:"policyType,omitempty"` + RetentionPolicy RetentionPolicy `json:"retentionPolicy"` + SchedulePolicy SchedulePolicy `json:"schedulePolicy"` + TieringPolicy *map[string]TieringPolicy `json:"tieringPolicy,omitempty"` +} + +var _ json.Unmarshaler = &SubProtectionPolicy{} + +func (s *SubProtectionPolicy) UnmarshalJSON(bytes []byte) error { + type alias SubProtectionPolicy + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SubProtectionPolicy: %+v", err) + } + + s.PolicyType = decoded.PolicyType + s.TieringPolicy = decoded.TieringPolicy + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SubProtectionPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["retentionPolicy"]; ok { + impl, err := unmarshalRetentionPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RetentionPolicy' for 'SubProtectionPolicy': %+v", err) + } + s.RetentionPolicy = impl + } + + if v, ok := temp["schedulePolicy"]; ok { + impl, err := unmarshalSchedulePolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'SchedulePolicy' for 'SubProtectionPolicy': %+v", err) + } + s.SchedulePolicy = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_tieringpolicy.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_tieringpolicy.go new file mode 100644 index 00000000000..51a5c8b97f0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_tieringpolicy.go @@ -0,0 +1,10 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TieringPolicy struct { + Duration *int64 `json:"duration,omitempty"` + DurationType *RetentionDurationType `json:"durationType,omitempty"` + TieringMode *TieringMode `json:"tieringMode,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyretentionformat.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyretentionformat.go new file mode 100644 index 00000000000..082fcf7abe1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyretentionformat.go @@ -0,0 +1,9 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WeeklyRetentionFormat struct { + DaysOfTheWeek *[]DayOfWeek `json:"daysOfTheWeek,omitempty"` + WeeksOfTheMonth *[]WeekOfMonth `json:"weeksOfTheMonth,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyretentionschedule.go new file mode 100644 index 00000000000..cde2551554d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyretentionschedule.go @@ -0,0 +1,10 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WeeklyRetentionSchedule struct { + DaysOfTheWeek *[]DayOfWeek `json:"daysOfTheWeek,omitempty"` + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyschedule.go new file mode 100644 index 00000000000..f3005f7015f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_weeklyschedule.go @@ -0,0 +1,9 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WeeklySchedule struct { + ScheduleRunDays *[]DayOfWeek `json:"scheduleRunDays,omitempty"` + ScheduleRunTimes *[]string `json:"scheduleRunTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_yearlyretentionschedule.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_yearlyretentionschedule.go new file mode 100644 index 00000000000..8d300368ef5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/model_yearlyretentionschedule.go @@ -0,0 +1,13 @@ +package protectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type YearlyRetentionSchedule struct { + MonthsOfYear *[]MonthOfYear `json:"monthsOfYear,omitempty"` + RetentionDuration *RetentionDuration `json:"retentionDuration,omitempty"` + RetentionScheduleDaily *DailyRetentionFormat `json:"retentionScheduleDaily,omitempty"` + RetentionScheduleFormatType *RetentionScheduleFormat `json:"retentionScheduleFormatType,omitempty"` + RetentionScheduleWeekly *WeeklyRetentionFormat `json:"retentionScheduleWeekly,omitempty"` + RetentionTimes *[]string `json:"retentionTimes,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/version.go new file mode 100644 index 00000000000..9c0088c68b7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/protectionpolicies/version.go @@ -0,0 +1,12 @@ +package protectionpolicies + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/protectionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/README.md new file mode 100644 index 00000000000..6337438979c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint` Documentation + +The `recoverypoint` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/recoverypoint" +``` + + +### Client Initialization + +```go +client := recoverypoint.NewRecoveryPointClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoveryPointClient.MoveRecoveryPoint` + +```go +ctx := context.TODO() +id := recoverypoint.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue") + +payload := recoverypoint.MoveRPAcrossTiersRequest{ + // ... +} + + +if err := client.MoveRecoveryPointThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/client.go new file mode 100644 index 00000000000..6c60cc292bc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/client.go @@ -0,0 +1,18 @@ +package recoverypoint + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointClient struct { + Client autorest.Client + baseUri string +} + +func NewRecoveryPointClientWithBaseURI(endpoint string) RecoveryPointClient { + return RecoveryPointClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/constants.go new file mode 100644 index 00000000000..90fc0ec9fcd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/constants.go @@ -0,0 +1,40 @@ +package recoverypoint + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointTierType string + +const ( + RecoveryPointTierTypeArchivedRP RecoveryPointTierType = "ArchivedRP" + RecoveryPointTierTypeHardenedRP RecoveryPointTierType = "HardenedRP" + RecoveryPointTierTypeInstantRP RecoveryPointTierType = "InstantRP" + RecoveryPointTierTypeInvalid RecoveryPointTierType = "Invalid" +) + +func PossibleValuesForRecoveryPointTierType() []string { + return []string{ + string(RecoveryPointTierTypeArchivedRP), + string(RecoveryPointTierTypeHardenedRP), + string(RecoveryPointTierTypeInstantRP), + string(RecoveryPointTierTypeInvalid), + } +} + +func parseRecoveryPointTierType(input string) (*RecoveryPointTierType, error) { + vals := map[string]RecoveryPointTierType{ + "archivedrp": RecoveryPointTierTypeArchivedRP, + "hardenedrp": RecoveryPointTierTypeHardenedRP, + "instantrp": RecoveryPointTierTypeInstantRP, + "invalid": RecoveryPointTierTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointTierType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/id_recoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/id_recoverypoint.go new file mode 100644 index 00000000000..ff7c54da144 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/id_recoverypoint.go @@ -0,0 +1,179 @@ +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 + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string + RecoveryPointId string +} + +// NewRecoveryPointID returns a new RecoveryPointId struct +func NewRecoveryPointID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string, recoveryPointId string) RecoveryPointId { + return RecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s/recoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName, 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + fmt.Sprintf("Recovery Point: %q", id.RecoveryPointId), + } + return fmt.Sprintf("Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/id_recoverypoint_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/id_recoverypoint_test.go new file mode 100644 index 00000000000..53e840f861f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/id_recoverypoint_test.go @@ -0,0 +1,462 @@ +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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } + + 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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS/rEcOvErYpOiNtIdVaLuE", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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/recoveryservicesbackup/2023-02-01/recoverypoint/method_moverecoverypoint_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/method_moverecoverypoint_autorest.go new file mode 100644 index 00000000000..77b6f679042 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/method_moverecoverypoint_autorest.go @@ -0,0 +1,79 @@ +package recoverypoint + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MoveRecoveryPointOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// MoveRecoveryPoint ... +func (c RecoveryPointClient) MoveRecoveryPoint(ctx context.Context, id RecoveryPointId, input MoveRPAcrossTiersRequest) (result MoveRecoveryPointOperationResponse, err error) { + req, err := c.preparerForMoveRecoveryPoint(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoint.RecoveryPointClient", "MoveRecoveryPoint", nil, "Failure preparing request") + return + } + + result, err = c.senderForMoveRecoveryPoint(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoint.RecoveryPointClient", "MoveRecoveryPoint", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// MoveRecoveryPointThenPoll performs MoveRecoveryPoint then polls until it's completed +func (c RecoveryPointClient) MoveRecoveryPointThenPoll(ctx context.Context, id RecoveryPointId, input MoveRPAcrossTiersRequest) error { + result, err := c.MoveRecoveryPoint(ctx, id, input) + if err != nil { + return fmt.Errorf("performing MoveRecoveryPoint: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after MoveRecoveryPoint: %+v", err) + } + + return nil +} + +// preparerForMoveRecoveryPoint prepares the MoveRecoveryPoint request. +func (c RecoveryPointClient) preparerForMoveRecoveryPoint(ctx context.Context, id RecoveryPointId, input MoveRPAcrossTiersRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/move", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForMoveRecoveryPoint sends the MoveRecoveryPoint request. The method will close the +// http.Response Body if it receives an error. +func (c RecoveryPointClient) senderForMoveRecoveryPoint(ctx context.Context, req *http.Request) (future MoveRecoveryPointOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/model_moverpacrosstiersrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/model_moverpacrosstiersrequest.go new file mode 100644 index 00000000000..c90154ae670 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/model_moverpacrosstiersrequest.go @@ -0,0 +1,10 @@ +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 MoveRPAcrossTiersRequest struct { + ObjectType *string `json:"objectType,omitempty"` + SourceTierType *RecoveryPointTierType `json:"sourceTierType,omitempty"` + TargetTierType *RecoveryPointTierType `json:"targetTierType,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoint/version.go new file mode 100644 index 00000000000..ab8ec3f33fa --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverypoint/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/README.md new file mode 100644 index 00000000000..f951890bb42 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints` Documentation + +The `recoverypoints` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/recoverypoints" +``` + + +### Client Initialization + +```go +client := recoverypoints.NewRecoveryPointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoveryPointsClient.Get` + +```go +ctx := context.TODO() +id := recoverypoints.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "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: `RecoveryPointsClient.List` + +```go +ctx := context.TODO() +id := recoverypoints.NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + +// alternatively `client.List(ctx, id, recoverypoints.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, recoverypoints.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/client.go new file mode 100644 index 00000000000..dab85424069 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/client.go @@ -0,0 +1,18 @@ +package recoverypoints + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointsClient struct { + Client autorest.Client + baseUri string +} + +func NewRecoveryPointsClientWithBaseURI(endpoint string) RecoveryPointsClient { + return RecoveryPointsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/constants.go new file mode 100644 index 00000000000..fa65db6e0e8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/constants.go @@ -0,0 +1,151 @@ +package recoverypoints + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointTierStatus string + +const ( + RecoveryPointTierStatusDeleted RecoveryPointTierStatus = "Deleted" + RecoveryPointTierStatusDisabled RecoveryPointTierStatus = "Disabled" + RecoveryPointTierStatusInvalid RecoveryPointTierStatus = "Invalid" + RecoveryPointTierStatusRehydrated RecoveryPointTierStatus = "Rehydrated" + RecoveryPointTierStatusValid RecoveryPointTierStatus = "Valid" +) + +func PossibleValuesForRecoveryPointTierStatus() []string { + return []string{ + string(RecoveryPointTierStatusDeleted), + string(RecoveryPointTierStatusDisabled), + string(RecoveryPointTierStatusInvalid), + string(RecoveryPointTierStatusRehydrated), + string(RecoveryPointTierStatusValid), + } +} + +func parseRecoveryPointTierStatus(input string) (*RecoveryPointTierStatus, error) { + vals := map[string]RecoveryPointTierStatus{ + "deleted": RecoveryPointTierStatusDeleted, + "disabled": RecoveryPointTierStatusDisabled, + "invalid": RecoveryPointTierStatusInvalid, + "rehydrated": RecoveryPointTierStatusRehydrated, + "valid": RecoveryPointTierStatusValid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointTierStatus(input) + return &out, nil +} + +type RecoveryPointTierType string + +const ( + RecoveryPointTierTypeArchivedRP RecoveryPointTierType = "ArchivedRP" + RecoveryPointTierTypeHardenedRP RecoveryPointTierType = "HardenedRP" + RecoveryPointTierTypeInstantRP RecoveryPointTierType = "InstantRP" + RecoveryPointTierTypeInvalid RecoveryPointTierType = "Invalid" +) + +func PossibleValuesForRecoveryPointTierType() []string { + return []string{ + string(RecoveryPointTierTypeArchivedRP), + string(RecoveryPointTierTypeHardenedRP), + string(RecoveryPointTierTypeInstantRP), + string(RecoveryPointTierTypeInvalid), + } +} + +func parseRecoveryPointTierType(input string) (*RecoveryPointTierType, error) { + vals := map[string]RecoveryPointTierType{ + "archivedrp": RecoveryPointTierTypeArchivedRP, + "hardenedrp": RecoveryPointTierTypeHardenedRP, + "instantrp": RecoveryPointTierTypeInstantRP, + "invalid": RecoveryPointTierTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointTierType(input) + return &out, nil +} + +type RestorePointType string + +const ( + RestorePointTypeDifferential RestorePointType = "Differential" + RestorePointTypeFull RestorePointType = "Full" + RestorePointTypeIncremental RestorePointType = "Incremental" + RestorePointTypeInvalid RestorePointType = "Invalid" + RestorePointTypeLog RestorePointType = "Log" + RestorePointTypeSnapshotCopyOnlyFull RestorePointType = "SnapshotCopyOnlyFull" + RestorePointTypeSnapshotFull RestorePointType = "SnapshotFull" +) + +func PossibleValuesForRestorePointType() []string { + return []string{ + string(RestorePointTypeDifferential), + string(RestorePointTypeFull), + string(RestorePointTypeIncremental), + string(RestorePointTypeInvalid), + string(RestorePointTypeLog), + string(RestorePointTypeSnapshotCopyOnlyFull), + string(RestorePointTypeSnapshotFull), + } +} + +func parseRestorePointType(input string) (*RestorePointType, error) { + vals := map[string]RestorePointType{ + "differential": RestorePointTypeDifferential, + "full": RestorePointTypeFull, + "incremental": RestorePointTypeIncremental, + "invalid": RestorePointTypeInvalid, + "log": RestorePointTypeLog, + "snapshotcopyonlyfull": RestorePointTypeSnapshotCopyOnlyFull, + "snapshotfull": RestorePointTypeSnapshotFull, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestorePointType(input) + return &out, nil +} + +type SQLDataDirectoryType string + +const ( + SQLDataDirectoryTypeData SQLDataDirectoryType = "Data" + SQLDataDirectoryTypeInvalid SQLDataDirectoryType = "Invalid" + SQLDataDirectoryTypeLog SQLDataDirectoryType = "Log" +) + +func PossibleValuesForSQLDataDirectoryType() []string { + return []string{ + string(SQLDataDirectoryTypeData), + string(SQLDataDirectoryTypeInvalid), + string(SQLDataDirectoryTypeLog), + } +} + +func parseSQLDataDirectoryType(input string) (*SQLDataDirectoryType, error) { + vals := map[string]SQLDataDirectoryType{ + "data": SQLDataDirectoryTypeData, + "invalid": SQLDataDirectoryTypeInvalid, + "log": SQLDataDirectoryTypeLog, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SQLDataDirectoryType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_protecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_protecteditem.go new file mode 100644 index 00000000000..db854fc16d0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_protecteditem.go @@ -0,0 +1,166 @@ +package recoverypoints + +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 = ProtectedItemId{} + +// ProtectedItemId is a struct representing the Resource ID for a Protected Item +type ProtectedItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string +} + +// NewProtectedItemID returns a new ProtectedItemId struct +func NewProtectedItemID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string) ProtectedItemId { + return ProtectedItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + } +} + +// ParseProtectedItemID parses 'input' into a ProtectedItemId +func ParseProtectedItemID(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProtectedItemIDInsensitively parses 'input' case-insensitively into a ProtectedItemId +// note: this method should only be used for API response data and not user input +func ParseProtectedItemIDInsensitively(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProtectedItemID checks that 'input' can be parsed as a Protected Item ID +func ValidateProtectedItemID(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 := ParseProtectedItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Protected Item ID +func (id ProtectedItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Protected Item ID +func (id ProtectedItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + } +} + +// String returns a human-readable description of this Protected Item ID +func (id ProtectedItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + } + return fmt.Sprintf("Protected Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_protecteditem_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_protecteditem_test.go new file mode 100644 index 00000000000..ca4b91d535b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_protecteditem_test.go @@ -0,0 +1,417 @@ +package recoverypoints + +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 = ProtectedItemId{} + +func TestNewProtectedItemID(t *testing.T) { + id := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } +} + +func TestFormatProtectedItemID(t *testing.T) { + actual := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProtectedItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestParseProtectedItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestSegmentsForProtectedItemId(t *testing.T) { + segments := ProtectedItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProtectedItemId 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/recoveryservicesbackup/2023-02-01/recoverypoints/id_recoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_recoverypoint.go new file mode 100644 index 00000000000..64772def3f8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_recoverypoint.go @@ -0,0 +1,179 @@ +package recoverypoints + +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 + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string + RecoveryPointId string +} + +// NewRecoveryPointID returns a new RecoveryPointId struct +func NewRecoveryPointID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string, recoveryPointId string) RecoveryPointId { + return RecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s/recoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName, 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + fmt.Sprintf("Recovery Point: %q", id.RecoveryPointId), + } + return fmt.Sprintf("Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_recoverypoint_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_recoverypoint_test.go new file mode 100644 index 00000000000..6ea1689a519 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/id_recoverypoint_test.go @@ -0,0 +1,462 @@ +package recoverypoints + +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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } + + 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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS/rEcOvErYpOiNtIdVaLuE", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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/recoveryservicesbackup/2023-02-01/recoverypoints/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/method_get_autorest.go new file mode 100644 index 00000000000..dce6d176011 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/method_get_autorest.go @@ -0,0 +1,68 @@ +package recoverypoints + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *RecoveryPointResource +} + +// Get ... +func (c RecoveryPointsClient) Get(ctx context.Context, id RecoveryPointId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c RecoveryPointsClient) preparerForGet(ctx context.Context, id RecoveryPointId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c RecoveryPointsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/method_list_autorest.go new file mode 100644 index 00000000000..904ef293b39 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/method_list_autorest.go @@ -0,0 +1,215 @@ +package recoverypoints + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]RecoveryPointResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []RecoveryPointResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c RecoveryPointsClient) List(ctx context.Context, id ProtectedItemId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c RecoveryPointsClient) preparerForList(ctx context.Context, id ProtectedItemId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/recoveryPoints", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c RecoveryPointsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c RecoveryPointsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []RecoveryPointResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c RecoveryPointsClient) ListComplete(ctx context.Context, id ProtectedItemId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RecoveryPointResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c RecoveryPointsClient) ListCompleteMatchingPredicate(ctx context.Context, id ProtectedItemId, options ListOperationOptions, predicate RecoveryPointResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]RecoveryPointResource, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azurefilesharerecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azurefilesharerecoverypoint.go new file mode 100644 index 00000000000..2a7c237f200 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azurefilesharerecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypoints + +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 _ RecoveryPoint = AzureFileShareRecoveryPoint{} + +type AzureFileShareRecoveryPoint struct { + FileShareSnapshotUri *string `json:"fileShareSnapshotUri,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointSizeInGB *int64 `json:"recoveryPointSizeInGB,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureFileShareRecoveryPoint{} + +func (s AzureFileShareRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureFileShareRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadpointintimerecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadpointintimerecoverypoint.go new file mode 100644 index 00000000000..a36ed7d5894 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadpointintimerecoverypoint.go @@ -0,0 +1,46 @@ +package recoverypoints + +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 _ RecoveryPoint = AzureWorkloadPointInTimeRecoveryPoint{} + +type AzureWorkloadPointInTimeRecoveryPoint struct { + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + TimeRanges *[]PointInTimeRange `json:"timeRanges,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadPointInTimeRecoveryPoint{} + +func (s AzureWorkloadPointInTimeRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadPointInTimeRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadPointInTimeRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadrecoverypoint.go new file mode 100644 index 00000000000..a060d0325a6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadrecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypoints + +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 _ RecoveryPoint = AzureWorkloadRecoveryPoint{} + +type AzureWorkloadRecoveryPoint struct { + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadRecoveryPoint{} + +func (s AzureWorkloadRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsaphanarecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsaphanarecoverypoint.go new file mode 100644 index 00000000000..3cc6563ceee --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsaphanarecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypoints + +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 _ RecoveryPoint = AzureWorkloadSAPHanaRecoveryPoint{} + +type AzureWorkloadSAPHanaRecoveryPoint struct { + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadSAPHanaRecoveryPoint{} + +func (s AzureWorkloadSAPHanaRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSAPHanaRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSAPHanaRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsqlrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsqlrecoverypoint.go new file mode 100644 index 00000000000..e4c16a37cbf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsqlrecoverypoint.go @@ -0,0 +1,46 @@ +package recoverypoints + +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 _ RecoveryPoint = AzureWorkloadSQLRecoveryPoint{} + +type AzureWorkloadSQLRecoveryPoint struct { + ExtendedInfo *AzureWorkloadSQLRecoveryPointExtendedInfo `json:"extendedInfo,omitempty"` + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadSQLRecoveryPoint{} + +func (s AzureWorkloadSQLRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSQLRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSQLRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSQLRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSQLRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSQLRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsqlrecoverypointextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsqlrecoverypointextendedinfo.go new file mode 100644 index 00000000000..8ad178eb3ba --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_azureworkloadsqlrecoverypointextendedinfo.go @@ -0,0 +1,27 @@ +package recoverypoints + +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 AzureWorkloadSQLRecoveryPointExtendedInfo struct { + DataDirectoryPaths *[]SQLDataDirectory `json:"dataDirectoryPaths,omitempty"` + DataDirectoryTimeInUTC *string `json:"dataDirectoryTimeInUTC,omitempty"` +} + +func (o *AzureWorkloadSQLRecoveryPointExtendedInfo) GetDataDirectoryTimeInUTCAsTime() (*time.Time, error) { + if o.DataDirectoryTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DataDirectoryTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureWorkloadSQLRecoveryPointExtendedInfo) SetDataDirectoryTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DataDirectoryTimeInUTC = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_bekdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_bekdetails.go new file mode 100644 index 00000000000..36772ad0169 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_bekdetails.go @@ -0,0 +1,10 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BEKDetails struct { + SecretData *string `json:"secretData,omitempty"` + SecretUrl *string `json:"secretUrl,omitempty"` + SecretVaultId *string `json:"secretVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_diskinformation.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_diskinformation.go new file mode 100644 index 00000000000..1d6ed082bf4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_diskinformation.go @@ -0,0 +1,9 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskInformation struct { + Lun *int64 `json:"lun,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_genericrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_genericrecoverypoint.go new file mode 100644 index 00000000000..97d3952dc2c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_genericrecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypoints + +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 _ RecoveryPoint = GenericRecoveryPoint{} + +type GenericRecoveryPoint struct { + FriendlyName *string `json:"friendlyName,omitempty"` + RecoveryPointAdditionalInfo *string `json:"recoveryPointAdditionalInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = GenericRecoveryPoint{} + +func (s GenericRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper GenericRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericRecoveryPoint: %+v", err) + } + decoded["objectType"] = "GenericRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_iaasvmrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_iaasvmrecoverypoint.go new file mode 100644 index 00000000000..d4f42a144f4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_iaasvmrecoverypoint.go @@ -0,0 +1,60 @@ +package recoverypoints + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RecoveryPoint = IaasVMRecoveryPoint{} + +type IaasVMRecoveryPoint struct { + IsInstantIlrSessionActive *bool `json:"isInstantIlrSessionActive,omitempty"` + IsManagedVirtualMachine *bool `json:"isManagedVirtualMachine,omitempty"` + IsPrivateAccessEnabledOnAnyDisk *bool `json:"isPrivateAccessEnabledOnAnyDisk,omitempty"` + IsSourceVMEncrypted *bool `json:"isSourceVMEncrypted,omitempty"` + KeyAndSecret *KeyAndSecretDetails `json:"keyAndSecret,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + OsType *string `json:"osType,omitempty"` + RecoveryPointAdditionalInfo *string `json:"recoveryPointAdditionalInfo,omitempty"` + RecoveryPointDiskConfiguration *RecoveryPointDiskConfiguration `json:"recoveryPointDiskConfiguration,omitempty"` + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + SecurityType *string `json:"securityType,omitempty"` + SourceVMStorageType *string `json:"sourceVMStorageType,omitempty"` + VirtualMachineSize *string `json:"virtualMachineSize,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = IaasVMRecoveryPoint{} + +func (s IaasVMRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRecoveryPoint: %+v", err) + } + decoded["objectType"] = "IaasVMRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_kekdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_kekdetails.go new file mode 100644 index 00000000000..36abbae9609 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_kekdetails.go @@ -0,0 +1,10 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KEKDetails struct { + KeyBackupData *string `json:"keyBackupData,omitempty"` + KeyUrl *string `json:"keyUrl,omitempty"` + KeyVaultId *string `json:"keyVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_keyandsecretdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_keyandsecretdetails.go new file mode 100644 index 00000000000..96c513fc516 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_keyandsecretdetails.go @@ -0,0 +1,10 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyAndSecretDetails struct { + BekDetails *BEKDetails `json:"bekDetails,omitempty"` + EncryptionMechanism *string `json:"encryptionMechanism,omitempty"` + KekDetails *KEKDetails `json:"kekDetails,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_pointintimerange.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_pointintimerange.go new file mode 100644 index 00000000000..4190258e022 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_pointintimerange.go @@ -0,0 +1,39 @@ +package recoverypoints + +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 PointInTimeRange struct { + EndTime *string `json:"endTime,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *PointInTimeRange) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PointInTimeRange) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *PointInTimeRange) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PointInTimeRange) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypoint.go new file mode 100644 index 00000000000..f48571630da --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypoint.go @@ -0,0 +1,96 @@ +package recoverypoints + +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 RecoveryPoint interface { +} + +func unmarshalRecoveryPointImplementation(input []byte) (RecoveryPoint, 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 RecoveryPoint into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareRecoveryPoint") { + var out AzureFileShareRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadPointInTimeRecoveryPoint") { + var out AzureWorkloadPointInTimeRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadRecoveryPoint") { + var out AzureWorkloadRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSAPHanaRecoveryPoint") { + var out AzureWorkloadSAPHanaRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSQLRecoveryPoint") { + var out AzureWorkloadSQLRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSQLRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericRecoveryPoint") { + var out GenericRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRecoveryPoint") { + var out IaasVMRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRecoveryPoint: %+v", err) + } + return out, nil + } + + type RawRecoveryPointImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryPointImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointdiskconfiguration.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointdiskconfiguration.go new file mode 100644 index 00000000000..d3935380d03 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointdiskconfiguration.go @@ -0,0 +1,11 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointDiskConfiguration struct { + ExcludedDiskList *[]DiskInformation `json:"excludedDiskList,omitempty"` + IncludedDiskList *[]DiskInformation `json:"includedDiskList,omitempty"` + NumberOfDisksAttachedToVM *int64 `json:"numberOfDisksAttachedToVm,omitempty"` + NumberOfDisksIncludedInBackup *int64 `json:"numberOfDisksIncludedInBackup,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointmovereadinessinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointmovereadinessinfo.go new file mode 100644 index 00000000000..03cab067198 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointmovereadinessinfo.go @@ -0,0 +1,9 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointMoveReadinessInfo struct { + AdditionalInfo *string `json:"additionalInfo,omitempty"` + IsReadyForMove *bool `json:"isReadyForMove,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointproperties.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointproperties.go new file mode 100644 index 00000000000..4bd3f5e75a3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointproperties.go @@ -0,0 +1,10 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointProperties struct { + ExpiryTime *string `json:"expiryTime,omitempty"` + IsSoftDeleted *bool `json:"isSoftDeleted,omitempty"` + RuleName *string `json:"ruleName,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointresource.go new file mode 100644 index 00000000000..8e67217424b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointresource.go @@ -0,0 +1,50 @@ +package recoverypoints + +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 RecoveryPointResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties RecoveryPoint `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &RecoveryPointResource{} + +func (s *RecoveryPointResource) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPointResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPointResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPointResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalRecoveryPointImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'RecoveryPointResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointtierinformationv2.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointtierinformationv2.go new file mode 100644 index 00000000000..996285f0562 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_recoverypointtierinformationv2.go @@ -0,0 +1,10 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointTierInformationV2 struct { + ExtendedInfo *map[string]string `json:"extendedInfo,omitempty"` + Status *RecoveryPointTierStatus `json:"status,omitempty"` + Type *RecoveryPointTierType `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_sqldatadirectory.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_sqldatadirectory.go new file mode 100644 index 00000000000..8460946fc57 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/model_sqldatadirectory.go @@ -0,0 +1,10 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SQLDataDirectory struct { + LogicalName *string `json:"logicalName,omitempty"` + Path *string `json:"path,omitempty"` + Type *SQLDataDirectoryType `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/predicates.go new file mode 100644 index 00000000000..5b2e75923a6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/predicates.go @@ -0,0 +1,37 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p RecoveryPointResourceOperationPredicate) Matches(input RecoveryPointResource) 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/recoveryservicesbackup/2023-02-01/recoverypoints/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/version.go new file mode 100644 index 00000000000..eaaccaad2f2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypoints/version.go @@ -0,0 +1,12 @@ +package recoverypoints + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverypoints/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/README.md new file mode 100644 index 00000000000..e5e86fb9a2f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove` Documentation + +The `recoverypointsrecommendedformove` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove" +``` + + +### Client Initialization + +```go +client := recoverypointsrecommendedformove.NewRecoveryPointsRecommendedForMoveClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoveryPointsRecommendedForMoveClient.List` + +```go +ctx := context.TODO() +id := recoverypointsrecommendedformove.NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + +payload := recoverypointsrecommendedformove.ListRecoveryPointsRecommendedForMoveRequest{ + // ... +} + + +// alternatively `client.List(ctx, id, payload)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, payload) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/client.go new file mode 100644 index 00000000000..0f891c24f9b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/client.go @@ -0,0 +1,18 @@ +package recoverypointsrecommendedformove + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointsRecommendedForMoveClient struct { + Client autorest.Client + baseUri string +} + +func NewRecoveryPointsRecommendedForMoveClientWithBaseURI(endpoint string) RecoveryPointsRecommendedForMoveClient { + return RecoveryPointsRecommendedForMoveClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/constants.go new file mode 100644 index 00000000000..e2e55355df0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/constants.go @@ -0,0 +1,151 @@ +package recoverypointsrecommendedformove + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointTierStatus string + +const ( + RecoveryPointTierStatusDeleted RecoveryPointTierStatus = "Deleted" + RecoveryPointTierStatusDisabled RecoveryPointTierStatus = "Disabled" + RecoveryPointTierStatusInvalid RecoveryPointTierStatus = "Invalid" + RecoveryPointTierStatusRehydrated RecoveryPointTierStatus = "Rehydrated" + RecoveryPointTierStatusValid RecoveryPointTierStatus = "Valid" +) + +func PossibleValuesForRecoveryPointTierStatus() []string { + return []string{ + string(RecoveryPointTierStatusDeleted), + string(RecoveryPointTierStatusDisabled), + string(RecoveryPointTierStatusInvalid), + string(RecoveryPointTierStatusRehydrated), + string(RecoveryPointTierStatusValid), + } +} + +func parseRecoveryPointTierStatus(input string) (*RecoveryPointTierStatus, error) { + vals := map[string]RecoveryPointTierStatus{ + "deleted": RecoveryPointTierStatusDeleted, + "disabled": RecoveryPointTierStatusDisabled, + "invalid": RecoveryPointTierStatusInvalid, + "rehydrated": RecoveryPointTierStatusRehydrated, + "valid": RecoveryPointTierStatusValid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointTierStatus(input) + return &out, nil +} + +type RecoveryPointTierType string + +const ( + RecoveryPointTierTypeArchivedRP RecoveryPointTierType = "ArchivedRP" + RecoveryPointTierTypeHardenedRP RecoveryPointTierType = "HardenedRP" + RecoveryPointTierTypeInstantRP RecoveryPointTierType = "InstantRP" + RecoveryPointTierTypeInvalid RecoveryPointTierType = "Invalid" +) + +func PossibleValuesForRecoveryPointTierType() []string { + return []string{ + string(RecoveryPointTierTypeArchivedRP), + string(RecoveryPointTierTypeHardenedRP), + string(RecoveryPointTierTypeInstantRP), + string(RecoveryPointTierTypeInvalid), + } +} + +func parseRecoveryPointTierType(input string) (*RecoveryPointTierType, error) { + vals := map[string]RecoveryPointTierType{ + "archivedrp": RecoveryPointTierTypeArchivedRP, + "hardenedrp": RecoveryPointTierTypeHardenedRP, + "instantrp": RecoveryPointTierTypeInstantRP, + "invalid": RecoveryPointTierTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointTierType(input) + return &out, nil +} + +type RestorePointType string + +const ( + RestorePointTypeDifferential RestorePointType = "Differential" + RestorePointTypeFull RestorePointType = "Full" + RestorePointTypeIncremental RestorePointType = "Incremental" + RestorePointTypeInvalid RestorePointType = "Invalid" + RestorePointTypeLog RestorePointType = "Log" + RestorePointTypeSnapshotCopyOnlyFull RestorePointType = "SnapshotCopyOnlyFull" + RestorePointTypeSnapshotFull RestorePointType = "SnapshotFull" +) + +func PossibleValuesForRestorePointType() []string { + return []string{ + string(RestorePointTypeDifferential), + string(RestorePointTypeFull), + string(RestorePointTypeIncremental), + string(RestorePointTypeInvalid), + string(RestorePointTypeLog), + string(RestorePointTypeSnapshotCopyOnlyFull), + string(RestorePointTypeSnapshotFull), + } +} + +func parseRestorePointType(input string) (*RestorePointType, error) { + vals := map[string]RestorePointType{ + "differential": RestorePointTypeDifferential, + "full": RestorePointTypeFull, + "incremental": RestorePointTypeIncremental, + "invalid": RestorePointTypeInvalid, + "log": RestorePointTypeLog, + "snapshotcopyonlyfull": RestorePointTypeSnapshotCopyOnlyFull, + "snapshotfull": RestorePointTypeSnapshotFull, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestorePointType(input) + return &out, nil +} + +type SQLDataDirectoryType string + +const ( + SQLDataDirectoryTypeData SQLDataDirectoryType = "Data" + SQLDataDirectoryTypeInvalid SQLDataDirectoryType = "Invalid" + SQLDataDirectoryTypeLog SQLDataDirectoryType = "Log" +) + +func PossibleValuesForSQLDataDirectoryType() []string { + return []string{ + string(SQLDataDirectoryTypeData), + string(SQLDataDirectoryTypeInvalid), + string(SQLDataDirectoryTypeLog), + } +} + +func parseSQLDataDirectoryType(input string) (*SQLDataDirectoryType, error) { + vals := map[string]SQLDataDirectoryType{ + "data": SQLDataDirectoryTypeData, + "invalid": SQLDataDirectoryTypeInvalid, + "log": SQLDataDirectoryTypeLog, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SQLDataDirectoryType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/id_protecteditem.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/id_protecteditem.go new file mode 100644 index 00000000000..6dad445d0cf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/id_protecteditem.go @@ -0,0 +1,166 @@ +package recoverypointsrecommendedformove + +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 = ProtectedItemId{} + +// ProtectedItemId is a struct representing the Resource ID for a Protected Item +type ProtectedItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string +} + +// NewProtectedItemID returns a new ProtectedItemId struct +func NewProtectedItemID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string) ProtectedItemId { + return ProtectedItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + } +} + +// ParseProtectedItemID parses 'input' into a ProtectedItemId +func ParseProtectedItemID(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProtectedItemIDInsensitively parses 'input' case-insensitively into a ProtectedItemId +// note: this method should only be used for API response data and not user input +func ParseProtectedItemIDInsensitively(input string) (*ProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ProtectedItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProtectedItemID checks that 'input' can be parsed as a Protected Item ID +func ValidateProtectedItemID(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 := ParseProtectedItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Protected Item ID +func (id ProtectedItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Protected Item ID +func (id ProtectedItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + } +} + +// String returns a human-readable description of this Protected Item ID +func (id ProtectedItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + } + return fmt.Sprintf("Protected Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/id_protecteditem_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/id_protecteditem_test.go new file mode 100644 index 00000000000..bfdb3476ef2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/id_protecteditem_test.go @@ -0,0 +1,417 @@ +package recoverypointsrecommendedformove + +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 = ProtectedItemId{} + +func TestNewProtectedItemID(t *testing.T) { + id := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } +} + +func TestFormatProtectedItemID(t *testing.T) { + actual := NewProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProtectedItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestParseProtectedItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Expected: &ProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProtectedItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + } +} + +func TestSegmentsForProtectedItemId(t *testing.T) { + segments := ProtectedItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProtectedItemId 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/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/method_list_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/method_list_autorest.go new file mode 100644 index 00000000000..71847a51411 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/method_list_autorest.go @@ -0,0 +1,187 @@ +package recoverypointsrecommendedformove + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]RecoveryPointResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []RecoveryPointResource +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c RecoveryPointsRecommendedForMoveClient) List(ctx context.Context, id ProtectedItemId, input ListRecoveryPointsRecommendedForMoveRequest) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypointsrecommendedformove.RecoveryPointsRecommendedForMoveClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypointsrecommendedformove.RecoveryPointsRecommendedForMoveClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypointsrecommendedformove.RecoveryPointsRecommendedForMoveClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c RecoveryPointsRecommendedForMoveClient) preparerForList(ctx context.Context, id ProtectedItemId, input ListRecoveryPointsRecommendedForMoveRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/recoveryPointsRecommendedForMove", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c RecoveryPointsRecommendedForMoveClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c RecoveryPointsRecommendedForMoveClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []RecoveryPointResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypointsrecommendedformove.RecoveryPointsRecommendedForMoveClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypointsrecommendedformove.RecoveryPointsRecommendedForMoveClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypointsrecommendedformove.RecoveryPointsRecommendedForMoveClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c RecoveryPointsRecommendedForMoveClient) ListComplete(ctx context.Context, id ProtectedItemId, input ListRecoveryPointsRecommendedForMoveRequest) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, input, RecoveryPointResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c RecoveryPointsRecommendedForMoveClient) ListCompleteMatchingPredicate(ctx context.Context, id ProtectedItemId, input ListRecoveryPointsRecommendedForMoveRequest, predicate RecoveryPointResourceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]RecoveryPointResource, 0) + + page, err := c.List(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azurefilesharerecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azurefilesharerecoverypoint.go new file mode 100644 index 00000000000..3654d6b1bf1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azurefilesharerecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypointsrecommendedformove + +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 _ RecoveryPoint = AzureFileShareRecoveryPoint{} + +type AzureFileShareRecoveryPoint struct { + FileShareSnapshotUri *string `json:"fileShareSnapshotUri,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointSizeInGB *int64 `json:"recoveryPointSizeInGB,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureFileShareRecoveryPoint{} + +func (s AzureFileShareRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureFileShareRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadpointintimerecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadpointintimerecoverypoint.go new file mode 100644 index 00000000000..4b477077a01 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadpointintimerecoverypoint.go @@ -0,0 +1,46 @@ +package recoverypointsrecommendedformove + +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 _ RecoveryPoint = AzureWorkloadPointInTimeRecoveryPoint{} + +type AzureWorkloadPointInTimeRecoveryPoint struct { + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + TimeRanges *[]PointInTimeRange `json:"timeRanges,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadPointInTimeRecoveryPoint{} + +func (s AzureWorkloadPointInTimeRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadPointInTimeRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadPointInTimeRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadrecoverypoint.go new file mode 100644 index 00000000000..6c7e5f6b958 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadrecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypointsrecommendedformove + +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 _ RecoveryPoint = AzureWorkloadRecoveryPoint{} + +type AzureWorkloadRecoveryPoint struct { + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadRecoveryPoint{} + +func (s AzureWorkloadRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsaphanarecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsaphanarecoverypoint.go new file mode 100644 index 00000000000..4ca5f3470d3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsaphanarecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypointsrecommendedformove + +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 _ RecoveryPoint = AzureWorkloadSAPHanaRecoveryPoint{} + +type AzureWorkloadSAPHanaRecoveryPoint struct { + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadSAPHanaRecoveryPoint{} + +func (s AzureWorkloadSAPHanaRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSAPHanaRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSAPHanaRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsqlrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsqlrecoverypoint.go new file mode 100644 index 00000000000..0e441f79cda --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsqlrecoverypoint.go @@ -0,0 +1,46 @@ +package recoverypointsrecommendedformove + +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 _ RecoveryPoint = AzureWorkloadSQLRecoveryPoint{} + +type AzureWorkloadSQLRecoveryPoint struct { + ExtendedInfo *AzureWorkloadSQLRecoveryPointExtendedInfo `json:"extendedInfo,omitempty"` + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTimeInUTC *string `json:"recoveryPointTimeInUTC,omitempty"` + Type *RestorePointType `json:"type,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = AzureWorkloadSQLRecoveryPoint{} + +func (s AzureWorkloadSQLRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSQLRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSQLRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSQLRecoveryPoint: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSQLRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSQLRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsqlrecoverypointextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsqlrecoverypointextendedinfo.go new file mode 100644 index 00000000000..f98b9b7a0b4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_azureworkloadsqlrecoverypointextendedinfo.go @@ -0,0 +1,27 @@ +package recoverypointsrecommendedformove + +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 AzureWorkloadSQLRecoveryPointExtendedInfo struct { + DataDirectoryPaths *[]SQLDataDirectory `json:"dataDirectoryPaths,omitempty"` + DataDirectoryTimeInUTC *string `json:"dataDirectoryTimeInUTC,omitempty"` +} + +func (o *AzureWorkloadSQLRecoveryPointExtendedInfo) GetDataDirectoryTimeInUTCAsTime() (*time.Time, error) { + if o.DataDirectoryTimeInUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DataDirectoryTimeInUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureWorkloadSQLRecoveryPointExtendedInfo) SetDataDirectoryTimeInUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DataDirectoryTimeInUTC = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_bekdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_bekdetails.go new file mode 100644 index 00000000000..2060eb3fa42 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_bekdetails.go @@ -0,0 +1,10 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BEKDetails struct { + SecretData *string `json:"secretData,omitempty"` + SecretUrl *string `json:"secretUrl,omitempty"` + SecretVaultId *string `json:"secretVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_diskinformation.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_diskinformation.go new file mode 100644 index 00000000000..efce1750999 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_diskinformation.go @@ -0,0 +1,9 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskInformation struct { + Lun *int64 `json:"lun,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_genericrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_genericrecoverypoint.go new file mode 100644 index 00000000000..040a2cf2cc1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_genericrecoverypoint.go @@ -0,0 +1,45 @@ +package recoverypointsrecommendedformove + +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 _ RecoveryPoint = GenericRecoveryPoint{} + +type GenericRecoveryPoint struct { + FriendlyName *string `json:"friendlyName,omitempty"` + RecoveryPointAdditionalInfo *string `json:"recoveryPointAdditionalInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = GenericRecoveryPoint{} + +func (s GenericRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper GenericRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericRecoveryPoint: %+v", err) + } + decoded["objectType"] = "GenericRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_iaasvmrecoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_iaasvmrecoverypoint.go new file mode 100644 index 00000000000..5d61b82ee31 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_iaasvmrecoverypoint.go @@ -0,0 +1,60 @@ +package recoverypointsrecommendedformove + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RecoveryPoint = IaasVMRecoveryPoint{} + +type IaasVMRecoveryPoint struct { + IsInstantIlrSessionActive *bool `json:"isInstantIlrSessionActive,omitempty"` + IsManagedVirtualMachine *bool `json:"isManagedVirtualMachine,omitempty"` + IsPrivateAccessEnabledOnAnyDisk *bool `json:"isPrivateAccessEnabledOnAnyDisk,omitempty"` + IsSourceVMEncrypted *bool `json:"isSourceVMEncrypted,omitempty"` + KeyAndSecret *KeyAndSecretDetails `json:"keyAndSecret,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + OsType *string `json:"osType,omitempty"` + RecoveryPointAdditionalInfo *string `json:"recoveryPointAdditionalInfo,omitempty"` + RecoveryPointDiskConfiguration *RecoveryPointDiskConfiguration `json:"recoveryPointDiskConfiguration,omitempty"` + RecoveryPointMoveReadinessInfo *map[string]RecoveryPointMoveReadinessInfo `json:"recoveryPointMoveReadinessInfo,omitempty"` + RecoveryPointProperties *RecoveryPointProperties `json:"recoveryPointProperties,omitempty"` + RecoveryPointTierDetails *[]RecoveryPointTierInformationV2 `json:"recoveryPointTierDetails,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + SecurityType *string `json:"securityType,omitempty"` + SourceVMStorageType *string `json:"sourceVMStorageType,omitempty"` + VirtualMachineSize *string `json:"virtualMachineSize,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RecoveryPoint +} + +var _ json.Marshaler = IaasVMRecoveryPoint{} + +func (s IaasVMRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRecoveryPoint: %+v", err) + } + decoded["objectType"] = "IaasVMRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_kekdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_kekdetails.go new file mode 100644 index 00000000000..a3aeb5f2512 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_kekdetails.go @@ -0,0 +1,10 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KEKDetails struct { + KeyBackupData *string `json:"keyBackupData,omitempty"` + KeyUrl *string `json:"keyUrl,omitempty"` + KeyVaultId *string `json:"keyVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_keyandsecretdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_keyandsecretdetails.go new file mode 100644 index 00000000000..65444fc0f49 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_keyandsecretdetails.go @@ -0,0 +1,10 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyAndSecretDetails struct { + BekDetails *BEKDetails `json:"bekDetails,omitempty"` + EncryptionMechanism *string `json:"encryptionMechanism,omitempty"` + KekDetails *KEKDetails `json:"kekDetails,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_listrecoverypointsrecommendedformoverequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_listrecoverypointsrecommendedformoverequest.go new file mode 100644 index 00000000000..0085a2a3b9d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_listrecoverypointsrecommendedformoverequest.go @@ -0,0 +1,9 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListRecoveryPointsRecommendedForMoveRequest struct { + ExcludedRPList *[]string `json:"excludedRPList,omitempty"` + ObjectType *string `json:"objectType,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_pointintimerange.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_pointintimerange.go new file mode 100644 index 00000000000..9bb33473707 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_pointintimerange.go @@ -0,0 +1,39 @@ +package recoverypointsrecommendedformove + +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 PointInTimeRange struct { + EndTime *string `json:"endTime,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *PointInTimeRange) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PointInTimeRange) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *PointInTimeRange) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PointInTimeRange) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypoint.go new file mode 100644 index 00000000000..08c0284bd6b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypoint.go @@ -0,0 +1,96 @@ +package recoverypointsrecommendedformove + +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 RecoveryPoint interface { +} + +func unmarshalRecoveryPointImplementation(input []byte) (RecoveryPoint, 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 RecoveryPoint into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareRecoveryPoint") { + var out AzureFileShareRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadPointInTimeRecoveryPoint") { + var out AzureWorkloadPointInTimeRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadPointInTimeRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadRecoveryPoint") { + var out AzureWorkloadRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSAPHanaRecoveryPoint") { + var out AzureWorkloadSAPHanaRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSAPHanaRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSQLRecoveryPoint") { + var out AzureWorkloadSQLRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSQLRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericRecoveryPoint") { + var out GenericRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericRecoveryPoint: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRecoveryPoint") { + var out IaasVMRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRecoveryPoint: %+v", err) + } + return out, nil + } + + type RawRecoveryPointImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryPointImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointdiskconfiguration.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointdiskconfiguration.go new file mode 100644 index 00000000000..6ec831b050f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointdiskconfiguration.go @@ -0,0 +1,11 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointDiskConfiguration struct { + ExcludedDiskList *[]DiskInformation `json:"excludedDiskList,omitempty"` + IncludedDiskList *[]DiskInformation `json:"includedDiskList,omitempty"` + NumberOfDisksAttachedToVM *int64 `json:"numberOfDisksAttachedToVm,omitempty"` + NumberOfDisksIncludedInBackup *int64 `json:"numberOfDisksIncludedInBackup,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointmovereadinessinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointmovereadinessinfo.go new file mode 100644 index 00000000000..2f638ab7bcd --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointmovereadinessinfo.go @@ -0,0 +1,9 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointMoveReadinessInfo struct { + AdditionalInfo *string `json:"additionalInfo,omitempty"` + IsReadyForMove *bool `json:"isReadyForMove,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointproperties.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointproperties.go new file mode 100644 index 00000000000..97af2516cec --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointproperties.go @@ -0,0 +1,10 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointProperties struct { + ExpiryTime *string `json:"expiryTime,omitempty"` + IsSoftDeleted *bool `json:"isSoftDeleted,omitempty"` + RuleName *string `json:"ruleName,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointresource.go new file mode 100644 index 00000000000..26a0bbdce62 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointresource.go @@ -0,0 +1,50 @@ +package recoverypointsrecommendedformove + +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 RecoveryPointResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties RecoveryPoint `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &RecoveryPointResource{} + +func (s *RecoveryPointResource) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPointResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPointResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPointResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalRecoveryPointImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'RecoveryPointResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointtierinformationv2.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointtierinformationv2.go new file mode 100644 index 00000000000..6f014df3e1d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_recoverypointtierinformationv2.go @@ -0,0 +1,10 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointTierInformationV2 struct { + ExtendedInfo *map[string]string `json:"extendedInfo,omitempty"` + Status *RecoveryPointTierStatus `json:"status,omitempty"` + Type *RecoveryPointTierType `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_sqldatadirectory.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_sqldatadirectory.go new file mode 100644 index 00000000000..74ae63ba5e5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/model_sqldatadirectory.go @@ -0,0 +1,10 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SQLDataDirectory struct { + LogicalName *string `json:"logicalName,omitempty"` + Path *string `json:"path,omitempty"` + Type *SQLDataDirectoryType `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/predicates.go new file mode 100644 index 00000000000..d6cd7490cce --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/predicates.go @@ -0,0 +1,37 @@ +package recoverypointsrecommendedformove + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p RecoveryPointResourceOperationPredicate) Matches(input RecoveryPointResource) 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/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/version.go new file mode 100644 index 00000000000..2439709477a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/recoverypointsrecommendedformove/version.go @@ -0,0 +1,12 @@ +package recoverypointsrecommendedformove + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverypointsrecommendedformove/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/README.md new file mode 100644 index 00000000000..46f7ef32e38 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies` Documentation + +The `resourceguardproxies` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/resourceguardproxies" +``` + + +### Client Initialization + +```go +client := resourceguardproxies.NewResourceGuardProxiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourceGuardProxiesClient.Get` + +```go +ctx := context.TODO() +id := resourceguardproxies.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.Get(ctx, id)` can be used to do batched pagination +items, err := client.GetComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/client.go new file mode 100644 index 00000000000..ad46ba07081 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/client.go @@ -0,0 +1,18 @@ +package resourceguardproxies + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardProxiesClient struct { + Client autorest.Client + baseUri string +} + +func NewResourceGuardProxiesClientWithBaseURI(endpoint string) ResourceGuardProxiesClient { + return ResourceGuardProxiesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/id_vault.go new file mode 100644 index 00000000000..89902449e4f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/id_vault.go @@ -0,0 +1,127 @@ +package resourceguardproxies + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/id_vault_test.go new file mode 100644 index 00000000000..0a81935aa77 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/id_vault_test.go @@ -0,0 +1,282 @@ +package resourceguardproxies + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/resourceguardproxies/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/method_get_autorest.go new file mode 100644 index 00000000000..d7c440b262d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/method_get_autorest.go @@ -0,0 +1,186 @@ +package resourceguardproxies + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *[]ResourceGuardProxyBaseResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (GetOperationResponse, error) +} + +type GetCompleteResult struct { + Items []ResourceGuardProxyBaseResource +} + +func (r GetOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r GetOperationResponse) LoadMore(ctx context.Context) (resp GetOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// Get ... +func (c ResourceGuardProxiesClient) Get(ctx context.Context, id VaultId) (resp GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxies.ResourceGuardProxiesClient", "Get", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxies.ResourceGuardProxiesClient", "Get", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForGet(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxies.ResourceGuardProxiesClient", "Get", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForGet prepares the Get request. +func (c ResourceGuardProxiesClient) preparerForGet(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupResourceGuardProxies", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForGetWithNextLink prepares the Get request with the given nextLink token. +func (c ResourceGuardProxiesClient) preparerForGetWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ResourceGuardProxiesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + type page struct { + Values []ResourceGuardProxyBaseResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result GetOperationResponse, err error) { + req, err := c.preparerForGetWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxies.ResourceGuardProxiesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxies.ResourceGuardProxiesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxies.ResourceGuardProxiesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// GetComplete retrieves all of the results into a single object +func (c ResourceGuardProxiesClient) GetComplete(ctx context.Context, id VaultId) (GetCompleteResult, error) { + return c.GetCompleteMatchingPredicate(ctx, id, ResourceGuardProxyBaseResourceOperationPredicate{}) +} + +// GetCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ResourceGuardProxiesClient) GetCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate ResourceGuardProxyBaseResourceOperationPredicate) (resp GetCompleteResult, err error) { + items := make([]ResourceGuardProxyBaseResource, 0) + + page, err := c.Get(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := GetCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardoperationdetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardoperationdetail.go new file mode 100644 index 00000000000..fedeee2c425 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardoperationdetail.go @@ -0,0 +1,9 @@ +package resourceguardproxies + +// 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/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardproxybase.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardproxybase.go new file mode 100644 index 00000000000..2d20e7f31b5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardproxybase.go @@ -0,0 +1,11 @@ +package resourceguardproxies + +// 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/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardproxybaseresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardproxybaseresource.go new file mode 100644 index 00000000000..bc307c162c1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/model_resourceguardproxybaseresource.go @@ -0,0 +1,14 @@ +package resourceguardproxies + +// 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 { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGuardProxyBase `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/predicates.go new file mode 100644 index 00000000000..979152ae703 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/predicates.go @@ -0,0 +1,37 @@ +package resourceguardproxies + +// 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 { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ResourceGuardProxyBaseResourceOperationPredicate) Matches(input ResourceGuardProxyBaseResource) 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/recoveryservicesbackup/2023-02-01/resourceguardproxies/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/version.go new file mode 100644 index 00000000000..d4864f03caa --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxies/version.go @@ -0,0 +1,12 @@ +package resourceguardproxies + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/resourceguardproxies/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/README.md new file mode 100644 index 00000000000..bf01ad9c85d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/README.md @@ -0,0 +1,94 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy` Documentation + +The `resourceguardproxy` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/resourceguardproxy" +``` + + +### Client Initialization + +```go +client := resourceguardproxy.NewResourceGuardProxyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourceGuardProxyClient.Delete` + +```go +ctx := context.TODO() +id := resourceguardproxy.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupResourceGuardProxyValue") + +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: `ResourceGuardProxyClient.Get` + +```go +ctx := context.TODO() +id := resourceguardproxy.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupResourceGuardProxyValue") + +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: `ResourceGuardProxyClient.Put` + +```go +ctx := context.TODO() +id := resourceguardproxy.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupResourceGuardProxyValue") + +payload := resourceguardproxy.ResourceGuardProxyBaseResource{ + // ... +} + + +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 +} +``` + + +### Example Usage: `ResourceGuardProxyClient.UnlockDelete` + +```go +ctx := context.TODO() +id := resourceguardproxy.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupResourceGuardProxyValue") + +payload := resourceguardproxy.UnlockDeleteRequest{ + // ... +} + + +read, err := client.UnlockDelete(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/recoveryservicesbackup/2023-02-01/resourceguardproxy/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/client.go new file mode 100644 index 00000000000..d07fa6e5381 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/client.go @@ -0,0 +1,18 @@ +package resourceguardproxy + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardProxyClient struct { + Client autorest.Client + baseUri string +} + +func NewResourceGuardProxyClientWithBaseURI(endpoint string) ResourceGuardProxyClient { + return ResourceGuardProxyClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/id_backupresourceguardproxy.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/id_backupresourceguardproxy.go new file mode 100644 index 00000000000..f4801c7a562 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/id_backupresourceguardproxy.go @@ -0,0 +1,140 @@ +package resourceguardproxy + +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 + VaultName string + BackupResourceGuardProxyName string +} + +// NewBackupResourceGuardProxyID returns a new BackupResourceGuardProxyId struct +func NewBackupResourceGuardProxyID(subscriptionId string, resourceGroupName string, vaultName string, backupResourceGuardProxyName string) BackupResourceGuardProxyId { + return BackupResourceGuardProxyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + 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) + } + + var ok bool + id := BackupResourceGuardProxyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupResourceGuardProxyName, ok = parsed.Parsed["backupResourceGuardProxyName"]; !ok { + return nil, fmt.Errorf("the segment 'backupResourceGuardProxyName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := BackupResourceGuardProxyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupResourceGuardProxyName, ok = parsed.Parsed["backupResourceGuardProxyName"]; !ok { + return nil, fmt.Errorf("the segment 'backupResourceGuardProxyName' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupResourceGuardProxies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + 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("Vault Name: %q", id.VaultName), + 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/recoveryservicesbackup/2023-02-01/resourceguardproxy/id_backupresourceguardproxy_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/id_backupresourceguardproxy_test.go new file mode 100644 index 00000000000..05ebe0dc40c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/id_backupresourceguardproxy_test.go @@ -0,0 +1,327 @@ +package resourceguardproxy + +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", "vaultValue", "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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + 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", "vaultValue", "backupResourceGuardProxyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupResourceGuardProxies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupResourceGuardProxies/backupResourceGuardProxyValue", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupResourceGuardProxyName: "backupResourceGuardProxyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupResourceGuardProxies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPrEsOuRcEgUaRdPrOxIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupResourceGuardProxies/backupResourceGuardProxyValue", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupResourceGuardProxyName: "backupResourceGuardProxyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPrEsOuRcEgUaRdPrOxIeS/bAcKuPrEsOuRcEgUaRdPrOxYvAlUe", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + 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/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_delete_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_delete_autorest.go new file mode 100644 index 00000000000..5bc566a1459 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_delete_autorest.go @@ -0,0 +1,66 @@ +package resourceguardproxy + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ResourceGuardProxyClient) Delete(ctx context.Context, id BackupResourceGuardProxyId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ResourceGuardProxyClient) preparerForDelete(ctx context.Context, id BackupResourceGuardProxyId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c ResourceGuardProxyClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_get_autorest.go new file mode 100644 index 00000000000..34cbc308b05 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_get_autorest.go @@ -0,0 +1,68 @@ +package resourceguardproxy + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ResourceGuardProxyBaseResource +} + +// Get ... +func (c ResourceGuardProxyClient) Get(ctx context.Context, id BackupResourceGuardProxyId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ResourceGuardProxyClient) preparerForGet(ctx context.Context, id BackupResourceGuardProxyId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ResourceGuardProxyClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_put_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_put_autorest.go new file mode 100644 index 00000000000..251f699920c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_put_autorest.go @@ -0,0 +1,69 @@ +package resourceguardproxy + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutOperationResponse struct { + HttpResponse *http.Response + Model *ResourceGuardProxyBaseResource +} + +// Put ... +func (c ResourceGuardProxyClient) Put(ctx context.Context, id BackupResourceGuardProxyId, input ResourceGuardProxyBaseResource) (result PutOperationResponse, err error) { + req, err := c.preparerForPut(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Put", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Put", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPut(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "Put", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPut prepares the Put request. +func (c ResourceGuardProxyClient) preparerForPut(ctx context.Context, id BackupResourceGuardProxyId, input ResourceGuardProxyBaseResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPut handles the response to the Put request. The method always +// closes the http.Response Body. +func (c ResourceGuardProxyClient) responderForPut(resp *http.Response) (result PutOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_unlockdelete_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_unlockdelete_autorest.go new file mode 100644 index 00000000000..4ddf4864869 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/method_unlockdelete_autorest.go @@ -0,0 +1,70 @@ +package resourceguardproxy + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnlockDeleteOperationResponse struct { + HttpResponse *http.Response + Model *UnlockDeleteResponse +} + +// UnlockDelete ... +func (c ResourceGuardProxyClient) UnlockDelete(ctx context.Context, id BackupResourceGuardProxyId, input UnlockDeleteRequest) (result UnlockDeleteOperationResponse, err error) { + req, err := c.preparerForUnlockDelete(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "UnlockDelete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "UnlockDelete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUnlockDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "resourceguardproxy.ResourceGuardProxyClient", "UnlockDelete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUnlockDelete prepares the UnlockDelete request. +func (c ResourceGuardProxyClient) preparerForUnlockDelete(ctx context.Context, id BackupResourceGuardProxyId, input UnlockDeleteRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/unlockDelete", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUnlockDelete handles the response to the UnlockDelete request. The method always +// closes the http.Response Body. +func (c ResourceGuardProxyClient) responderForUnlockDelete(resp *http.Response) (result UnlockDeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardoperationdetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardoperationdetail.go new file mode 100644 index 00000000000..a211e1f34bb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardoperationdetail.go @@ -0,0 +1,9 @@ +package resourceguardproxy + +// 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/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardproxybase.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardproxybase.go new file mode 100644 index 00000000000..a9fa6c988f8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardproxybase.go @@ -0,0 +1,11 @@ +package resourceguardproxy + +// 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/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardproxybaseresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardproxybaseresource.go new file mode 100644 index 00000000000..f68fdd803b7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_resourceguardproxybaseresource.go @@ -0,0 +1,14 @@ +package resourceguardproxy + +// 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 { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGuardProxyBase `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_unlockdeleterequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_unlockdeleterequest.go new file mode 100644 index 00000000000..5ed0ee6ebfe --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_unlockdeleterequest.go @@ -0,0 +1,9 @@ +package resourceguardproxy + +// 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/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_unlockdeleteresponse.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_unlockdeleteresponse.go new file mode 100644 index 00000000000..6304a0fa5e6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/model_unlockdeleteresponse.go @@ -0,0 +1,8 @@ +package resourceguardproxy + +// 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/recoveryservicesbackup/2023-02-01/resourceguardproxy/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/version.go new file mode 100644 index 00000000000..c3087a3194e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/resourceguardproxy/version.go @@ -0,0 +1,12 @@ +package resourceguardproxy + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/resourceguardproxy/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/restores/README.md new file mode 100644 index 00000000000..d7601722629 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/restores` Documentation + +The `restores` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/restores" +``` + + +### Client Initialization + +```go +client := restores.NewRestoresClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RestoresClient.Trigger` + +```go +ctx := context.TODO() +id := restores.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue") + +payload := restores.RestoreRequestResource{ + // ... +} + + +if err := client.TriggerThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/client.go new file mode 100644 index 00000000000..3263d991a1e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/client.go @@ -0,0 +1,18 @@ +package restores + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestoresClient struct { + Client autorest.Client + baseUri string +} + +func NewRestoresClientWithBaseURI(endpoint string) RestoresClient { + return RestoresClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/constants.go new file mode 100644 index 00000000000..6dcd4b901b7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/constants.go @@ -0,0 +1,263 @@ +package restores + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CopyOptions string + +const ( + CopyOptionsCreateCopy CopyOptions = "CreateCopy" + CopyOptionsFailOnConflict CopyOptions = "FailOnConflict" + CopyOptionsInvalid CopyOptions = "Invalid" + CopyOptionsOverwrite CopyOptions = "Overwrite" + CopyOptionsSkip CopyOptions = "Skip" +) + +func PossibleValuesForCopyOptions() []string { + return []string{ + string(CopyOptionsCreateCopy), + string(CopyOptionsFailOnConflict), + string(CopyOptionsInvalid), + string(CopyOptionsOverwrite), + string(CopyOptionsSkip), + } +} + +func parseCopyOptions(input string) (*CopyOptions, error) { + vals := map[string]CopyOptions{ + "createcopy": CopyOptionsCreateCopy, + "failonconflict": CopyOptionsFailOnConflict, + "invalid": CopyOptionsInvalid, + "overwrite": CopyOptionsOverwrite, + "skip": CopyOptionsSkip, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CopyOptions(input) + return &out, nil +} + +type OverwriteOptions string + +const ( + OverwriteOptionsFailOnConflict OverwriteOptions = "FailOnConflict" + OverwriteOptionsInvalid OverwriteOptions = "Invalid" + OverwriteOptionsOverwrite OverwriteOptions = "Overwrite" +) + +func PossibleValuesForOverwriteOptions() []string { + return []string{ + string(OverwriteOptionsFailOnConflict), + string(OverwriteOptionsInvalid), + string(OverwriteOptionsOverwrite), + } +} + +func parseOverwriteOptions(input string) (*OverwriteOptions, error) { + vals := map[string]OverwriteOptions{ + "failonconflict": OverwriteOptionsFailOnConflict, + "invalid": OverwriteOptionsInvalid, + "overwrite": OverwriteOptionsOverwrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OverwriteOptions(input) + return &out, nil +} + +type RecoveryMode string + +const ( + RecoveryModeFileRecovery RecoveryMode = "FileRecovery" + RecoveryModeInvalid RecoveryMode = "Invalid" + RecoveryModeWorkloadRecovery RecoveryMode = "WorkloadRecovery" +) + +func PossibleValuesForRecoveryMode() []string { + return []string{ + string(RecoveryModeFileRecovery), + string(RecoveryModeInvalid), + string(RecoveryModeWorkloadRecovery), + } +} + +func parseRecoveryMode(input string) (*RecoveryMode, error) { + vals := map[string]RecoveryMode{ + "filerecovery": RecoveryModeFileRecovery, + "invalid": RecoveryModeInvalid, + "workloadrecovery": RecoveryModeWorkloadRecovery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryMode(input) + return &out, nil +} + +type RecoveryType string + +const ( + RecoveryTypeAlternateLocation RecoveryType = "AlternateLocation" + RecoveryTypeInvalid RecoveryType = "Invalid" + RecoveryTypeOffline RecoveryType = "Offline" + RecoveryTypeOriginalLocation RecoveryType = "OriginalLocation" + RecoveryTypeRestoreDisks RecoveryType = "RestoreDisks" +) + +func PossibleValuesForRecoveryType() []string { + return []string{ + string(RecoveryTypeAlternateLocation), + string(RecoveryTypeInvalid), + string(RecoveryTypeOffline), + string(RecoveryTypeOriginalLocation), + string(RecoveryTypeRestoreDisks), + } +} + +func parseRecoveryType(input string) (*RecoveryType, error) { + vals := map[string]RecoveryType{ + "alternatelocation": RecoveryTypeAlternateLocation, + "invalid": RecoveryTypeInvalid, + "offline": RecoveryTypeOffline, + "originallocation": RecoveryTypeOriginalLocation, + "restoredisks": RecoveryTypeRestoreDisks, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryType(input) + return &out, nil +} + +type RehydrationPriority string + +const ( + RehydrationPriorityHigh RehydrationPriority = "High" + RehydrationPriorityStandard RehydrationPriority = "Standard" +) + +func PossibleValuesForRehydrationPriority() []string { + return []string{ + string(RehydrationPriorityHigh), + string(RehydrationPriorityStandard), + } +} + +func parseRehydrationPriority(input string) (*RehydrationPriority, error) { + vals := map[string]RehydrationPriority{ + "high": RehydrationPriorityHigh, + "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 RestoreRequestType string + +const ( + RestoreRequestTypeFullShareRestore RestoreRequestType = "FullShareRestore" + RestoreRequestTypeInvalid RestoreRequestType = "Invalid" + RestoreRequestTypeItemLevelRestore RestoreRequestType = "ItemLevelRestore" +) + +func PossibleValuesForRestoreRequestType() []string { + return []string{ + string(RestoreRequestTypeFullShareRestore), + string(RestoreRequestTypeInvalid), + string(RestoreRequestTypeItemLevelRestore), + } +} + +func parseRestoreRequestType(input string) (*RestoreRequestType, error) { + vals := map[string]RestoreRequestType{ + "fullsharerestore": RestoreRequestTypeFullShareRestore, + "invalid": RestoreRequestTypeInvalid, + "itemlevelrestore": RestoreRequestTypeItemLevelRestore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestoreRequestType(input) + return &out, nil +} + +type SQLDataDirectoryType string + +const ( + SQLDataDirectoryTypeData SQLDataDirectoryType = "Data" + SQLDataDirectoryTypeInvalid SQLDataDirectoryType = "Invalid" + SQLDataDirectoryTypeLog SQLDataDirectoryType = "Log" +) + +func PossibleValuesForSQLDataDirectoryType() []string { + return []string{ + string(SQLDataDirectoryTypeData), + string(SQLDataDirectoryTypeInvalid), + string(SQLDataDirectoryTypeLog), + } +} + +func parseSQLDataDirectoryType(input string) (*SQLDataDirectoryType, error) { + vals := map[string]SQLDataDirectoryType{ + "data": SQLDataDirectoryTypeData, + "invalid": SQLDataDirectoryTypeInvalid, + "log": SQLDataDirectoryTypeLog, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SQLDataDirectoryType(input) + return &out, nil +} + +type TargetDiskNetworkAccessOption string + +const ( + TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks TargetDiskNetworkAccessOption = "EnablePrivateAccessForAllDisks" + TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks TargetDiskNetworkAccessOption = "EnablePublicAccessForAllDisks" + TargetDiskNetworkAccessOptionSameAsOnSourceDisks TargetDiskNetworkAccessOption = "SameAsOnSourceDisks" +) + +func PossibleValuesForTargetDiskNetworkAccessOption() []string { + return []string{ + string(TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks), + string(TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks), + string(TargetDiskNetworkAccessOptionSameAsOnSourceDisks), + } +} + +func parseTargetDiskNetworkAccessOption(input string) (*TargetDiskNetworkAccessOption, error) { + vals := map[string]TargetDiskNetworkAccessOption{ + "enableprivateaccessforalldisks": TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks, + "enablepublicaccessforalldisks": TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks, + "sameasonsourcedisks": TargetDiskNetworkAccessOptionSameAsOnSourceDisks, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TargetDiskNetworkAccessOption(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/id_recoverypoint.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/id_recoverypoint.go new file mode 100644 index 00000000000..ef68934685d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/id_recoverypoint.go @@ -0,0 +1,179 @@ +package restores + +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 + VaultName string + BackupFabricName string + ProtectionContainerName string + ProtectedItemName string + RecoveryPointId string +} + +// NewRecoveryPointID returns a new RecoveryPointId struct +func NewRecoveryPointID(subscriptionId string, resourceGroupName string, vaultName string, backupFabricName string, protectionContainerName string, protectedItemName string, recoveryPointId string) RecoveryPointId { + return RecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + BackupFabricName: backupFabricName, + ProtectionContainerName: protectionContainerName, + ProtectedItemName: protectedItemName, + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.BackupFabricName, ok = parsed.Parsed["backupFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'backupFabricName' was not found in the resource id %q", input) + } + + if id.ProtectionContainerName, ok = parsed.Parsed["protectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'protectionContainerName' was not found in the resource id %q", input) + } + + if id.ProtectedItemName, ok = parsed.Parsed["protectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'protectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointId, ok = parsed.Parsed["recoveryPointId"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointId' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/backupFabrics/%s/protectionContainers/%s/protectedItems/%s/recoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.BackupFabricName, id.ProtectionContainerName, id.ProtectedItemName, 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticBackupFabrics", "backupFabrics", "backupFabrics"), + resourceids.UserSpecifiedSegment("backupFabricName", "backupFabricValue"), + resourceids.StaticSegment("staticProtectionContainers", "protectionContainers", "protectionContainers"), + resourceids.UserSpecifiedSegment("protectionContainerName", "protectionContainerValue"), + resourceids.StaticSegment("staticProtectedItems", "protectedItems", "protectedItems"), + resourceids.UserSpecifiedSegment("protectedItemName", "protectedItemValue"), + 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Backup Fabric Name: %q", id.BackupFabricName), + fmt.Sprintf("Protection Container Name: %q", id.ProtectionContainerName), + fmt.Sprintf("Protected Item Name: %q", id.ProtectedItemName), + fmt.Sprintf("Recovery Point: %q", id.RecoveryPointId), + } + return fmt.Sprintf("Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/id_recoverypoint_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/id_recoverypoint_test.go new file mode 100644 index 00000000000..87f7f573a82 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/id_recoverypoint_test.go @@ -0,0 +1,462 @@ +package restores + +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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.BackupFabricName != "backupFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackupFabricName'", id.BackupFabricName, "backupFabricValue") + } + + if id.ProtectionContainerName != "protectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectionContainerName'", id.ProtectionContainerName, "protectionContainerValue") + } + + if id.ProtectedItemName != "protectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProtectedItemName'", id.ProtectedItemName, "protectedItemValue") + } + + 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", "vaultValue", "backupFabricValue", "protectionContainerValue", "protectedItemValue", "recoveryPointIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/recoveryPoints/recoveryPointIdValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + BackupFabricName: "backupFabricValue", + ProtectionContainerName: "protectionContainerValue", + ProtectedItemName: "protectedItemValue", + RecoveryPointId: "recoveryPointIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/backupFabrics/backupFabricValue/protectionContainers/protectionContainerValue/protectedItems/protectedItemValue/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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/rEcOvErYpOiNtS/rEcOvErYpOiNtIdVaLuE", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + BackupFabricName: "bAcKuPfAbRiCvAlUe", + ProtectionContainerName: "pRoTeCtIoNcOnTaInErVaLuE", + ProtectedItemName: "pRoTeCtEdItEmVaLuE", + 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/bAcKuPfAbRiCs/bAcKuPfAbRiCvAlUe/pRoTeCtIoNcOnTaInErS/pRoTeCtIoNcOnTaInErVaLuE/pRoTeCtEdItEmS/pRoTeCtEdItEmVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.BackupFabricName != v.Expected.BackupFabricName { + t.Fatalf("Expected %q but got %q for BackupFabricName", v.Expected.BackupFabricName, actual.BackupFabricName) + } + + if actual.ProtectionContainerName != v.Expected.ProtectionContainerName { + t.Fatalf("Expected %q but got %q for ProtectionContainerName", v.Expected.ProtectionContainerName, actual.ProtectionContainerName) + } + + if actual.ProtectedItemName != v.Expected.ProtectedItemName { + t.Fatalf("Expected %q but got %q for ProtectedItemName", v.Expected.ProtectedItemName, actual.ProtectedItemName) + } + + 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/recoveryservicesbackup/2023-02-01/restores/method_trigger_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/method_trigger_autorest.go new file mode 100644 index 00000000000..4a458fa582a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/method_trigger_autorest.go @@ -0,0 +1,79 @@ +package restores + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Trigger ... +func (c RestoresClient) Trigger(ctx context.Context, id RecoveryPointId, input RestoreRequestResource) (result TriggerOperationResponse, err error) { + req, err := c.preparerForTrigger(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "restores.RestoresClient", "Trigger", nil, "Failure preparing request") + return + } + + result, err = c.senderForTrigger(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "restores.RestoresClient", "Trigger", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TriggerThenPoll performs Trigger then polls until it's completed +func (c RestoresClient) TriggerThenPoll(ctx context.Context, id RecoveryPointId, input RestoreRequestResource) error { + result, err := c.Trigger(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Trigger: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Trigger: %+v", err) + } + + return nil +} + +// preparerForTrigger prepares the Trigger request. +func (c RestoresClient) preparerForTrigger(ctx context.Context, id RecoveryPointId, input RestoreRequestResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/restore", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTrigger sends the Trigger request. The method will close the +// http.Response Body if it receives an error. +func (c RestoresClient) senderForTrigger(ctx context.Context, req *http.Request) (future TriggerOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azurefilesharerestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azurefilesharerestorerequest.go new file mode 100644 index 00000000000..731b4adc0f3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azurefilesharerestorerequest.go @@ -0,0 +1,46 @@ +package restores + +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 _ RestoreRequest = AzureFileShareRestoreRequest{} + +type AzureFileShareRestoreRequest struct { + CopyOptions *CopyOptions `json:"copyOptions,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + RestoreFileSpecs *[]RestoreFileSpecs `json:"restoreFileSpecs,omitempty"` + RestoreRequestType *RestoreRequestType `json:"restoreRequestType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetDetails *TargetAFSRestoreInfo `json:"targetDetails,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureFileShareRestoreRequest{} + +func (s AzureFileShareRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureFileShareRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadpointintimerestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadpointintimerestorerequest.go new file mode 100644 index 00000000000..f785bb6fa71 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadpointintimerestorerequest.go @@ -0,0 +1,47 @@ +package restores + +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 _ RestoreRequest = AzureWorkloadPointInTimeRestoreRequest{} + +type AzureWorkloadPointInTimeRestoreRequest struct { + PointInTime *string `json:"pointInTime,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadPointInTimeRestoreRequest{} + +func (s AzureWorkloadPointInTimeRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadPointInTimeRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadPointInTimeRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadrestorerequest.go new file mode 100644 index 00000000000..947201a5715 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadrestorerequest.go @@ -0,0 +1,46 @@ +package restores + +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 _ RestoreRequest = AzureWorkloadRestoreRequest{} + +type AzureWorkloadRestoreRequest struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadRestoreRequest{} + +func (s AzureWorkloadRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadsaphanarestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadsaphanarestorerequest.go new file mode 100644 index 00000000000..049a667efaa --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadsaphanarestorerequest.go @@ -0,0 +1,46 @@ +package restores + +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 _ RestoreRequest = AzureWorkloadSAPHanaRestoreRequest{} + +type AzureWorkloadSAPHanaRestoreRequest struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadSAPHanaRestoreRequest{} + +func (s AzureWorkloadSAPHanaRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSAPHanaRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSAPHanaRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadsqlrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadsqlrestorerequest.go new file mode 100644 index 00000000000..19981bfa4d4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_azureworkloadsqlrestorerequest.go @@ -0,0 +1,49 @@ +package restores + +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 _ RestoreRequest = AzureWorkloadSQLRestoreRequest{} + +type AzureWorkloadSQLRestoreRequest struct { + AlternateDirectoryPaths *[]SQLDataDirectoryMapping `json:"alternateDirectoryPaths,omitempty"` + IsNonRecoverable *bool `json:"isNonRecoverable,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + ShouldUseAlternateTargetLocation *bool `json:"shouldUseAlternateTargetLocation,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadSQLRestoreRequest{} + +func (s AzureWorkloadSQLRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSQLRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSQLRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_encryptiondetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_encryptiondetails.go new file mode 100644 index 00000000000..59b1b6b4b01 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_encryptiondetails.go @@ -0,0 +1,12 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionDetails struct { + EncryptionEnabled *bool `json:"encryptionEnabled,omitempty"` + KekUrl *string `json:"kekUrl,omitempty"` + KekVaultId *string `json:"kekVaultId,omitempty"` + SecretKeyUrl *string `json:"secretKeyUrl,omitempty"` + SecretKeyVaultId *string `json:"secretKeyVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_extendedlocation.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_extendedlocation.go new file mode 100644 index 00000000000..379c8d626ce --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_extendedlocation.go @@ -0,0 +1,9 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_iaasvmrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_iaasvmrestorerequest.go new file mode 100644 index 00000000000..4480e70efa7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_iaasvmrestorerequest.go @@ -0,0 +1,65 @@ +package restores + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreRequest = IaasVMRestoreRequest{} + +type IaasVMRestoreRequest struct { + AffinityGroup *string `json:"affinityGroup,omitempty"` + CreateNewCloudService *bool `json:"createNewCloudService,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + EncryptionDetails *EncryptionDetails `json:"encryptionDetails,omitempty"` + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + IdentityBasedRestoreDetails *IdentityBasedRestoreDetails `json:"identityBasedRestoreDetails,omitempty"` + IdentityInfo *IdentityInfo `json:"identityInfo,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + Region *string `json:"region,omitempty"` + RestoreDiskLunList *[]int64 `json:"restoreDiskLunList,omitempty"` + RestoreWithManagedDisks *bool `json:"restoreWithManagedDisks,omitempty"` + SecuredVMDetails *SecuredVMDetails `json:"securedVMDetails,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TargetDiskNetworkAccessSettings *TargetDiskNetworkAccessSettings `json:"targetDiskNetworkAccessSettings,omitempty"` + TargetDomainNameId *string `json:"targetDomainNameId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + VirtualNetworkId *string `json:"virtualNetworkId,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = IaasVMRestoreRequest{} + +func (s IaasVMRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRestoreRequest: %+v", err) + } + decoded["objectType"] = "IaasVMRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_iaasvmrestorewithrehydrationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_iaasvmrestorewithrehydrationrequest.go new file mode 100644 index 00000000000..d905fc56e53 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_iaasvmrestorewithrehydrationrequest.go @@ -0,0 +1,66 @@ +package restores + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreRequest = IaasVMRestoreWithRehydrationRequest{} + +type IaasVMRestoreWithRehydrationRequest struct { + AffinityGroup *string `json:"affinityGroup,omitempty"` + CreateNewCloudService *bool `json:"createNewCloudService,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + EncryptionDetails *EncryptionDetails `json:"encryptionDetails,omitempty"` + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + IdentityBasedRestoreDetails *IdentityBasedRestoreDetails `json:"identityBasedRestoreDetails,omitempty"` + IdentityInfo *IdentityInfo `json:"identityInfo,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointRehydrationInfo *RecoveryPointRehydrationInfo `json:"recoveryPointRehydrationInfo,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + Region *string `json:"region,omitempty"` + RestoreDiskLunList *[]int64 `json:"restoreDiskLunList,omitempty"` + RestoreWithManagedDisks *bool `json:"restoreWithManagedDisks,omitempty"` + SecuredVMDetails *SecuredVMDetails `json:"securedVMDetails,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TargetDiskNetworkAccessSettings *TargetDiskNetworkAccessSettings `json:"targetDiskNetworkAccessSettings,omitempty"` + TargetDomainNameId *string `json:"targetDomainNameId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + VirtualNetworkId *string `json:"virtualNetworkId,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = IaasVMRestoreWithRehydrationRequest{} + +func (s IaasVMRestoreWithRehydrationRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRestoreWithRehydrationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + decoded["objectType"] = "IaasVMRestoreWithRehydrationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_identitybasedrestoredetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_identitybasedrestoredetails.go new file mode 100644 index 00000000000..a9c51c27edc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_identitybasedrestoredetails.go @@ -0,0 +1,9 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityBasedRestoreDetails struct { + ObjectType *string `json:"objectType,omitempty"` + TargetStorageAccountId *string `json:"targetStorageAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_identityinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_identityinfo.go new file mode 100644 index 00000000000..54e5f53f23c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_identityinfo.go @@ -0,0 +1,9 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityInfo struct { + IsSystemAssignedIdentity *bool `json:"isSystemAssignedIdentity,omitempty"` + ManagedIdentityResourceId *string `json:"managedIdentityResourceId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_recoverypointrehydrationinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_recoverypointrehydrationinfo.go new file mode 100644 index 00000000000..73a3eba8ff1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_recoverypointrehydrationinfo.go @@ -0,0 +1,9 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointRehydrationInfo struct { + RehydrationPriority *RehydrationPriority `json:"rehydrationPriority,omitempty"` + RehydrationRetentionDuration *string `json:"rehydrationRetentionDuration,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorefilespecs.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorefilespecs.go new file mode 100644 index 00000000000..717dcbaffd2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorefilespecs.go @@ -0,0 +1,10 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestoreFileSpecs struct { + FileSpecType *string `json:"fileSpecType,omitempty"` + Path *string `json:"path,omitempty"` + TargetFolderPath *string `json:"targetFolderPath,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorerequest.go new file mode 100644 index 00000000000..1885c430ae5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorerequest.go @@ -0,0 +1,96 @@ +package restores + +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 RestoreRequest interface { +} + +func unmarshalRestoreRequestImplementation(input []byte) (RestoreRequest, 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 RestoreRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareRestoreRequest") { + var out AzureFileShareRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadPointInTimeRestoreRequest") { + var out AzureWorkloadPointInTimeRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadRestoreRequest") { + var out AzureWorkloadRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSAPHanaRestoreRequest") { + var out AzureWorkloadSAPHanaRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSQLRestoreRequest") { + var out AzureWorkloadSQLRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSQLRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRestoreRequest") { + var out IaasVMRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRestoreWithRehydrationRequest") { + var out IaasVMRestoreWithRehydrationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRestoreWithRehydrationRequest: %+v", err) + } + return out, nil + } + + type RawRestoreRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRestoreRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorerequestresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorerequestresource.go new file mode 100644 index 00000000000..47ea43b2a9e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_restorerequestresource.go @@ -0,0 +1,50 @@ +package restores + +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 RestoreRequestResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties RestoreRequest `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &RestoreRequestResource{} + +func (s *RestoreRequestResource) UnmarshalJSON(bytes []byte) error { + type alias RestoreRequestResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RestoreRequestResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RestoreRequestResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'RestoreRequestResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_securedvmdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_securedvmdetails.go new file mode 100644 index 00000000000..f83115fc592 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_securedvmdetails.go @@ -0,0 +1,8 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecuredVMDetails struct { + SecuredVMOsDiskEncryptionSetId *string `json:"securedVMOsDiskEncryptionSetId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_sqldatadirectorymapping.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_sqldatadirectorymapping.go new file mode 100644 index 00000000000..6a51b7654a7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_sqldatadirectorymapping.go @@ -0,0 +1,11 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SQLDataDirectoryMapping struct { + MappingType *SQLDataDirectoryType `json:"mappingType,omitempty"` + SourceLogicalName *string `json:"sourceLogicalName,omitempty"` + SourcePath *string `json:"sourcePath,omitempty"` + TargetPath *string `json:"targetPath,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetafsrestoreinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetafsrestoreinfo.go new file mode 100644 index 00000000000..c87d917d3d7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetafsrestoreinfo.go @@ -0,0 +1,9 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetAFSRestoreInfo struct { + Name *string `json:"name,omitempty"` + TargetResourceId *string `json:"targetResourceId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetdisknetworkaccesssettings.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetdisknetworkaccesssettings.go new file mode 100644 index 00000000000..a4aef071ffb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetdisknetworkaccesssettings.go @@ -0,0 +1,9 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetDiskNetworkAccessSettings struct { + TargetDiskAccessId *string `json:"targetDiskAccessId,omitempty"` + TargetDiskNetworkAccessOption *TargetDiskNetworkAccessOption `json:"targetDiskNetworkAccessOption,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetrestoreinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetrestoreinfo.go new file mode 100644 index 00000000000..84b61c24b37 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/model_targetrestoreinfo.go @@ -0,0 +1,11 @@ +package restores + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetRestoreInfo struct { + ContainerId *string `json:"containerId,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + OverwriteOption *OverwriteOptions `json:"overwriteOption,omitempty"` + TargetDirectoryForFileRestore *string `json:"targetDirectoryForFileRestore,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/restores/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/restores/version.go new file mode 100644 index 00000000000..08f07cbaa91 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/restores/version.go @@ -0,0 +1,12 @@ +package restores + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/restores/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/README.md new file mode 100644 index 00000000000..95e28f34634 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/securitypins` Documentation + +The `securitypins` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/securitypins" +``` + + +### Client Initialization + +```go +client := securitypins.NewSecurityPINsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SecurityPINsClient.Get` + +```go +ctx := context.TODO() +id := securitypins.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := securitypins.SecurityPinBase{ + // ... +} + + +read, err := client.Get(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/recoveryservicesbackup/2023-02-01/securitypins/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/client.go new file mode 100644 index 00000000000..117208a5554 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/client.go @@ -0,0 +1,18 @@ +package securitypins + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPINsClient struct { + Client autorest.Client + baseUri string +} + +func NewSecurityPINsClientWithBaseURI(endpoint string) SecurityPINsClient { + return SecurityPINsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/id_vault.go new file mode 100644 index 00000000000..2c53dc5ee1f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/id_vault.go @@ -0,0 +1,127 @@ +package securitypins + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/id_vault_test.go new file mode 100644 index 00000000000..186dc3df8e4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/id_vault_test.go @@ -0,0 +1,282 @@ +package securitypins + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/securitypins/method_get_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/method_get_autorest.go new file mode 100644 index 00000000000..34fe1e336f4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/method_get_autorest.go @@ -0,0 +1,70 @@ +package securitypins + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *TokenInformation +} + +// Get ... +func (c SecurityPINsClient) Get(ctx context.Context, id VaultId, input SecurityPinBase) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "securitypins.SecurityPINsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "securitypins.SecurityPINsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "securitypins.SecurityPINsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c SecurityPINsClient) preparerForGet(ctx context.Context, id VaultId, input SecurityPinBase) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupSecurityPIN", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c SecurityPINsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/model_securitypinbase.go b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/model_securitypinbase.go new file mode 100644 index 00000000000..acc76db8d99 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/model_securitypinbase.go @@ -0,0 +1,8 @@ +package securitypins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPinBase struct { + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/model_tokeninformation.go b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/model_tokeninformation.go new file mode 100644 index 00000000000..cfebb48a56d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/model_tokeninformation.go @@ -0,0 +1,10 @@ +package securitypins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenInformation struct { + ExpiryTimeInUtcTicks *int64 `json:"expiryTimeInUtcTicks,omitempty"` + SecurityPIN *string `json:"securityPIN,omitempty"` + Token *string `json:"token,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/version.go new file mode 100644 index 00000000000..9394589719b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/securitypins/version.go @@ -0,0 +1,12 @@ +package securitypins + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/securitypins/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/README.md new file mode 100644 index 00000000000..1898c79b91c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers` Documentation + +The `softdeletedcontainers` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/softdeletedcontainers" +``` + + +### Client Initialization + +```go +client := softdeletedcontainers.NewSoftDeletedContainersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SoftDeletedContainersClient.DeletedProtectionContainersList` + +```go +ctx := context.TODO() +id := softdeletedcontainers.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.DeletedProtectionContainersList(ctx, id, softdeletedcontainers.DefaultDeletedProtectionContainersListOperationOptions())` can be used to do batched pagination +items, err := client.DeletedProtectionContainersListComplete(ctx, id, softdeletedcontainers.DefaultDeletedProtectionContainersListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/client.go new file mode 100644 index 00000000000..a671a0559b3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/client.go @@ -0,0 +1,18 @@ +package softdeletedcontainers + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SoftDeletedContainersClient struct { + Client autorest.Client + baseUri string +} + +func NewSoftDeletedContainersClientWithBaseURI(endpoint string) SoftDeletedContainersClient { + return SoftDeletedContainersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/constants.go new file mode 100644 index 00000000000..66a7b8fc216 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/constants.go @@ -0,0 +1,330 @@ +package softdeletedcontainers + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AcquireStorageAccountLock string + +const ( + AcquireStorageAccountLockAcquire AcquireStorageAccountLock = "Acquire" + AcquireStorageAccountLockNotAcquire AcquireStorageAccountLock = "NotAcquire" +) + +func PossibleValuesForAcquireStorageAccountLock() []string { + return []string{ + string(AcquireStorageAccountLockAcquire), + string(AcquireStorageAccountLockNotAcquire), + } +} + +func parseAcquireStorageAccountLock(input string) (*AcquireStorageAccountLock, error) { + vals := map[string]AcquireStorageAccountLock{ + "acquire": AcquireStorageAccountLockAcquire, + "notacquire": AcquireStorageAccountLockNotAcquire, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AcquireStorageAccountLock(input) + return &out, nil +} + +type BackupItemType string + +const ( + BackupItemTypeAzureFileShare BackupItemType = "AzureFileShare" + BackupItemTypeAzureSqlDb BackupItemType = "AzureSqlDb" + BackupItemTypeClient BackupItemType = "Client" + BackupItemTypeExchange BackupItemType = "Exchange" + BackupItemTypeFileFolder BackupItemType = "FileFolder" + BackupItemTypeGenericDataSource BackupItemType = "GenericDataSource" + BackupItemTypeInvalid BackupItemType = "Invalid" + BackupItemTypeSAPAseDatabase BackupItemType = "SAPAseDatabase" + BackupItemTypeSAPHanaDBInstance BackupItemType = "SAPHanaDBInstance" + BackupItemTypeSAPHanaDatabase BackupItemType = "SAPHanaDatabase" + BackupItemTypeSQLDB BackupItemType = "SQLDB" + BackupItemTypeSQLDataBase BackupItemType = "SQLDataBase" + BackupItemTypeSharepoint BackupItemType = "Sharepoint" + BackupItemTypeSystemState BackupItemType = "SystemState" + BackupItemTypeVM BackupItemType = "VM" + BackupItemTypeVMwareVM BackupItemType = "VMwareVM" +) + +func PossibleValuesForBackupItemType() []string { + return []string{ + string(BackupItemTypeAzureFileShare), + string(BackupItemTypeAzureSqlDb), + string(BackupItemTypeClient), + string(BackupItemTypeExchange), + string(BackupItemTypeFileFolder), + string(BackupItemTypeGenericDataSource), + string(BackupItemTypeInvalid), + string(BackupItemTypeSAPAseDatabase), + string(BackupItemTypeSAPHanaDBInstance), + string(BackupItemTypeSAPHanaDatabase), + string(BackupItemTypeSQLDB), + string(BackupItemTypeSQLDataBase), + string(BackupItemTypeSharepoint), + string(BackupItemTypeSystemState), + string(BackupItemTypeVM), + string(BackupItemTypeVMwareVM), + } +} + +func parseBackupItemType(input string) (*BackupItemType, error) { + vals := map[string]BackupItemType{ + "azurefileshare": BackupItemTypeAzureFileShare, + "azuresqldb": BackupItemTypeAzureSqlDb, + "client": BackupItemTypeClient, + "exchange": BackupItemTypeExchange, + "filefolder": BackupItemTypeFileFolder, + "genericdatasource": BackupItemTypeGenericDataSource, + "invalid": BackupItemTypeInvalid, + "sapasedatabase": BackupItemTypeSAPAseDatabase, + "saphanadbinstance": BackupItemTypeSAPHanaDBInstance, + "saphanadatabase": BackupItemTypeSAPHanaDatabase, + "sqldb": BackupItemTypeSQLDB, + "sqldatabase": BackupItemTypeSQLDataBase, + "sharepoint": BackupItemTypeSharepoint, + "systemstate": BackupItemTypeSystemState, + "vm": BackupItemTypeVM, + "vmwarevm": BackupItemTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupItemType(input) + return &out, nil +} + +type BackupManagementType string + +const ( + BackupManagementTypeAzureBackupServer BackupManagementType = "AzureBackupServer" + BackupManagementTypeAzureIaasVM BackupManagementType = "AzureIaasVM" + BackupManagementTypeAzureSql BackupManagementType = "AzureSql" + BackupManagementTypeAzureStorage BackupManagementType = "AzureStorage" + BackupManagementTypeAzureWorkload BackupManagementType = "AzureWorkload" + BackupManagementTypeDPM BackupManagementType = "DPM" + BackupManagementTypeDefaultBackup BackupManagementType = "DefaultBackup" + BackupManagementTypeInvalid BackupManagementType = "Invalid" + BackupManagementTypeMAB BackupManagementType = "MAB" +) + +func PossibleValuesForBackupManagementType() []string { + return []string{ + string(BackupManagementTypeAzureBackupServer), + string(BackupManagementTypeAzureIaasVM), + string(BackupManagementTypeAzureSql), + string(BackupManagementTypeAzureStorage), + string(BackupManagementTypeAzureWorkload), + string(BackupManagementTypeDPM), + string(BackupManagementTypeDefaultBackup), + string(BackupManagementTypeInvalid), + string(BackupManagementTypeMAB), + } +} + +func parseBackupManagementType(input string) (*BackupManagementType, error) { + vals := map[string]BackupManagementType{ + "azurebackupserver": BackupManagementTypeAzureBackupServer, + "azureiaasvm": BackupManagementTypeAzureIaasVM, + "azuresql": BackupManagementTypeAzureSql, + "azurestorage": BackupManagementTypeAzureStorage, + "azureworkload": BackupManagementTypeAzureWorkload, + "dpm": BackupManagementTypeDPM, + "defaultbackup": BackupManagementTypeDefaultBackup, + "invalid": BackupManagementTypeInvalid, + "mab": BackupManagementTypeMAB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupManagementType(input) + return &out, nil +} + +type OperationType string + +const ( + OperationTypeInvalid OperationType = "Invalid" + OperationTypeRegister OperationType = "Register" + OperationTypeReregister OperationType = "Reregister" +) + +func PossibleValuesForOperationType() []string { + return []string{ + string(OperationTypeInvalid), + string(OperationTypeRegister), + string(OperationTypeReregister), + } +} + +func parseOperationType(input string) (*OperationType, error) { + vals := map[string]OperationType{ + "invalid": OperationTypeInvalid, + "register": OperationTypeRegister, + "reregister": OperationTypeReregister, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationType(input) + return &out, nil +} + +type ProtectableContainerType string + +const ( + ProtectableContainerTypeAzureBackupServerContainer ProtectableContainerType = "AzureBackupServerContainer" + ProtectableContainerTypeAzureSqlContainer ProtectableContainerType = "AzureSqlContainer" + ProtectableContainerTypeAzureWorkloadContainer ProtectableContainerType = "AzureWorkloadContainer" + ProtectableContainerTypeCluster ProtectableContainerType = "Cluster" + ProtectableContainerTypeDPMContainer ProtectableContainerType = "DPMContainer" + ProtectableContainerTypeGenericContainer ProtectableContainerType = "GenericContainer" + ProtectableContainerTypeIaasVMContainer ProtectableContainerType = "IaasVMContainer" + ProtectableContainerTypeIaasVMServiceContainer ProtectableContainerType = "IaasVMServiceContainer" + ProtectableContainerTypeInvalid ProtectableContainerType = "Invalid" + ProtectableContainerTypeMABContainer ProtectableContainerType = "MABContainer" + ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines ProtectableContainerType = "Microsoft.ClassicCompute/virtualMachines" + ProtectableContainerTypeMicrosoftPointComputeVirtualMachines ProtectableContainerType = "Microsoft.Compute/virtualMachines" + ProtectableContainerTypeSQLAGWorkLoadContainer ProtectableContainerType = "SQLAGWorkLoadContainer" + ProtectableContainerTypeStorageContainer ProtectableContainerType = "StorageContainer" + ProtectableContainerTypeUnknown ProtectableContainerType = "Unknown" + ProtectableContainerTypeVCenter ProtectableContainerType = "VCenter" + ProtectableContainerTypeVMAppContainer ProtectableContainerType = "VMAppContainer" + ProtectableContainerTypeWindows ProtectableContainerType = "Windows" +) + +func PossibleValuesForProtectableContainerType() []string { + return []string{ + string(ProtectableContainerTypeAzureBackupServerContainer), + string(ProtectableContainerTypeAzureSqlContainer), + string(ProtectableContainerTypeAzureWorkloadContainer), + string(ProtectableContainerTypeCluster), + string(ProtectableContainerTypeDPMContainer), + string(ProtectableContainerTypeGenericContainer), + string(ProtectableContainerTypeIaasVMContainer), + string(ProtectableContainerTypeIaasVMServiceContainer), + string(ProtectableContainerTypeInvalid), + string(ProtectableContainerTypeMABContainer), + string(ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines), + string(ProtectableContainerTypeMicrosoftPointComputeVirtualMachines), + string(ProtectableContainerTypeSQLAGWorkLoadContainer), + string(ProtectableContainerTypeStorageContainer), + string(ProtectableContainerTypeUnknown), + string(ProtectableContainerTypeVCenter), + string(ProtectableContainerTypeVMAppContainer), + string(ProtectableContainerTypeWindows), + } +} + +func parseProtectableContainerType(input string) (*ProtectableContainerType, error) { + vals := map[string]ProtectableContainerType{ + "azurebackupservercontainer": ProtectableContainerTypeAzureBackupServerContainer, + "azuresqlcontainer": ProtectableContainerTypeAzureSqlContainer, + "azureworkloadcontainer": ProtectableContainerTypeAzureWorkloadContainer, + "cluster": ProtectableContainerTypeCluster, + "dpmcontainer": ProtectableContainerTypeDPMContainer, + "genericcontainer": ProtectableContainerTypeGenericContainer, + "iaasvmcontainer": ProtectableContainerTypeIaasVMContainer, + "iaasvmservicecontainer": ProtectableContainerTypeIaasVMServiceContainer, + "invalid": ProtectableContainerTypeInvalid, + "mabcontainer": ProtectableContainerTypeMABContainer, + "microsoft.classiccompute/virtualmachines": ProtectableContainerTypeMicrosoftPointClassicComputeVirtualMachines, + "microsoft.compute/virtualmachines": ProtectableContainerTypeMicrosoftPointComputeVirtualMachines, + "sqlagworkloadcontainer": ProtectableContainerTypeSQLAGWorkLoadContainer, + "storagecontainer": ProtectableContainerTypeStorageContainer, + "unknown": ProtectableContainerTypeUnknown, + "vcenter": ProtectableContainerTypeVCenter, + "vmappcontainer": ProtectableContainerTypeVMAppContainer, + "windows": ProtectableContainerTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectableContainerType(input) + return &out, nil +} + +type WorkloadType string + +const ( + WorkloadTypeAzureFileShare WorkloadType = "AzureFileShare" + WorkloadTypeAzureSqlDb WorkloadType = "AzureSqlDb" + WorkloadTypeClient WorkloadType = "Client" + WorkloadTypeExchange WorkloadType = "Exchange" + WorkloadTypeFileFolder WorkloadType = "FileFolder" + WorkloadTypeGenericDataSource WorkloadType = "GenericDataSource" + WorkloadTypeInvalid WorkloadType = "Invalid" + WorkloadTypeSAPAseDatabase WorkloadType = "SAPAseDatabase" + WorkloadTypeSAPHanaDBInstance WorkloadType = "SAPHanaDBInstance" + WorkloadTypeSAPHanaDatabase WorkloadType = "SAPHanaDatabase" + WorkloadTypeSQLDB WorkloadType = "SQLDB" + WorkloadTypeSQLDataBase WorkloadType = "SQLDataBase" + WorkloadTypeSharepoint WorkloadType = "Sharepoint" + WorkloadTypeSystemState WorkloadType = "SystemState" + WorkloadTypeVM WorkloadType = "VM" + WorkloadTypeVMwareVM WorkloadType = "VMwareVM" +) + +func PossibleValuesForWorkloadType() []string { + return []string{ + string(WorkloadTypeAzureFileShare), + string(WorkloadTypeAzureSqlDb), + string(WorkloadTypeClient), + string(WorkloadTypeExchange), + string(WorkloadTypeFileFolder), + string(WorkloadTypeGenericDataSource), + string(WorkloadTypeInvalid), + string(WorkloadTypeSAPAseDatabase), + string(WorkloadTypeSAPHanaDBInstance), + string(WorkloadTypeSAPHanaDatabase), + string(WorkloadTypeSQLDB), + string(WorkloadTypeSQLDataBase), + string(WorkloadTypeSharepoint), + string(WorkloadTypeSystemState), + string(WorkloadTypeVM), + string(WorkloadTypeVMwareVM), + } +} + +func parseWorkloadType(input string) (*WorkloadType, error) { + vals := map[string]WorkloadType{ + "azurefileshare": WorkloadTypeAzureFileShare, + "azuresqldb": WorkloadTypeAzureSqlDb, + "client": WorkloadTypeClient, + "exchange": WorkloadTypeExchange, + "filefolder": WorkloadTypeFileFolder, + "genericdatasource": WorkloadTypeGenericDataSource, + "invalid": WorkloadTypeInvalid, + "sapasedatabase": WorkloadTypeSAPAseDatabase, + "saphanadbinstance": WorkloadTypeSAPHanaDBInstance, + "saphanadatabase": WorkloadTypeSAPHanaDatabase, + "sqldb": WorkloadTypeSQLDB, + "sqldatabase": WorkloadTypeSQLDataBase, + "sharepoint": WorkloadTypeSharepoint, + "systemstate": WorkloadTypeSystemState, + "vm": WorkloadTypeVM, + "vmwarevm": WorkloadTypeVMwareVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkloadType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/id_vault.go new file mode 100644 index 00000000000..5a614988774 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/id_vault.go @@ -0,0 +1,127 @@ +package softdeletedcontainers + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/id_vault_test.go new file mode 100644 index 00000000000..8c0f402bd11 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/id_vault_test.go @@ -0,0 +1,282 @@ +package softdeletedcontainers + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/softdeletedcontainers/method_deletedprotectioncontainerslist_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/method_deletedprotectioncontainerslist_autorest.go new file mode 100644 index 00000000000..412ffcc44a7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/method_deletedprotectioncontainerslist_autorest.go @@ -0,0 +1,215 @@ +package softdeletedcontainers + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedProtectionContainersListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionContainerResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (DeletedProtectionContainersListOperationResponse, error) +} + +type DeletedProtectionContainersListCompleteResult struct { + Items []ProtectionContainerResource +} + +func (r DeletedProtectionContainersListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r DeletedProtectionContainersListOperationResponse) LoadMore(ctx context.Context) (resp DeletedProtectionContainersListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type DeletedProtectionContainersListOperationOptions struct { + Filter *string +} + +func DefaultDeletedProtectionContainersListOperationOptions() DeletedProtectionContainersListOperationOptions { + return DeletedProtectionContainersListOperationOptions{} +} + +func (o DeletedProtectionContainersListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeletedProtectionContainersListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// DeletedProtectionContainersList ... +func (c SoftDeletedContainersClient) DeletedProtectionContainersList(ctx context.Context, id VaultId, options DeletedProtectionContainersListOperationOptions) (resp DeletedProtectionContainersListOperationResponse, err error) { + req, err := c.preparerForDeletedProtectionContainersList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "softdeletedcontainers.SoftDeletedContainersClient", "DeletedProtectionContainersList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "softdeletedcontainers.SoftDeletedContainersClient", "DeletedProtectionContainersList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForDeletedProtectionContainersList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "softdeletedcontainers.SoftDeletedContainersClient", "DeletedProtectionContainersList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForDeletedProtectionContainersList prepares the DeletedProtectionContainersList request. +func (c SoftDeletedContainersClient) preparerForDeletedProtectionContainersList(ctx context.Context, id VaultId, options DeletedProtectionContainersListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/backupDeletedProtectionContainers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForDeletedProtectionContainersListWithNextLink prepares the DeletedProtectionContainersList request with the given nextLink token. +func (c SoftDeletedContainersClient) preparerForDeletedProtectionContainersListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDeletedProtectionContainersList handles the response to the DeletedProtectionContainersList request. The method always +// closes the http.Response Body. +func (c SoftDeletedContainersClient) responderForDeletedProtectionContainersList(resp *http.Response) (result DeletedProtectionContainersListOperationResponse, err error) { + type page struct { + Values []ProtectionContainerResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result DeletedProtectionContainersListOperationResponse, err error) { + req, err := c.preparerForDeletedProtectionContainersListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "softdeletedcontainers.SoftDeletedContainersClient", "DeletedProtectionContainersList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "softdeletedcontainers.SoftDeletedContainersClient", "DeletedProtectionContainersList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDeletedProtectionContainersList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "softdeletedcontainers.SoftDeletedContainersClient", "DeletedProtectionContainersList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// DeletedProtectionContainersListComplete retrieves all of the results into a single object +func (c SoftDeletedContainersClient) DeletedProtectionContainersListComplete(ctx context.Context, id VaultId, options DeletedProtectionContainersListOperationOptions) (DeletedProtectionContainersListCompleteResult, error) { + return c.DeletedProtectionContainersListCompleteMatchingPredicate(ctx, id, options, ProtectionContainerResourceOperationPredicate{}) +} + +// DeletedProtectionContainersListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SoftDeletedContainersClient) DeletedProtectionContainersListCompleteMatchingPredicate(ctx context.Context, id VaultId, options DeletedProtectionContainersListOperationOptions, predicate ProtectionContainerResourceOperationPredicate) (resp DeletedProtectionContainersListCompleteResult, err error) { + items := make([]ProtectionContainerResource, 0) + + page, err := c.DeletedProtectionContainersList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := DeletedProtectionContainersListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurebackupservercontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurebackupservercontainer.go new file mode 100644 index 00000000000..573efc50aa1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurebackupservercontainer.go @@ -0,0 +1,53 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureBackupServerContainer{} + +type AzureBackupServerContainer struct { + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + DpmAgentVersion *string `json:"dpmAgentVersion,omitempty"` + DpmServers *[]string `json:"dpmServers,omitempty"` + ExtendedInfo *DPMContainerExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + UpgradeAvailable *bool `json:"upgradeAvailable,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureBackupServerContainer{} + +func (s AzureBackupServerContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupServerContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupServerContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupServerContainer: %+v", err) + } + decoded["containerType"] = "AzureBackupServerContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupServerContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureiaasclassiccomputevmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureiaasclassiccomputevmcontainer.go new file mode 100644 index 00000000000..1ffb8ed0e0d --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureiaasclassiccomputevmcontainer.go @@ -0,0 +1,48 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureIaaSClassicComputeVMContainer{} + +type AzureIaaSClassicComputeVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureIaaSClassicComputeVMContainer{} + +func (s AzureIaaSClassicComputeVMContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSClassicComputeVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + decoded["containerType"] = "Microsoft.ClassicCompute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSClassicComputeVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureiaascomputevmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureiaascomputevmcontainer.go new file mode 100644 index 00000000000..24481ef7aeb --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureiaascomputevmcontainer.go @@ -0,0 +1,48 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureIaaSComputeVMContainer{} + +type AzureIaaSComputeVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureIaaSComputeVMContainer{} + +func (s AzureIaaSComputeVMContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureIaaSComputeVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureIaaSComputeVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureIaaSComputeVMContainer: %+v", err) + } + decoded["containerType"] = "Microsoft.Compute/virtualMachines" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureIaaSComputeVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go new file mode 100644 index 00000000000..e359f39f411 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azuresqlagworkloadcontainerprotectioncontainer.go @@ -0,0 +1,50 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureSQLAGWorkloadContainerProtectionContainer{} + +type AzureSQLAGWorkloadContainerProtectionContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureSQLAGWorkloadContainerProtectionContainer{} + +func (s AzureSQLAGWorkloadContainerProtectionContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureSQLAGWorkloadContainerProtectionContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + decoded["containerType"] = "SQLAGWorkLoadContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azuresqlcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azuresqlcontainer.go new file mode 100644 index 00000000000..e45c918f9ff --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azuresqlcontainer.go @@ -0,0 +1,45 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureSqlContainer{} + +type AzureSqlContainer struct { + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureSqlContainer{} + +func (s AzureSqlContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureSqlContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureSqlContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureSqlContainer: %+v", err) + } + decoded["containerType"] = "AzureSqlContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureSqlContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurestoragecontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurestoragecontainer.go new file mode 100644 index 00000000000..f0c84f07fa1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurestoragecontainer.go @@ -0,0 +1,50 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureStorageContainer{} + +type AzureStorageContainer struct { + AcquireStorageAccountLock *AcquireStorageAccountLock `json:"acquireStorageAccountLock,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ResourceGroup *string `json:"resourceGroup,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountVersion *string `json:"storageAccountVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureStorageContainer{} + +func (s AzureStorageContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureStorageContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureStorageContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureStorageContainer: %+v", err) + } + decoded["containerType"] = "StorageContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureStorageContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurevmappcontainerprotectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurevmappcontainerprotectioncontainer.go new file mode 100644 index 00000000000..19bc1ebe0f0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azurevmappcontainerprotectioncontainer.go @@ -0,0 +1,50 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureVMAppContainerProtectionContainer{} + +type AzureVMAppContainerProtectionContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureVMAppContainerProtectionContainer{} + +func (s AzureVMAppContainerProtectionContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureVMAppContainerProtectionContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + decoded["containerType"] = "VMAppContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureVMAppContainerProtectionContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureworkloadcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureworkloadcontainer.go new file mode 100644 index 00000000000..e89bdafedc4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureworkloadcontainer.go @@ -0,0 +1,50 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = AzureWorkloadContainer{} + +type AzureWorkloadContainer struct { + ExtendedInfo *AzureWorkloadContainerExtendedInfo `json:"extendedInfo,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + OperationType *OperationType `json:"operationType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + WorkloadType *WorkloadType `json:"workloadType,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = AzureWorkloadContainer{} + +func (s AzureWorkloadContainer) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadContainer: %+v", err) + } + decoded["containerType"] = "AzureWorkloadContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureworkloadcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureworkloadcontainerextendedinfo.go new file mode 100644 index 00000000000..141007ebdda --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_azureworkloadcontainerextendedinfo.go @@ -0,0 +1,10 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureWorkloadContainerExtendedInfo struct { + HostServerName *string `json:"hostServerName,omitempty"` + InquiryInfo *InquiryInfo `json:"inquiryInfo,omitempty"` + NodesList *[]DistributedNodesInfo `json:"nodesList,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_containeridentityinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_containeridentityinfo.go new file mode 100644 index 00000000000..367cba6804a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_containeridentityinfo.go @@ -0,0 +1,11 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerIdentityInfo struct { + AadTenantId *string `json:"aadTenantId,omitempty"` + Audience *string `json:"audience,omitempty"` + ServicePrincipalClientId *string `json:"servicePrincipalClientId,omitempty"` + UniqueName *string `json:"uniqueName,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_distributednodesinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_distributednodesinfo.go new file mode 100644 index 00000000000..52eede1eb89 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_distributednodesinfo.go @@ -0,0 +1,10 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedNodesInfo struct { + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + NodeName *string `json:"nodeName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_dpmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_dpmcontainer.go new file mode 100644 index 00000000000..349969c7db5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_dpmcontainer.go @@ -0,0 +1,53 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = DpmContainer{} + +type DpmContainer struct { + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerId *string `json:"containerId,omitempty"` + DpmAgentVersion *string `json:"dpmAgentVersion,omitempty"` + DpmServers *[]string `json:"dpmServers,omitempty"` + ExtendedInfo *DPMContainerExtendedInfo `json:"extendedInfo,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + UpgradeAvailable *bool `json:"upgradeAvailable,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = DpmContainer{} + +func (s DpmContainer) MarshalJSON() ([]byte, error) { + type wrapper DpmContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DpmContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DpmContainer: %+v", err) + } + decoded["containerType"] = "DPMContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DpmContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_dpmcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_dpmcontainerextendedinfo.go new file mode 100644 index 00000000000..c0f911a34b6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_dpmcontainerextendedinfo.go @@ -0,0 +1,26 @@ +package softdeletedcontainers + +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 DPMContainerExtendedInfo struct { + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` +} + +func (o *DPMContainerExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *DPMContainerExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_errordetail.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_errordetail.go new file mode 100644 index 00000000000..b76617c0e57 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_errordetail.go @@ -0,0 +1,10 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_genericcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_genericcontainer.go new file mode 100644 index 00000000000..c5e6d8bd349 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_genericcontainer.go @@ -0,0 +1,47 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = GenericContainer{} + +type GenericContainer struct { + ExtendedInformation *GenericContainerExtendedInfo `json:"extendedInformation,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = GenericContainer{} + +func (s GenericContainer) MarshalJSON() ([]byte, error) { + type wrapper GenericContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GenericContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GenericContainer: %+v", err) + } + decoded["containerType"] = "GenericContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GenericContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_genericcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_genericcontainerextendedinfo.go new file mode 100644 index 00000000000..79e66b1ffda --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_genericcontainerextendedinfo.go @@ -0,0 +1,10 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericContainerExtendedInfo struct { + ContainerIdentityInfo *ContainerIdentityInfo `json:"containerIdentityInfo,omitempty"` + RawCertData *string `json:"rawCertData,omitempty"` + ServiceEndpoints *map[string]string `json:"serviceEndpoints,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_iaasvmcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_iaasvmcontainer.go new file mode 100644 index 00000000000..b8f3da1ebe1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_iaasvmcontainer.go @@ -0,0 +1,48 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = IaaSVMContainer{} + +type IaaSVMContainer struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` + VirtualMachineVersion *string `json:"virtualMachineVersion,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = IaaSVMContainer{} + +func (s IaaSVMContainer) MarshalJSON() ([]byte, error) { + type wrapper IaaSVMContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaaSVMContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaaSVMContainer: %+v", err) + } + decoded["containerType"] = "IaasVMContainer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaaSVMContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_inquiryinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_inquiryinfo.go new file mode 100644 index 00000000000..c4d9f8360b5 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_inquiryinfo.go @@ -0,0 +1,10 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InquiryInfo struct { + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + InquiryDetails *[]WorkloadInquiryDetails `json:"inquiryDetails,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_inquiryvalidation.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_inquiryvalidation.go new file mode 100644 index 00000000000..edd8a28b18e --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_inquiryvalidation.go @@ -0,0 +1,10 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InquiryValidation struct { + AdditionalDetail *string `json:"additionalDetail,omitempty"` + ErrorDetail *ErrorDetail `json:"errorDetail,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainer.go new file mode 100644 index 00000000000..6a7fcdfdffa --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainer.go @@ -0,0 +1,52 @@ +package softdeletedcontainers + +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 _ ProtectionContainer = MabContainer{} + +type MabContainer struct { + AgentVersion *string `json:"agentVersion,omitempty"` + CanReRegister *bool `json:"canReRegister,omitempty"` + ContainerHealthState *string `json:"containerHealthState,omitempty"` + ContainerId *int64 `json:"containerId,omitempty"` + ExtendedInfo *MabContainerExtendedInfo `json:"extendedInfo,omitempty"` + MabContainerHealthDetails *[]MABContainerHealthDetails `json:"mabContainerHealthDetails,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + + // Fields inherited from ProtectionContainer + BackupManagementType *BackupManagementType `json:"backupManagementType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthStatus *string `json:"healthStatus,omitempty"` + ProtectableObjectType *string `json:"protectableObjectType,omitempty"` + RegistrationStatus *string `json:"registrationStatus,omitempty"` +} + +var _ json.Marshaler = MabContainer{} + +func (s MabContainer) MarshalJSON() ([]byte, error) { + type wrapper MabContainer + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MabContainer: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MabContainer: %+v", err) + } + decoded["containerType"] = "Windows" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MabContainer: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainerextendedinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainerextendedinfo.go new file mode 100644 index 00000000000..a5bc672fcf2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainerextendedinfo.go @@ -0,0 +1,30 @@ +package softdeletedcontainers + +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 MabContainerExtendedInfo struct { + BackupItemType *BackupItemType `json:"backupItemType,omitempty"` + BackupItems *[]string `json:"backupItems,omitempty"` + LastBackupStatus *string `json:"lastBackupStatus,omitempty"` + LastRefreshedAt *string `json:"lastRefreshedAt,omitempty"` + PolicyName *string `json:"policyName,omitempty"` +} + +func (o *MabContainerExtendedInfo) GetLastRefreshedAtAsTime() (*time.Time, error) { + if o.LastRefreshedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefreshedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *MabContainerExtendedInfo) SetLastRefreshedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefreshedAt = &formatted +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainerhealthdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainerhealthdetails.go new file mode 100644 index 00000000000..8e91b126cc6 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_mabcontainerhealthdetails.go @@ -0,0 +1,11 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MABContainerHealthDetails struct { + Code *int64 `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Recommendations *[]string `json:"recommendations,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_protectioncontainer.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_protectioncontainer.go new file mode 100644 index 00000000000..5628330f5e7 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_protectioncontainer.go @@ -0,0 +1,136 @@ +package softdeletedcontainers + +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 ProtectionContainer interface { +} + +func unmarshalProtectionContainerImplementation(input []byte) (ProtectionContainer, 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 ProtectionContainer into map[string]interface: %+v", err) + } + + value, ok := temp["containerType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureBackupServerContainer") { + var out AzureBackupServerContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupServerContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.ClassicCompute/virtualMachines") { + var out AzureIaaSClassicComputeVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSClassicComputeVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Microsoft.Compute/virtualMachines") { + var out AzureIaaSComputeVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureIaaSComputeVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SQLAGWorkLoadContainer") { + var out AzureSQLAGWorkloadContainerProtectionContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSQLAGWorkloadContainerProtectionContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureSqlContainer") { + var out AzureSqlContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureSqlContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StorageContainer") { + var out AzureStorageContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureStorageContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMAppContainer") { + var out AzureVMAppContainerProtectionContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureVMAppContainerProtectionContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadContainer") { + var out AzureWorkloadContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DPMContainer") { + var out DpmContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DpmContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GenericContainer") { + var out GenericContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GenericContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMContainer") { + var out IaaSVMContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaaSVMContainer: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Windows") { + var out MabContainer + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MabContainer: %+v", err) + } + return out, nil + } + + type RawProtectionContainerImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionContainerImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_protectioncontainerresource.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_protectioncontainerresource.go new file mode 100644 index 00000000000..2d5ed02148a --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_protectioncontainerresource.go @@ -0,0 +1,50 @@ +package softdeletedcontainers + +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 ProtectionContainerResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ProtectionContainer `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionContainerResource{} + +func (s *ProtectionContainerResource) UnmarshalJSON(bytes []byte) error { + type alias ProtectionContainerResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionContainerResource: %+v", err) + } + + s.ETag = decoded.ETag + s.Id = decoded.Id + s.Location = decoded.Location + s.Name = decoded.Name + s.Tags = decoded.Tags + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionContainerResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalProtectionContainerImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'ProtectionContainerResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_workloadinquirydetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_workloadinquirydetails.go new file mode 100644 index 00000000000..ca519886a94 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/model_workloadinquirydetails.go @@ -0,0 +1,10 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadInquiryDetails struct { + InquiryValidation *InquiryValidation `json:"inquiryValidation,omitempty"` + ItemCount *int64 `json:"itemCount,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/predicates.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/predicates.go new file mode 100644 index 00000000000..259e53120a0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/predicates.go @@ -0,0 +1,37 @@ +package softdeletedcontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainerResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectionContainerResourceOperationPredicate) Matches(input ProtectionContainerResource) 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/recoveryservicesbackup/2023-02-01/softdeletedcontainers/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/version.go new file mode 100644 index 00000000000..9603cde79b2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/softdeletedcontainers/version.go @@ -0,0 +1,12 @@ +package softdeletedcontainers + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/softdeletedcontainers/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/README.md b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/README.md new file mode 100644 index 00000000000..72f395726d0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation` Documentation + +The `validateoperation` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicesbackup` (API Version `2023-02-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/recoveryservicesbackup/2023-02-01/validateoperation" +``` + + +### Client Initialization + +```go +client := validateoperation.NewValidateOperationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ValidateOperationClient.Trigger` + +```go +ctx := context.TODO() +id := validateoperation.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := validateoperation.ValidateOperationRequest{ + // ... +} + + +if err := client.TriggerThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/client.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/client.go new file mode 100644 index 00000000000..e729f452d88 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/client.go @@ -0,0 +1,18 @@ +package validateoperation + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateOperationClient struct { + Client autorest.Client + baseUri string +} + +func NewValidateOperationClientWithBaseURI(endpoint string) ValidateOperationClient { + return ValidateOperationClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/constants.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/constants.go new file mode 100644 index 00000000000..7585807f251 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/constants.go @@ -0,0 +1,263 @@ +package validateoperation + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CopyOptions string + +const ( + CopyOptionsCreateCopy CopyOptions = "CreateCopy" + CopyOptionsFailOnConflict CopyOptions = "FailOnConflict" + CopyOptionsInvalid CopyOptions = "Invalid" + CopyOptionsOverwrite CopyOptions = "Overwrite" + CopyOptionsSkip CopyOptions = "Skip" +) + +func PossibleValuesForCopyOptions() []string { + return []string{ + string(CopyOptionsCreateCopy), + string(CopyOptionsFailOnConflict), + string(CopyOptionsInvalid), + string(CopyOptionsOverwrite), + string(CopyOptionsSkip), + } +} + +func parseCopyOptions(input string) (*CopyOptions, error) { + vals := map[string]CopyOptions{ + "createcopy": CopyOptionsCreateCopy, + "failonconflict": CopyOptionsFailOnConflict, + "invalid": CopyOptionsInvalid, + "overwrite": CopyOptionsOverwrite, + "skip": CopyOptionsSkip, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CopyOptions(input) + return &out, nil +} + +type OverwriteOptions string + +const ( + OverwriteOptionsFailOnConflict OverwriteOptions = "FailOnConflict" + OverwriteOptionsInvalid OverwriteOptions = "Invalid" + OverwriteOptionsOverwrite OverwriteOptions = "Overwrite" +) + +func PossibleValuesForOverwriteOptions() []string { + return []string{ + string(OverwriteOptionsFailOnConflict), + string(OverwriteOptionsInvalid), + string(OverwriteOptionsOverwrite), + } +} + +func parseOverwriteOptions(input string) (*OverwriteOptions, error) { + vals := map[string]OverwriteOptions{ + "failonconflict": OverwriteOptionsFailOnConflict, + "invalid": OverwriteOptionsInvalid, + "overwrite": OverwriteOptionsOverwrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OverwriteOptions(input) + return &out, nil +} + +type RecoveryMode string + +const ( + RecoveryModeFileRecovery RecoveryMode = "FileRecovery" + RecoveryModeInvalid RecoveryMode = "Invalid" + RecoveryModeWorkloadRecovery RecoveryMode = "WorkloadRecovery" +) + +func PossibleValuesForRecoveryMode() []string { + return []string{ + string(RecoveryModeFileRecovery), + string(RecoveryModeInvalid), + string(RecoveryModeWorkloadRecovery), + } +} + +func parseRecoveryMode(input string) (*RecoveryMode, error) { + vals := map[string]RecoveryMode{ + "filerecovery": RecoveryModeFileRecovery, + "invalid": RecoveryModeInvalid, + "workloadrecovery": RecoveryModeWorkloadRecovery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryMode(input) + return &out, nil +} + +type RecoveryType string + +const ( + RecoveryTypeAlternateLocation RecoveryType = "AlternateLocation" + RecoveryTypeInvalid RecoveryType = "Invalid" + RecoveryTypeOffline RecoveryType = "Offline" + RecoveryTypeOriginalLocation RecoveryType = "OriginalLocation" + RecoveryTypeRestoreDisks RecoveryType = "RestoreDisks" +) + +func PossibleValuesForRecoveryType() []string { + return []string{ + string(RecoveryTypeAlternateLocation), + string(RecoveryTypeInvalid), + string(RecoveryTypeOffline), + string(RecoveryTypeOriginalLocation), + string(RecoveryTypeRestoreDisks), + } +} + +func parseRecoveryType(input string) (*RecoveryType, error) { + vals := map[string]RecoveryType{ + "alternatelocation": RecoveryTypeAlternateLocation, + "invalid": RecoveryTypeInvalid, + "offline": RecoveryTypeOffline, + "originallocation": RecoveryTypeOriginalLocation, + "restoredisks": RecoveryTypeRestoreDisks, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryType(input) + return &out, nil +} + +type RehydrationPriority string + +const ( + RehydrationPriorityHigh RehydrationPriority = "High" + RehydrationPriorityStandard RehydrationPriority = "Standard" +) + +func PossibleValuesForRehydrationPriority() []string { + return []string{ + string(RehydrationPriorityHigh), + string(RehydrationPriorityStandard), + } +} + +func parseRehydrationPriority(input string) (*RehydrationPriority, error) { + vals := map[string]RehydrationPriority{ + "high": RehydrationPriorityHigh, + "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 RestoreRequestType string + +const ( + RestoreRequestTypeFullShareRestore RestoreRequestType = "FullShareRestore" + RestoreRequestTypeInvalid RestoreRequestType = "Invalid" + RestoreRequestTypeItemLevelRestore RestoreRequestType = "ItemLevelRestore" +) + +func PossibleValuesForRestoreRequestType() []string { + return []string{ + string(RestoreRequestTypeFullShareRestore), + string(RestoreRequestTypeInvalid), + string(RestoreRequestTypeItemLevelRestore), + } +} + +func parseRestoreRequestType(input string) (*RestoreRequestType, error) { + vals := map[string]RestoreRequestType{ + "fullsharerestore": RestoreRequestTypeFullShareRestore, + "invalid": RestoreRequestTypeInvalid, + "itemlevelrestore": RestoreRequestTypeItemLevelRestore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestoreRequestType(input) + return &out, nil +} + +type SQLDataDirectoryType string + +const ( + SQLDataDirectoryTypeData SQLDataDirectoryType = "Data" + SQLDataDirectoryTypeInvalid SQLDataDirectoryType = "Invalid" + SQLDataDirectoryTypeLog SQLDataDirectoryType = "Log" +) + +func PossibleValuesForSQLDataDirectoryType() []string { + return []string{ + string(SQLDataDirectoryTypeData), + string(SQLDataDirectoryTypeInvalid), + string(SQLDataDirectoryTypeLog), + } +} + +func parseSQLDataDirectoryType(input string) (*SQLDataDirectoryType, error) { + vals := map[string]SQLDataDirectoryType{ + "data": SQLDataDirectoryTypeData, + "invalid": SQLDataDirectoryTypeInvalid, + "log": SQLDataDirectoryTypeLog, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SQLDataDirectoryType(input) + return &out, nil +} + +type TargetDiskNetworkAccessOption string + +const ( + TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks TargetDiskNetworkAccessOption = "EnablePrivateAccessForAllDisks" + TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks TargetDiskNetworkAccessOption = "EnablePublicAccessForAllDisks" + TargetDiskNetworkAccessOptionSameAsOnSourceDisks TargetDiskNetworkAccessOption = "SameAsOnSourceDisks" +) + +func PossibleValuesForTargetDiskNetworkAccessOption() []string { + return []string{ + string(TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks), + string(TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks), + string(TargetDiskNetworkAccessOptionSameAsOnSourceDisks), + } +} + +func parseTargetDiskNetworkAccessOption(input string) (*TargetDiskNetworkAccessOption, error) { + vals := map[string]TargetDiskNetworkAccessOption{ + "enableprivateaccessforalldisks": TargetDiskNetworkAccessOptionEnablePrivateAccessForAllDisks, + "enablepublicaccessforalldisks": TargetDiskNetworkAccessOptionEnablePublicAccessForAllDisks, + "sameasonsourcedisks": TargetDiskNetworkAccessOptionSameAsOnSourceDisks, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TargetDiskNetworkAccessOption(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/id_vault.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/id_vault.go new file mode 100644 index 00000000000..1294ad057be --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/id_vault.go @@ -0,0 +1,127 @@ +package validateoperation + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/id_vault_test.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/id_vault_test.go new file mode 100644 index 00000000000..7f3d773ef92 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/id_vault_test.go @@ -0,0 +1,282 @@ +package validateoperation + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicesbackup/2023-02-01/validateoperation/method_trigger_autorest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/method_trigger_autorest.go new file mode 100644 index 00000000000..6d6eb68828f --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/method_trigger_autorest.go @@ -0,0 +1,79 @@ +package validateoperation + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Trigger ... +func (c ValidateOperationClient) Trigger(ctx context.Context, id VaultId, input ValidateOperationRequest) (result TriggerOperationResponse, err error) { + req, err := c.preparerForTrigger(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "validateoperation.ValidateOperationClient", "Trigger", nil, "Failure preparing request") + return + } + + result, err = c.senderForTrigger(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "validateoperation.ValidateOperationClient", "Trigger", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TriggerThenPoll performs Trigger then polls until it's completed +func (c ValidateOperationClient) TriggerThenPoll(ctx context.Context, id VaultId, input ValidateOperationRequest) error { + result, err := c.Trigger(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Trigger: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Trigger: %+v", err) + } + + return nil +} + +// preparerForTrigger prepares the Trigger request. +func (c ValidateOperationClient) preparerForTrigger(ctx context.Context, id VaultId, input ValidateOperationRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/backupTriggerValidateOperation", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTrigger sends the Trigger request. The method will close the +// http.Response Body if it receives an error. +func (c ValidateOperationClient) senderForTrigger(ctx context.Context, req *http.Request) (future TriggerOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azurefilesharerestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azurefilesharerestorerequest.go new file mode 100644 index 00000000000..f7f995b0ccf --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azurefilesharerestorerequest.go @@ -0,0 +1,46 @@ +package validateoperation + +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 _ RestoreRequest = AzureFileShareRestoreRequest{} + +type AzureFileShareRestoreRequest struct { + CopyOptions *CopyOptions `json:"copyOptions,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + RestoreFileSpecs *[]RestoreFileSpecs `json:"restoreFileSpecs,omitempty"` + RestoreRequestType *RestoreRequestType `json:"restoreRequestType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetDetails *TargetAFSRestoreInfo `json:"targetDetails,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureFileShareRestoreRequest{} + +func (s AzureFileShareRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureFileShareRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFileShareRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFileShareRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureFileShareRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFileShareRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadpointintimerestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadpointintimerestorerequest.go new file mode 100644 index 00000000000..4ca971b07b1 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadpointintimerestorerequest.go @@ -0,0 +1,47 @@ +package validateoperation + +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 _ RestoreRequest = AzureWorkloadPointInTimeRestoreRequest{} + +type AzureWorkloadPointInTimeRestoreRequest struct { + PointInTime *string `json:"pointInTime,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadPointInTimeRestoreRequest{} + +func (s AzureWorkloadPointInTimeRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadPointInTimeRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadPointInTimeRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadrestorerequest.go new file mode 100644 index 00000000000..03a7caf817b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadrestorerequest.go @@ -0,0 +1,46 @@ +package validateoperation + +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 _ RestoreRequest = AzureWorkloadRestoreRequest{} + +type AzureWorkloadRestoreRequest struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadRestoreRequest{} + +func (s AzureWorkloadRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadsaphanarestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadsaphanarestorerequest.go new file mode 100644 index 00000000000..28f49cd4217 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadsaphanarestorerequest.go @@ -0,0 +1,46 @@ +package validateoperation + +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 _ RestoreRequest = AzureWorkloadSAPHanaRestoreRequest{} + +type AzureWorkloadSAPHanaRestoreRequest struct { + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadSAPHanaRestoreRequest{} + +func (s AzureWorkloadSAPHanaRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSAPHanaRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSAPHanaRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadsqlrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadsqlrestorerequest.go new file mode 100644 index 00000000000..abf3327bfc4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_azureworkloadsqlrestorerequest.go @@ -0,0 +1,49 @@ +package validateoperation + +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 _ RestoreRequest = AzureWorkloadSQLRestoreRequest{} + +type AzureWorkloadSQLRestoreRequest struct { + AlternateDirectoryPaths *[]SQLDataDirectoryMapping `json:"alternateDirectoryPaths,omitempty"` + IsNonRecoverable *bool `json:"isNonRecoverable,omitempty"` + PropertyBag *map[string]string `json:"propertyBag,omitempty"` + RecoveryMode *RecoveryMode `json:"recoveryMode,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + ShouldUseAlternateTargetLocation *bool `json:"shouldUseAlternateTargetLocation,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + TargetInfo *TargetRestoreInfo `json:"targetInfo,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = AzureWorkloadSQLRestoreRequest{} + +func (s AzureWorkloadSQLRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureWorkloadSQLRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + decoded["objectType"] = "AzureWorkloadSQLRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureWorkloadSQLRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_encryptiondetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_encryptiondetails.go new file mode 100644 index 00000000000..68be47387a8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_encryptiondetails.go @@ -0,0 +1,12 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionDetails struct { + EncryptionEnabled *bool `json:"encryptionEnabled,omitempty"` + KekUrl *string `json:"kekUrl,omitempty"` + KekVaultId *string `json:"kekVaultId,omitempty"` + SecretKeyUrl *string `json:"secretKeyUrl,omitempty"` + SecretKeyVaultId *string `json:"secretKeyVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_extendedlocation.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_extendedlocation.go new file mode 100644 index 00000000000..608d19191a4 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_extendedlocation.go @@ -0,0 +1,9 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_iaasvmrestorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_iaasvmrestorerequest.go new file mode 100644 index 00000000000..b6ff82b3064 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_iaasvmrestorerequest.go @@ -0,0 +1,65 @@ +package validateoperation + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreRequest = IaasVMRestoreRequest{} + +type IaasVMRestoreRequest struct { + AffinityGroup *string `json:"affinityGroup,omitempty"` + CreateNewCloudService *bool `json:"createNewCloudService,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + EncryptionDetails *EncryptionDetails `json:"encryptionDetails,omitempty"` + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + IdentityBasedRestoreDetails *IdentityBasedRestoreDetails `json:"identityBasedRestoreDetails,omitempty"` + IdentityInfo *IdentityInfo `json:"identityInfo,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + Region *string `json:"region,omitempty"` + RestoreDiskLunList *[]int64 `json:"restoreDiskLunList,omitempty"` + RestoreWithManagedDisks *bool `json:"restoreWithManagedDisks,omitempty"` + SecuredVMDetails *SecuredVMDetails `json:"securedVMDetails,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TargetDiskNetworkAccessSettings *TargetDiskNetworkAccessSettings `json:"targetDiskNetworkAccessSettings,omitempty"` + TargetDomainNameId *string `json:"targetDomainNameId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + VirtualNetworkId *string `json:"virtualNetworkId,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = IaasVMRestoreRequest{} + +func (s IaasVMRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRestoreRequest: %+v", err) + } + decoded["objectType"] = "IaasVMRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRestoreRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_iaasvmrestorewithrehydrationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_iaasvmrestorewithrehydrationrequest.go new file mode 100644 index 00000000000..6ab30430699 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_iaasvmrestorewithrehydrationrequest.go @@ -0,0 +1,66 @@ +package validateoperation + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreRequest = IaasVMRestoreWithRehydrationRequest{} + +type IaasVMRestoreWithRehydrationRequest struct { + AffinityGroup *string `json:"affinityGroup,omitempty"` + CreateNewCloudService *bool `json:"createNewCloudService,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + EncryptionDetails *EncryptionDetails `json:"encryptionDetails,omitempty"` + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + IdentityBasedRestoreDetails *IdentityBasedRestoreDetails `json:"identityBasedRestoreDetails,omitempty"` + IdentityInfo *IdentityInfo `json:"identityInfo,omitempty"` + OriginalStorageAccountOption *bool `json:"originalStorageAccountOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointRehydrationInfo *RecoveryPointRehydrationInfo `json:"recoveryPointRehydrationInfo,omitempty"` + RecoveryType *RecoveryType `json:"recoveryType,omitempty"` + Region *string `json:"region,omitempty"` + RestoreDiskLunList *[]int64 `json:"restoreDiskLunList,omitempty"` + RestoreWithManagedDisks *bool `json:"restoreWithManagedDisks,omitempty"` + SecuredVMDetails *SecuredVMDetails `json:"securedVMDetails,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TargetDiskNetworkAccessSettings *TargetDiskNetworkAccessSettings `json:"targetDiskNetworkAccessSettings,omitempty"` + TargetDomainNameId *string `json:"targetDomainNameId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVirtualMachineId *string `json:"targetVirtualMachineId,omitempty"` + VirtualNetworkId *string `json:"virtualNetworkId,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` + + // Fields inherited from RestoreRequest +} + +var _ json.Marshaler = IaasVMRestoreWithRehydrationRequest{} + +func (s IaasVMRestoreWithRehydrationRequest) MarshalJSON() ([]byte, error) { + type wrapper IaasVMRestoreWithRehydrationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + decoded["objectType"] = "IaasVMRestoreWithRehydrationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IaasVMRestoreWithRehydrationRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_identitybasedrestoredetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_identitybasedrestoredetails.go new file mode 100644 index 00000000000..d804db396e3 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_identitybasedrestoredetails.go @@ -0,0 +1,9 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityBasedRestoreDetails struct { + ObjectType *string `json:"objectType,omitempty"` + TargetStorageAccountId *string `json:"targetStorageAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_identityinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_identityinfo.go new file mode 100644 index 00000000000..71e633fc3ea --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_identityinfo.go @@ -0,0 +1,9 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityInfo struct { + IsSystemAssignedIdentity *bool `json:"isSystemAssignedIdentity,omitempty"` + ManagedIdentityResourceId *string `json:"managedIdentityResourceId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_recoverypointrehydrationinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_recoverypointrehydrationinfo.go new file mode 100644 index 00000000000..9f5b85e6ad0 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_recoverypointrehydrationinfo.go @@ -0,0 +1,9 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointRehydrationInfo struct { + RehydrationPriority *RehydrationPriority `json:"rehydrationPriority,omitempty"` + RehydrationRetentionDuration *string `json:"rehydrationRetentionDuration,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_restorefilespecs.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_restorefilespecs.go new file mode 100644 index 00000000000..f850cae1f62 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_restorefilespecs.go @@ -0,0 +1,10 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestoreFileSpecs struct { + FileSpecType *string `json:"fileSpecType,omitempty"` + Path *string `json:"path,omitempty"` + TargetFolderPath *string `json:"targetFolderPath,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_restorerequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_restorerequest.go new file mode 100644 index 00000000000..9ca0f81e1a2 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_restorerequest.go @@ -0,0 +1,96 @@ +package validateoperation + +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 RestoreRequest interface { +} + +func unmarshalRestoreRequestImplementation(input []byte) (RestoreRequest, 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 RestoreRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFileShareRestoreRequest") { + var out AzureFileShareRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFileShareRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadPointInTimeRestoreRequest") { + var out AzureWorkloadPointInTimeRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadPointInTimeRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadRestoreRequest") { + var out AzureWorkloadRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSAPHanaRestoreRequest") { + var out AzureWorkloadSAPHanaRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSAPHanaRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureWorkloadSQLRestoreRequest") { + var out AzureWorkloadSQLRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureWorkloadSQLRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRestoreRequest") { + var out IaasVMRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IaasVMRestoreWithRehydrationRequest") { + var out IaasVMRestoreWithRehydrationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IaasVMRestoreWithRehydrationRequest: %+v", err) + } + return out, nil + } + + type RawRestoreRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRestoreRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_securedvmdetails.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_securedvmdetails.go new file mode 100644 index 00000000000..d6bbd38ddcc --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_securedvmdetails.go @@ -0,0 +1,8 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecuredVMDetails struct { + SecuredVMOsDiskEncryptionSetId *string `json:"securedVMOsDiskEncryptionSetId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_sqldatadirectorymapping.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_sqldatadirectorymapping.go new file mode 100644 index 00000000000..3d7ad759e25 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_sqldatadirectorymapping.go @@ -0,0 +1,11 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SQLDataDirectoryMapping struct { + MappingType *SQLDataDirectoryType `json:"mappingType,omitempty"` + SourceLogicalName *string `json:"sourceLogicalName,omitempty"` + SourcePath *string `json:"sourcePath,omitempty"` + TargetPath *string `json:"targetPath,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetafsrestoreinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetafsrestoreinfo.go new file mode 100644 index 00000000000..32d155ab051 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetafsrestoreinfo.go @@ -0,0 +1,9 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetAFSRestoreInfo struct { + Name *string `json:"name,omitempty"` + TargetResourceId *string `json:"targetResourceId,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetdisknetworkaccesssettings.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetdisknetworkaccesssettings.go new file mode 100644 index 00000000000..9185ea14d0c --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetdisknetworkaccesssettings.go @@ -0,0 +1,9 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetDiskNetworkAccessSettings struct { + TargetDiskAccessId *string `json:"targetDiskAccessId,omitempty"` + TargetDiskNetworkAccessOption *TargetDiskNetworkAccessOption `json:"targetDiskNetworkAccessOption,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetrestoreinfo.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetrestoreinfo.go new file mode 100644 index 00000000000..03ec88a3e93 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_targetrestoreinfo.go @@ -0,0 +1,11 @@ +package validateoperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetRestoreInfo struct { + ContainerId *string `json:"containerId,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + OverwriteOption *OverwriteOptions `json:"overwriteOption,omitempty"` + TargetDirectoryForFileRestore *string `json:"targetDirectoryForFileRestore,omitempty"` +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validateiaasvmrestoreoperationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validateiaasvmrestoreoperationrequest.go new file mode 100644 index 00000000000..01dc3ab0f73 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validateiaasvmrestoreoperationrequest.go @@ -0,0 +1,60 @@ +package validateoperation + +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 _ ValidateOperationRequest = ValidateIaasVMRestoreOperationRequest{} + +type ValidateIaasVMRestoreOperationRequest struct { + RestoreRequest RestoreRequest `json:"restoreRequest"` + + // Fields inherited from ValidateOperationRequest +} + +var _ json.Marshaler = ValidateIaasVMRestoreOperationRequest{} + +func (s ValidateIaasVMRestoreOperationRequest) MarshalJSON() ([]byte, error) { + type wrapper ValidateIaasVMRestoreOperationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ValidateIaasVMRestoreOperationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ValidateIaasVMRestoreOperationRequest: %+v", err) + } + decoded["objectType"] = "ValidateIaasVMRestoreOperationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ValidateIaasVMRestoreOperationRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &ValidateIaasVMRestoreOperationRequest{} + +func (s *ValidateIaasVMRestoreOperationRequest) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateIaasVMRestoreOperationRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequest"]; ok { + impl, err := unmarshalRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequest' for 'ValidateIaasVMRestoreOperationRequest': %+v", err) + } + s.RestoreRequest = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validateoperationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validateoperationrequest.go new file mode 100644 index 00000000000..3bf7633aff8 --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validateoperationrequest.go @@ -0,0 +1,56 @@ +package validateoperation + +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 ValidateOperationRequest interface { +} + +func unmarshalValidateOperationRequestImplementation(input []byte) (ValidateOperationRequest, 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 ValidateOperationRequest into map[string]interface: %+v", err) + } + + value, ok := temp["objectType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ValidateIaasVMRestoreOperationRequest") { + var out ValidateIaasVMRestoreOperationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ValidateIaasVMRestoreOperationRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ValidateRestoreOperationRequest") { + var out ValidateRestoreOperationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ValidateRestoreOperationRequest: %+v", err) + } + return out, nil + } + + type RawValidateOperationRequestImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawValidateOperationRequestImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validaterestoreoperationrequest.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validaterestoreoperationrequest.go new file mode 100644 index 00000000000..16aa0307fac --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/model_validaterestoreoperationrequest.go @@ -0,0 +1,60 @@ +package validateoperation + +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 _ ValidateOperationRequest = ValidateRestoreOperationRequest{} + +type ValidateRestoreOperationRequest struct { + RestoreRequest RestoreRequest `json:"restoreRequest"` + + // Fields inherited from ValidateOperationRequest +} + +var _ json.Marshaler = ValidateRestoreOperationRequest{} + +func (s ValidateRestoreOperationRequest) MarshalJSON() ([]byte, error) { + type wrapper ValidateRestoreOperationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ValidateRestoreOperationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ValidateRestoreOperationRequest: %+v", err) + } + decoded["objectType"] = "ValidateRestoreOperationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ValidateRestoreOperationRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &ValidateRestoreOperationRequest{} + +func (s *ValidateRestoreOperationRequest) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateRestoreOperationRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequest"]; ok { + impl, err := unmarshalRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequest' for 'ValidateRestoreOperationRequest': %+v", err) + } + s.RestoreRequest = impl + } + return nil +} diff --git a/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/version.go b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/version.go new file mode 100644 index 00000000000..fc4547ca58b --- /dev/null +++ b/resource-manager/recoveryservicesbackup/2023-02-01/validateoperation/version.go @@ -0,0 +1,12 @@ +package validateoperation + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/validateoperation/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/client.go new file mode 100644 index 00000000000..1f285f979d0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/client.go @@ -0,0 +1,179 @@ +package v2023_01_01 + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems" + "github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Client struct { + MigrationRecoveryPoints *migrationrecoverypoints.MigrationRecoveryPointsClient + RecoveryPoints *recoverypoints.RecoveryPointsClient + ReplicationAlertSettings *replicationalertsettings.ReplicationAlertSettingsClient + ReplicationAppliances *replicationappliances.ReplicationAppliancesClient + ReplicationEligibilityResults *replicationeligibilityresults.ReplicationEligibilityResultsClient + ReplicationEvents *replicationevents.ReplicationEventsClient + ReplicationFabrics *replicationfabrics.ReplicationFabricsClient + ReplicationJobs *replicationjobs.ReplicationJobsClient + ReplicationLogicalNetworks *replicationlogicalnetworks.ReplicationLogicalNetworksClient + ReplicationMigrationItems *replicationmigrationitems.ReplicationMigrationItemsClient + ReplicationNetworkMappings *replicationnetworkmappings.ReplicationNetworkMappingsClient + ReplicationNetworks *replicationnetworks.ReplicationNetworksClient + ReplicationPolicies *replicationpolicies.ReplicationPoliciesClient + ReplicationProtectableItems *replicationprotectableitems.ReplicationProtectableItemsClient + ReplicationProtectedItems *replicationprotecteditems.ReplicationProtectedItemsClient + ReplicationProtectionContainerMappings *replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient + ReplicationProtectionContainers *replicationprotectioncontainers.ReplicationProtectionContainersClient + ReplicationProtectionIntents *replicationprotectionintents.ReplicationProtectionIntentsClient + ReplicationRecoveryPlans *replicationrecoveryplans.ReplicationRecoveryPlansClient + ReplicationRecoveryServicesProviders *replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient + ReplicationStorageClassificationMappings *replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient + ReplicationStorageClassifications *replicationstorageclassifications.ReplicationStorageClassificationsClient + ReplicationVaultHealth *replicationvaulthealth.ReplicationVaultHealthClient + ReplicationVaultSetting *replicationvaultsetting.ReplicationVaultSettingClient + ReplicationvCenters *replicationvcenters.ReplicationvCentersClient + SupportedOperatingSystems *supportedoperatingsystems.SupportedOperatingSystemsClient + TargetComputeSizes *targetcomputesizes.TargetComputeSizesClient +} + +func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { + + migrationRecoveryPointsClient := migrationrecoverypoints.NewMigrationRecoveryPointsClientWithBaseURI(endpoint) + configureAuthFunc(&migrationRecoveryPointsClient.Client) + + recoveryPointsClient := recoverypoints.NewRecoveryPointsClientWithBaseURI(endpoint) + configureAuthFunc(&recoveryPointsClient.Client) + + replicationAlertSettingsClient := replicationalertsettings.NewReplicationAlertSettingsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationAlertSettingsClient.Client) + + replicationAppliancesClient := replicationappliances.NewReplicationAppliancesClientWithBaseURI(endpoint) + configureAuthFunc(&replicationAppliancesClient.Client) + + replicationEligibilityResultsClient := replicationeligibilityresults.NewReplicationEligibilityResultsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationEligibilityResultsClient.Client) + + replicationEventsClient := replicationevents.NewReplicationEventsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationEventsClient.Client) + + replicationFabricsClient := replicationfabrics.NewReplicationFabricsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationFabricsClient.Client) + + replicationJobsClient := replicationjobs.NewReplicationJobsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationJobsClient.Client) + + replicationLogicalNetworksClient := replicationlogicalnetworks.NewReplicationLogicalNetworksClientWithBaseURI(endpoint) + configureAuthFunc(&replicationLogicalNetworksClient.Client) + + replicationMigrationItemsClient := replicationmigrationitems.NewReplicationMigrationItemsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationMigrationItemsClient.Client) + + replicationNetworkMappingsClient := replicationnetworkmappings.NewReplicationNetworkMappingsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationNetworkMappingsClient.Client) + + replicationNetworksClient := replicationnetworks.NewReplicationNetworksClientWithBaseURI(endpoint) + configureAuthFunc(&replicationNetworksClient.Client) + + replicationPoliciesClient := replicationpolicies.NewReplicationPoliciesClientWithBaseURI(endpoint) + configureAuthFunc(&replicationPoliciesClient.Client) + + replicationProtectableItemsClient := replicationprotectableitems.NewReplicationProtectableItemsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationProtectableItemsClient.Client) + + replicationProtectedItemsClient := replicationprotecteditems.NewReplicationProtectedItemsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationProtectedItemsClient.Client) + + replicationProtectionContainerMappingsClient := replicationprotectioncontainermappings.NewReplicationProtectionContainerMappingsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationProtectionContainerMappingsClient.Client) + + replicationProtectionContainersClient := replicationprotectioncontainers.NewReplicationProtectionContainersClientWithBaseURI(endpoint) + configureAuthFunc(&replicationProtectionContainersClient.Client) + + replicationProtectionIntentsClient := replicationprotectionintents.NewReplicationProtectionIntentsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationProtectionIntentsClient.Client) + + replicationRecoveryPlansClient := replicationrecoveryplans.NewReplicationRecoveryPlansClientWithBaseURI(endpoint) + configureAuthFunc(&replicationRecoveryPlansClient.Client) + + replicationRecoveryServicesProvidersClient := replicationrecoveryservicesproviders.NewReplicationRecoveryServicesProvidersClientWithBaseURI(endpoint) + configureAuthFunc(&replicationRecoveryServicesProvidersClient.Client) + + replicationStorageClassificationMappingsClient := replicationstorageclassificationmappings.NewReplicationStorageClassificationMappingsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationStorageClassificationMappingsClient.Client) + + replicationStorageClassificationsClient := replicationstorageclassifications.NewReplicationStorageClassificationsClientWithBaseURI(endpoint) + configureAuthFunc(&replicationStorageClassificationsClient.Client) + + replicationVaultHealthClient := replicationvaulthealth.NewReplicationVaultHealthClientWithBaseURI(endpoint) + configureAuthFunc(&replicationVaultHealthClient.Client) + + replicationVaultSettingClient := replicationvaultsetting.NewReplicationVaultSettingClientWithBaseURI(endpoint) + configureAuthFunc(&replicationVaultSettingClient.Client) + + replicationvCentersClient := replicationvcenters.NewReplicationvCentersClientWithBaseURI(endpoint) + configureAuthFunc(&replicationvCentersClient.Client) + + supportedOperatingSystemsClient := supportedoperatingsystems.NewSupportedOperatingSystemsClientWithBaseURI(endpoint) + configureAuthFunc(&supportedOperatingSystemsClient.Client) + + targetComputeSizesClient := targetcomputesizes.NewTargetComputeSizesClientWithBaseURI(endpoint) + configureAuthFunc(&targetComputeSizesClient.Client) + + return Client{ + MigrationRecoveryPoints: &migrationRecoveryPointsClient, + RecoveryPoints: &recoveryPointsClient, + ReplicationAlertSettings: &replicationAlertSettingsClient, + ReplicationAppliances: &replicationAppliancesClient, + ReplicationEligibilityResults: &replicationEligibilityResultsClient, + ReplicationEvents: &replicationEventsClient, + ReplicationFabrics: &replicationFabricsClient, + ReplicationJobs: &replicationJobsClient, + ReplicationLogicalNetworks: &replicationLogicalNetworksClient, + ReplicationMigrationItems: &replicationMigrationItemsClient, + ReplicationNetworkMappings: &replicationNetworkMappingsClient, + ReplicationNetworks: &replicationNetworksClient, + ReplicationPolicies: &replicationPoliciesClient, + ReplicationProtectableItems: &replicationProtectableItemsClient, + ReplicationProtectedItems: &replicationProtectedItemsClient, + ReplicationProtectionContainerMappings: &replicationProtectionContainerMappingsClient, + ReplicationProtectionContainers: &replicationProtectionContainersClient, + ReplicationProtectionIntents: &replicationProtectionIntentsClient, + ReplicationRecoveryPlans: &replicationRecoveryPlansClient, + ReplicationRecoveryServicesProviders: &replicationRecoveryServicesProvidersClient, + ReplicationStorageClassificationMappings: &replicationStorageClassificationMappingsClient, + ReplicationStorageClassifications: &replicationStorageClassificationsClient, + ReplicationVaultHealth: &replicationVaultHealthClient, + ReplicationVaultSetting: &replicationVaultSettingClient, + ReplicationvCenters: &replicationvCentersClient, + SupportedOperatingSystems: &supportedOperatingSystemsClient, + TargetComputeSizes: &targetComputeSizesClient, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/README.md new file mode 100644 index 00000000000..721a9a1e738 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints` Documentation + +The `migrationrecoverypoints` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints" +``` + + +### Client Initialization + +```go +client := migrationrecoverypoints.NewMigrationRecoveryPointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MigrationRecoveryPointsClient.Get` + +```go +ctx := context.TODO() +id := migrationrecoverypoints.NewMigrationRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue", "migrationRecoveryPointValue") + +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: `MigrationRecoveryPointsClient.ListByReplicationMigrationItems` + +```go +ctx := context.TODO() +id := migrationrecoverypoints.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +// alternatively `client.ListByReplicationMigrationItems(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationMigrationItemsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/client.go new file mode 100644 index 00000000000..950ecf18150 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/client.go @@ -0,0 +1,18 @@ +package migrationrecoverypoints + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRecoveryPointsClient struct { + Client autorest.Client + baseUri string +} + +func NewMigrationRecoveryPointsClientWithBaseURI(endpoint string) MigrationRecoveryPointsClient { + return MigrationRecoveryPointsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/constants.go new file mode 100644 index 00000000000..d34e9f30fac --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/constants.go @@ -0,0 +1,37 @@ +package migrationrecoverypoints + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRecoveryPointType string + +const ( + MigrationRecoveryPointTypeApplicationConsistent MigrationRecoveryPointType = "ApplicationConsistent" + MigrationRecoveryPointTypeCrashConsistent MigrationRecoveryPointType = "CrashConsistent" + MigrationRecoveryPointTypeNotSpecified MigrationRecoveryPointType = "NotSpecified" +) + +func PossibleValuesForMigrationRecoveryPointType() []string { + return []string{ + string(MigrationRecoveryPointTypeApplicationConsistent), + string(MigrationRecoveryPointTypeCrashConsistent), + string(MigrationRecoveryPointTypeNotSpecified), + } +} + +func parseMigrationRecoveryPointType(input string) (*MigrationRecoveryPointType, error) { + vals := map[string]MigrationRecoveryPointType{ + "applicationconsistent": MigrationRecoveryPointTypeApplicationConsistent, + "crashconsistent": MigrationRecoveryPointTypeCrashConsistent, + "notspecified": MigrationRecoveryPointTypeNotSpecified, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MigrationRecoveryPointType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_migrationrecoverypoint.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_migrationrecoverypoint.go new file mode 100644 index 00000000000..a1ce5970fdb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_migrationrecoverypoint.go @@ -0,0 +1,179 @@ +package migrationrecoverypoints + +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 = MigrationRecoveryPointId{} + +// MigrationRecoveryPointId is a struct representing the Resource ID for a Migration Recovery Point +type MigrationRecoveryPointId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationMigrationItemName string + MigrationRecoveryPointName string +} + +// NewMigrationRecoveryPointID returns a new MigrationRecoveryPointId struct +func NewMigrationRecoveryPointID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationMigrationItemName string, migrationRecoveryPointName string) MigrationRecoveryPointId { + return MigrationRecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationMigrationItemName: replicationMigrationItemName, + MigrationRecoveryPointName: migrationRecoveryPointName, + } +} + +// ParseMigrationRecoveryPointID parses 'input' into a MigrationRecoveryPointId +func ParseMigrationRecoveryPointID(input string) (*MigrationRecoveryPointId, error) { + parser := resourceids.NewParserFromResourceIdType(MigrationRecoveryPointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MigrationRecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationMigrationItemName, ok = parsed.Parsed["replicationMigrationItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationMigrationItemName' was not found in the resource id %q", input) + } + + if id.MigrationRecoveryPointName, ok = parsed.Parsed["migrationRecoveryPointName"]; !ok { + return nil, fmt.Errorf("the segment 'migrationRecoveryPointName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseMigrationRecoveryPointIDInsensitively parses 'input' case-insensitively into a MigrationRecoveryPointId +// note: this method should only be used for API response data and not user input +func ParseMigrationRecoveryPointIDInsensitively(input string) (*MigrationRecoveryPointId, error) { + parser := resourceids.NewParserFromResourceIdType(MigrationRecoveryPointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := MigrationRecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationMigrationItemName, ok = parsed.Parsed["replicationMigrationItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationMigrationItemName' was not found in the resource id %q", input) + } + + if id.MigrationRecoveryPointName, ok = parsed.Parsed["migrationRecoveryPointName"]; !ok { + return nil, fmt.Errorf("the segment 'migrationRecoveryPointName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateMigrationRecoveryPointID checks that 'input' can be parsed as a Migration Recovery Point ID +func ValidateMigrationRecoveryPointID(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 := ParseMigrationRecoveryPointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Migration Recovery Point ID +func (id MigrationRecoveryPointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationMigrationItems/%s/migrationRecoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationMigrationItemName, id.MigrationRecoveryPointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Migration Recovery Point ID +func (id MigrationRecoveryPointId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationMigrationItems", "replicationMigrationItems", "replicationMigrationItems"), + resourceids.UserSpecifiedSegment("replicationMigrationItemName", "replicationMigrationItemValue"), + resourceids.StaticSegment("staticMigrationRecoveryPoints", "migrationRecoveryPoints", "migrationRecoveryPoints"), + resourceids.UserSpecifiedSegment("migrationRecoveryPointName", "migrationRecoveryPointValue"), + } +} + +// String returns a human-readable description of this Migration Recovery Point ID +func (id MigrationRecoveryPointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Migration Item Name: %q", id.ReplicationMigrationItemName), + fmt.Sprintf("Migration Recovery Point Name: %q", id.MigrationRecoveryPointName), + } + return fmt.Sprintf("Migration Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_migrationrecoverypoint_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_migrationrecoverypoint_test.go new file mode 100644 index 00000000000..5c501de9802 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_migrationrecoverypoint_test.go @@ -0,0 +1,462 @@ +package migrationrecoverypoints + +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 = MigrationRecoveryPointId{} + +func TestNewMigrationRecoveryPointID(t *testing.T) { + id := NewMigrationRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue", "migrationRecoveryPointValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationMigrationItemName != "replicationMigrationItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationMigrationItemName'", id.ReplicationMigrationItemName, "replicationMigrationItemValue") + } + + if id.MigrationRecoveryPointName != "migrationRecoveryPointValue" { + t.Fatalf("Expected %q but got %q for Segment 'MigrationRecoveryPointName'", id.MigrationRecoveryPointName, "migrationRecoveryPointValue") + } +} + +func TestFormatMigrationRecoveryPointID(t *testing.T) { + actual := NewMigrationRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue", "migrationRecoveryPointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/migrationRecoveryPoints/migrationRecoveryPointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMigrationRecoveryPointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MigrationRecoveryPointId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/migrationRecoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/migrationRecoveryPoints/migrationRecoveryPointValue", + Expected: &MigrationRecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationMigrationItemName: "replicationMigrationItemValue", + MigrationRecoveryPointName: "migrationRecoveryPointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/migrationRecoveryPoints/migrationRecoveryPointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMigrationRecoveryPointID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationMigrationItemName != v.Expected.ReplicationMigrationItemName { + t.Fatalf("Expected %q but got %q for ReplicationMigrationItemName", v.Expected.ReplicationMigrationItemName, actual.ReplicationMigrationItemName) + } + + if actual.MigrationRecoveryPointName != v.Expected.MigrationRecoveryPointName { + t.Fatalf("Expected %q but got %q for MigrationRecoveryPointName", v.Expected.MigrationRecoveryPointName, actual.MigrationRecoveryPointName) + } + + } +} + +func TestParseMigrationRecoveryPointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MigrationRecoveryPointId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/migrationRecoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe/mIgRaTiOnReCoVeRyPoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/migrationRecoveryPoints/migrationRecoveryPointValue", + Expected: &MigrationRecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationMigrationItemName: "replicationMigrationItemValue", + MigrationRecoveryPointName: "migrationRecoveryPointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/migrationRecoveryPoints/migrationRecoveryPointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe/mIgRaTiOnReCoVeRyPoInTs/mIgRaTiOnReCoVeRyPoInTvAlUe", + Expected: &MigrationRecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationMigrationItemName: "rEpLiCaTiOnMiGrAtIoNiTeMvAlUe", + MigrationRecoveryPointName: "mIgRaTiOnReCoVeRyPoInTvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe/mIgRaTiOnReCoVeRyPoInTs/mIgRaTiOnReCoVeRyPoInTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMigrationRecoveryPointIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationMigrationItemName != v.Expected.ReplicationMigrationItemName { + t.Fatalf("Expected %q but got %q for ReplicationMigrationItemName", v.Expected.ReplicationMigrationItemName, actual.ReplicationMigrationItemName) + } + + if actual.MigrationRecoveryPointName != v.Expected.MigrationRecoveryPointName { + t.Fatalf("Expected %q but got %q for MigrationRecoveryPointName", v.Expected.MigrationRecoveryPointName, actual.MigrationRecoveryPointName) + } + + } +} + +func TestSegmentsForMigrationRecoveryPointId(t *testing.T) { + segments := MigrationRecoveryPointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MigrationRecoveryPointId 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/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_replicationmigrationitem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_replicationmigrationitem.go new file mode 100644 index 00000000000..403910fabe1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_replicationmigrationitem.go @@ -0,0 +1,166 @@ +package migrationrecoverypoints + +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 = ReplicationMigrationItemId{} + +// ReplicationMigrationItemId is a struct representing the Resource ID for a Replication Migration Item +type ReplicationMigrationItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationMigrationItemName string +} + +// NewReplicationMigrationItemID returns a new ReplicationMigrationItemId struct +func NewReplicationMigrationItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationMigrationItemName string) ReplicationMigrationItemId { + return ReplicationMigrationItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationMigrationItemName: replicationMigrationItemName, + } +} + +// ParseReplicationMigrationItemID parses 'input' into a ReplicationMigrationItemId +func ParseReplicationMigrationItemID(input string) (*ReplicationMigrationItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationMigrationItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationMigrationItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationMigrationItemName, ok = parsed.Parsed["replicationMigrationItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationMigrationItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationMigrationItemIDInsensitively parses 'input' case-insensitively into a ReplicationMigrationItemId +// note: this method should only be used for API response data and not user input +func ParseReplicationMigrationItemIDInsensitively(input string) (*ReplicationMigrationItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationMigrationItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationMigrationItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationMigrationItemName, ok = parsed.Parsed["replicationMigrationItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationMigrationItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationMigrationItemID checks that 'input' can be parsed as a Replication Migration Item ID +func ValidateReplicationMigrationItemID(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 := ParseReplicationMigrationItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Migration Item ID +func (id ReplicationMigrationItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationMigrationItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationMigrationItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Migration Item ID +func (id ReplicationMigrationItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationMigrationItems", "replicationMigrationItems", "replicationMigrationItems"), + resourceids.UserSpecifiedSegment("replicationMigrationItemName", "replicationMigrationItemValue"), + } +} + +// String returns a human-readable description of this Replication Migration Item ID +func (id ReplicationMigrationItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Migration Item Name: %q", id.ReplicationMigrationItemName), + } + return fmt.Sprintf("Replication Migration Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_replicationmigrationitem_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_replicationmigrationitem_test.go new file mode 100644 index 00000000000..9c0fb9b40b5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/id_replicationmigrationitem_test.go @@ -0,0 +1,417 @@ +package migrationrecoverypoints + +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 = ReplicationMigrationItemId{} + +func TestNewReplicationMigrationItemID(t *testing.T) { + id := NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationMigrationItemName != "replicationMigrationItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationMigrationItemName'", id.ReplicationMigrationItemName, "replicationMigrationItemValue") + } +} + +func TestFormatReplicationMigrationItemID(t *testing.T) { + actual := NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationMigrationItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationMigrationItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue", + Expected: &ReplicationMigrationItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationMigrationItemName: "replicationMigrationItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationMigrationItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationMigrationItemName != v.Expected.ReplicationMigrationItemName { + t.Fatalf("Expected %q but got %q for ReplicationMigrationItemName", v.Expected.ReplicationMigrationItemName, actual.ReplicationMigrationItemName) + } + + } +} + +func TestParseReplicationMigrationItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationMigrationItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue", + Expected: &ReplicationMigrationItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationMigrationItemName: "replicationMigrationItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe", + Expected: &ReplicationMigrationItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationMigrationItemName: "rEpLiCaTiOnMiGrAtIoNiTeMvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationMigrationItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationMigrationItemName != v.Expected.ReplicationMigrationItemName { + t.Fatalf("Expected %q but got %q for ReplicationMigrationItemName", v.Expected.ReplicationMigrationItemName, actual.ReplicationMigrationItemName) + } + + } +} + +func TestSegmentsForReplicationMigrationItemId(t *testing.T) { + segments := ReplicationMigrationItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationMigrationItemId 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/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/method_get_autorest.go new file mode 100644 index 00000000000..0ebb4bb8bc3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/method_get_autorest.go @@ -0,0 +1,68 @@ +package migrationrecoverypoints + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *MigrationRecoveryPoint +} + +// Get ... +func (c MigrationRecoveryPointsClient) Get(ctx context.Context, id MigrationRecoveryPointId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c MigrationRecoveryPointsClient) preparerForGet(ctx context.Context, id MigrationRecoveryPointId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c MigrationRecoveryPointsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/method_listbyreplicationmigrationitems_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/method_listbyreplicationmigrationitems_autorest.go new file mode 100644 index 00000000000..50d6454baac --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/method_listbyreplicationmigrationitems_autorest.go @@ -0,0 +1,186 @@ +package migrationrecoverypoints + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationMigrationItemsOperationResponse struct { + HttpResponse *http.Response + Model *[]MigrationRecoveryPoint + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationMigrationItemsOperationResponse, error) +} + +type ListByReplicationMigrationItemsCompleteResult struct { + Items []MigrationRecoveryPoint +} + +func (r ListByReplicationMigrationItemsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationMigrationItemsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationMigrationItemsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationMigrationItems ... +func (c MigrationRecoveryPointsClient) ListByReplicationMigrationItems(ctx context.Context, id ReplicationMigrationItemId) (resp ListByReplicationMigrationItemsOperationResponse, err error) { + req, err := c.preparerForListByReplicationMigrationItems(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "ListByReplicationMigrationItems", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "ListByReplicationMigrationItems", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationMigrationItems(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "ListByReplicationMigrationItems", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationMigrationItems prepares the ListByReplicationMigrationItems request. +func (c MigrationRecoveryPointsClient) preparerForListByReplicationMigrationItems(ctx context.Context, id ReplicationMigrationItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/migrationRecoveryPoints", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationMigrationItemsWithNextLink prepares the ListByReplicationMigrationItems request with the given nextLink token. +func (c MigrationRecoveryPointsClient) preparerForListByReplicationMigrationItemsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationMigrationItems handles the response to the ListByReplicationMigrationItems request. The method always +// closes the http.Response Body. +func (c MigrationRecoveryPointsClient) responderForListByReplicationMigrationItems(resp *http.Response) (result ListByReplicationMigrationItemsOperationResponse, err error) { + type page struct { + Values []MigrationRecoveryPoint `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationMigrationItemsOperationResponse, err error) { + req, err := c.preparerForListByReplicationMigrationItemsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "ListByReplicationMigrationItems", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "ListByReplicationMigrationItems", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationMigrationItems(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "migrationrecoverypoints.MigrationRecoveryPointsClient", "ListByReplicationMigrationItems", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationMigrationItemsComplete retrieves all of the results into a single object +func (c MigrationRecoveryPointsClient) ListByReplicationMigrationItemsComplete(ctx context.Context, id ReplicationMigrationItemId) (ListByReplicationMigrationItemsCompleteResult, error) { + return c.ListByReplicationMigrationItemsCompleteMatchingPredicate(ctx, id, MigrationRecoveryPointOperationPredicate{}) +} + +// ListByReplicationMigrationItemsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c MigrationRecoveryPointsClient) ListByReplicationMigrationItemsCompleteMatchingPredicate(ctx context.Context, id ReplicationMigrationItemId, predicate MigrationRecoveryPointOperationPredicate) (resp ListByReplicationMigrationItemsCompleteResult, err error) { + items := make([]MigrationRecoveryPoint, 0) + + page, err := c.ListByReplicationMigrationItems(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationMigrationItemsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/model_migrationrecoverypoint.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/model_migrationrecoverypoint.go new file mode 100644 index 00000000000..6b0ba9fb2d1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/model_migrationrecoverypoint.go @@ -0,0 +1,12 @@ +package migrationrecoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRecoveryPoint struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MigrationRecoveryPointProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/model_migrationrecoverypointproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/model_migrationrecoverypointproperties.go new file mode 100644 index 00000000000..65f481c3cb9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/model_migrationrecoverypointproperties.go @@ -0,0 +1,27 @@ +package migrationrecoverypoints + +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 MigrationRecoveryPointProperties struct { + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *MigrationRecoveryPointType `json:"recoveryPointType,omitempty"` +} + +func (o *MigrationRecoveryPointProperties) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MigrationRecoveryPointProperties) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/predicates.go new file mode 100644 index 00000000000..2d50ad009a2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/predicates.go @@ -0,0 +1,32 @@ +package migrationrecoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationRecoveryPointOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p MigrationRecoveryPointOperationPredicate) Matches(input MigrationRecoveryPoint) bool { + + 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/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/version.go new file mode 100644 index 00000000000..624feac1d3f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/migrationrecoverypoints/version.go @@ -0,0 +1,12 @@ +package migrationrecoverypoints + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/migrationrecoverypoints/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/README.md new file mode 100644 index 00000000000..191b7297d48 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints` Documentation + +The `recoverypoints` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/recoverypoints" +``` + + +### Client Initialization + +```go +client := recoverypoints.NewRecoveryPointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoveryPointsClient.Get` + +```go +ctx := context.TODO() +id := recoverypoints.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue", "recoveryPointValue") + +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: `RecoveryPointsClient.ListByReplicationProtectedItems` + +```go +ctx := context.TODO() +id := recoverypoints.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +// alternatively `client.ListByReplicationProtectedItems(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationProtectedItemsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/client.go new file mode 100644 index 00000000000..dab85424069 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/client.go @@ -0,0 +1,18 @@ +package recoverypoints + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointsClient struct { + Client autorest.Client + baseUri string +} + +func NewRecoveryPointsClientWithBaseURI(endpoint string) RecoveryPointsClient { + return RecoveryPointsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/constants.go new file mode 100644 index 00000000000..ffff29a089f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/constants.go @@ -0,0 +1,34 @@ +package recoverypoints + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointSyncType string + +const ( + RecoveryPointSyncTypeMultiVMSyncRecoveryPoint RecoveryPointSyncType = "MultiVmSyncRecoveryPoint" + RecoveryPointSyncTypePerVMRecoveryPoint RecoveryPointSyncType = "PerVmRecoveryPoint" +) + +func PossibleValuesForRecoveryPointSyncType() []string { + return []string{ + string(RecoveryPointSyncTypeMultiVMSyncRecoveryPoint), + string(RecoveryPointSyncTypePerVMRecoveryPoint), + } +} + +func parseRecoveryPointSyncType(input string) (*RecoveryPointSyncType, error) { + vals := map[string]RecoveryPointSyncType{ + "multivmsyncrecoverypoint": RecoveryPointSyncTypeMultiVMSyncRecoveryPoint, + "pervmrecoverypoint": RecoveryPointSyncTypePerVMRecoveryPoint, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointSyncType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_recoverypoint.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_recoverypoint.go new file mode 100644 index 00000000000..976806a26b6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_recoverypoint.go @@ -0,0 +1,179 @@ +package recoverypoints + +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 + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationProtectedItemName string + RecoveryPointName string +} + +// NewRecoveryPointID returns a new RecoveryPointId struct +func NewRecoveryPointID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectedItemName string, recoveryPointName string) RecoveryPointId { + return RecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationProtectedItemName: replicationProtectedItemName, + RecoveryPointName: recoveryPointName, + } +} + +// 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointName, ok = parsed.Parsed["recoveryPointName"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := RecoveryPointId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + if id.RecoveryPointName, ok = parsed.Parsed["recoveryPointName"]; !ok { + return nil, fmt.Errorf("the segment 'recoveryPointName' was not found in the resource id %q", input) + } + + return &id, 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.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectedItems/%s/recoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectedItemName, id.RecoveryPointName) +} + +// 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationProtectedItems", "replicationProtectedItems", "replicationProtectedItems"), + resourceids.UserSpecifiedSegment("replicationProtectedItemName", "replicationProtectedItemValue"), + resourceids.StaticSegment("staticRecoveryPoints", "recoveryPoints", "recoveryPoints"), + resourceids.UserSpecifiedSegment("recoveryPointName", "recoveryPointValue"), + } +} + +// 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("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Protected Item Name: %q", id.ReplicationProtectedItemName), + fmt.Sprintf("Recovery Point Name: %q", id.RecoveryPointName), + } + return fmt.Sprintf("Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_recoverypoint_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_recoverypoint_test.go new file mode 100644 index 00000000000..0b409d2d420 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_recoverypoint_test.go @@ -0,0 +1,462 @@ +package recoverypoints + +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", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue", "recoveryPointValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationProtectedItemName != "replicationProtectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectedItemName'", id.ReplicationProtectedItemName, "replicationProtectedItemValue") + } + + if id.RecoveryPointName != "recoveryPointValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecoveryPointName'", id.RecoveryPointName, "recoveryPointValue") + } +} + +func TestFormatRecoveryPointID(t *testing.T) { + actual := NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue", "recoveryPointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/recoveryPoints/recoveryPointValue" + 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/recoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/recoveryPoints/recoveryPointValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + RecoveryPointName: "recoveryPointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/recoveryPoints/recoveryPointValue/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + if actual.RecoveryPointName != v.Expected.RecoveryPointName { + t.Fatalf("Expected %q but got %q for RecoveryPointName", v.Expected.RecoveryPointName, actual.RecoveryPointName) + } + + } +} + +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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/recoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe/rEcOvErYpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/recoveryPoints/recoveryPointValue", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + RecoveryPointName: "recoveryPointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/recoveryPoints/recoveryPointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe/rEcOvErYpOiNtS/rEcOvErYpOiNtVaLuE", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationProtectedItemName: "rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + RecoveryPointName: "rEcOvErYpOiNtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe/rEcOvErYpOiNtS/rEcOvErYpOiNtVaLuE/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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + if actual.RecoveryPointName != v.Expected.RecoveryPointName { + t.Fatalf("Expected %q but got %q for RecoveryPointName", v.Expected.RecoveryPointName, actual.RecoveryPointName) + } + + } +} + +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/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_replicationprotecteditem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_replicationprotecteditem.go new file mode 100644 index 00000000000..296f157f2d0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_replicationprotecteditem.go @@ -0,0 +1,166 @@ +package recoverypoints + +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 = ReplicationProtectedItemId{} + +// ReplicationProtectedItemId is a struct representing the Resource ID for a Replication Protected Item +type ReplicationProtectedItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationProtectedItemName string +} + +// NewReplicationProtectedItemID returns a new ReplicationProtectedItemId struct +func NewReplicationProtectedItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectedItemName string) ReplicationProtectedItemId { + return ReplicationProtectedItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationProtectedItemName: replicationProtectedItemName, + } +} + +// ParseReplicationProtectedItemID parses 'input' into a ReplicationProtectedItemId +func ParseReplicationProtectedItemID(input string) (*ReplicationProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectedItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectedItemIDInsensitively parses 'input' case-insensitively into a ReplicationProtectedItemId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectedItemIDInsensitively(input string) (*ReplicationProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectedItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectedItemID checks that 'input' can be parsed as a Replication Protected Item ID +func ValidateReplicationProtectedItemID(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 := ParseReplicationProtectedItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protected Item ID +func (id ReplicationProtectedItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectedItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectedItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protected Item ID +func (id ReplicationProtectedItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationProtectedItems", "replicationProtectedItems", "replicationProtectedItems"), + resourceids.UserSpecifiedSegment("replicationProtectedItemName", "replicationProtectedItemValue"), + } +} + +// String returns a human-readable description of this Replication Protected Item ID +func (id ReplicationProtectedItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Protected Item Name: %q", id.ReplicationProtectedItemName), + } + return fmt.Sprintf("Replication Protected Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_replicationprotecteditem_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_replicationprotecteditem_test.go new file mode 100644 index 00000000000..c99a88c2210 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/id_replicationprotecteditem_test.go @@ -0,0 +1,417 @@ +package recoverypoints + +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 = ReplicationProtectedItemId{} + +func TestNewReplicationProtectedItemID(t *testing.T) { + id := NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationProtectedItemName != "replicationProtectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectedItemName'", id.ReplicationProtectedItemName, "replicationProtectedItemValue") + } +} + +func TestFormatReplicationProtectedItemID(t *testing.T) { + actual := NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectedItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectedItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + } +} + +func TestParseReplicationProtectedItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationProtectedItemName: "rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectedItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + } +} + +func TestSegmentsForReplicationProtectedItemId(t *testing.T) { + segments := ReplicationProtectedItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectedItemId 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/recoveryservicessiterecovery/2023-01-01/recoverypoints/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/method_get_autorest.go new file mode 100644 index 00000000000..572dedb1e03 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/method_get_autorest.go @@ -0,0 +1,68 @@ +package recoverypoints + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *RecoveryPoint +} + +// Get ... +func (c RecoveryPointsClient) Get(ctx context.Context, id RecoveryPointId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c RecoveryPointsClient) preparerForGet(ctx context.Context, id RecoveryPointId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c RecoveryPointsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/method_listbyreplicationprotecteditems_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/method_listbyreplicationprotecteditems_autorest.go new file mode 100644 index 00000000000..b62cd07b4b5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/method_listbyreplicationprotecteditems_autorest.go @@ -0,0 +1,186 @@ +package recoverypoints + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationProtectedItemsOperationResponse struct { + HttpResponse *http.Response + Model *[]RecoveryPoint + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectedItemsOperationResponse, error) +} + +type ListByReplicationProtectedItemsCompleteResult struct { + Items []RecoveryPoint +} + +func (r ListByReplicationProtectedItemsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationProtectedItemsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectedItemsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationProtectedItems ... +func (c RecoveryPointsClient) ListByReplicationProtectedItems(ctx context.Context, id ReplicationProtectedItemId) (resp ListByReplicationProtectedItemsOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectedItems(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "ListByReplicationProtectedItems", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "ListByReplicationProtectedItems", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationProtectedItems(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "ListByReplicationProtectedItems", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationProtectedItems prepares the ListByReplicationProtectedItems request. +func (c RecoveryPointsClient) preparerForListByReplicationProtectedItems(ctx context.Context, id ReplicationProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/recoveryPoints", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationProtectedItemsWithNextLink prepares the ListByReplicationProtectedItems request with the given nextLink token. +func (c RecoveryPointsClient) preparerForListByReplicationProtectedItemsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationProtectedItems handles the response to the ListByReplicationProtectedItems request. The method always +// closes the http.Response Body. +func (c RecoveryPointsClient) responderForListByReplicationProtectedItems(resp *http.Response) (result ListByReplicationProtectedItemsOperationResponse, err error) { + type page struct { + Values []RecoveryPoint `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationProtectedItemsOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectedItemsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "ListByReplicationProtectedItems", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "ListByReplicationProtectedItems", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationProtectedItems(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "recoverypoints.RecoveryPointsClient", "ListByReplicationProtectedItems", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationProtectedItemsComplete retrieves all of the results into a single object +func (c RecoveryPointsClient) ListByReplicationProtectedItemsComplete(ctx context.Context, id ReplicationProtectedItemId) (ListByReplicationProtectedItemsCompleteResult, error) { + return c.ListByReplicationProtectedItemsCompleteMatchingPredicate(ctx, id, RecoveryPointOperationPredicate{}) +} + +// ListByReplicationProtectedItemsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c RecoveryPointsClient) ListByReplicationProtectedItemsCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectedItemId, predicate RecoveryPointOperationPredicate) (resp ListByReplicationProtectedItemsCompleteResult, err error) { + items := make([]RecoveryPoint, 0) + + page, err := c.ListByReplicationProtectedItems(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationProtectedItemsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_a2arecoverypointdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_a2arecoverypointdetails.go new file mode 100644 index 00000000000..759b8fbf2b4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_a2arecoverypointdetails.go @@ -0,0 +1,42 @@ +package recoverypoints + +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 _ ProviderSpecificRecoveryPointDetails = A2ARecoveryPointDetails{} + +type A2ARecoveryPointDetails struct { + Disks *[]string `json:"disks,omitempty"` + RecoveryPointSyncType *RecoveryPointSyncType `json:"recoveryPointSyncType,omitempty"` + + // Fields inherited from ProviderSpecificRecoveryPointDetails +} + +var _ json.Marshaler = A2ARecoveryPointDetails{} + +func (s A2ARecoveryPointDetails) MarshalJSON() ([]byte, error) { + type wrapper A2ARecoveryPointDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ARecoveryPointDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ARecoveryPointDetails: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ARecoveryPointDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_inmageazurev2recoverypointdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_inmageazurev2recoverypointdetails.go new file mode 100644 index 00000000000..c4f33dd48fc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_inmageazurev2recoverypointdetails.go @@ -0,0 +1,41 @@ +package recoverypoints + +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 _ ProviderSpecificRecoveryPointDetails = InMageAzureV2RecoveryPointDetails{} + +type InMageAzureV2RecoveryPointDetails struct { + IsMultiVMSyncPoint *string `json:"isMultiVmSyncPoint,omitempty"` + + // Fields inherited from ProviderSpecificRecoveryPointDetails +} + +var _ json.Marshaler = InMageAzureV2RecoveryPointDetails{} + +func (s InMageAzureV2RecoveryPointDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2RecoveryPointDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2RecoveryPointDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2RecoveryPointDetails: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2RecoveryPointDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_inmagercmrecoverypointdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_inmagercmrecoverypointdetails.go new file mode 100644 index 00000000000..3dfe05eb012 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_inmagercmrecoverypointdetails.go @@ -0,0 +1,41 @@ +package recoverypoints + +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 _ ProviderSpecificRecoveryPointDetails = InMageRcmRecoveryPointDetails{} + +type InMageRcmRecoveryPointDetails struct { + IsMultiVMSyncPoint *string `json:"isMultiVmSyncPoint,omitempty"` + + // Fields inherited from ProviderSpecificRecoveryPointDetails +} + +var _ json.Marshaler = InMageRcmRecoveryPointDetails{} + +func (s InMageRcmRecoveryPointDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmRecoveryPointDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmRecoveryPointDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmRecoveryPointDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmRecoveryPointDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_providerspecificrecoverypointdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_providerspecificrecoverypointdetails.go new file mode 100644 index 00000000000..be5d4db1b4f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_providerspecificrecoverypointdetails.go @@ -0,0 +1,64 @@ +package recoverypoints + +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 ProviderSpecificRecoveryPointDetails interface { +} + +func unmarshalProviderSpecificRecoveryPointDetailsImplementation(input []byte) (ProviderSpecificRecoveryPointDetails, 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 ProviderSpecificRecoveryPointDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2ARecoveryPointDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ARecoveryPointDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2RecoveryPointDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2RecoveryPointDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmRecoveryPointDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmRecoveryPointDetails: %+v", err) + } + return out, nil + } + + type RawProviderSpecificRecoveryPointDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProviderSpecificRecoveryPointDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_recoverypoint.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_recoverypoint.go new file mode 100644 index 00000000000..cd0df01a0a3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_recoverypoint.go @@ -0,0 +1,12 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPoint struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecoveryPointProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_recoverypointproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_recoverypointproperties.go new file mode 100644 index 00000000000..69ba9472ece --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/model_recoverypointproperties.go @@ -0,0 +1,57 @@ +package recoverypoints + +import ( + "encoding/json" + "fmt" + "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 RecoveryPointProperties struct { + ProviderSpecificDetails ProviderSpecificRecoveryPointDetails `json:"providerSpecificDetails"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` +} + +func (o *RecoveryPointProperties) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointProperties) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} + +var _ json.Unmarshaler = &RecoveryPointProperties{} + +func (s *RecoveryPointProperties) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPointProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPointProperties: %+v", err) + } + + s.RecoveryPointTime = decoded.RecoveryPointTime + s.RecoveryPointType = decoded.RecoveryPointType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPointProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalProviderSpecificRecoveryPointDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'RecoveryPointProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/predicates.go new file mode 100644 index 00000000000..1d3e414e2cc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/predicates.go @@ -0,0 +1,32 @@ +package recoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPointOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RecoveryPointOperationPredicate) Matches(input RecoveryPoint) bool { + + 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/recoveryservicessiterecovery/2023-01-01/recoverypoints/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/version.go new file mode 100644 index 00000000000..3c9834e31e2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/recoverypoints/version.go @@ -0,0 +1,12 @@ +package recoverypoints + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverypoints/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/README.md new file mode 100644 index 00000000000..ffcce093933 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings` Documentation + +The `replicationalertsettings` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationalertsettings" +``` + + +### Client Initialization + +```go +client := replicationalertsettings.NewReplicationAlertSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationAlertSettingsClient.Create` + +```go +ctx := context.TODO() +id := replicationalertsettings.NewReplicationAlertSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationAlertSettingValue") + +payload := replicationalertsettings.ConfigureAlertRequest{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ReplicationAlertSettingsClient.Get` + +```go +ctx := context.TODO() +id := replicationalertsettings.NewReplicationAlertSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationAlertSettingValue") + +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: `ReplicationAlertSettingsClient.List` + +```go +ctx := context.TODO() +id := replicationalertsettings.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/client.go new file mode 100644 index 00000000000..97deb986214 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/client.go @@ -0,0 +1,18 @@ +package replicationalertsettings + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationAlertSettingsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationAlertSettingsClientWithBaseURI(endpoint string) ReplicationAlertSettingsClient { + return ReplicationAlertSettingsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_replicationalertsetting.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_replicationalertsetting.go new file mode 100644 index 00000000000..648d38f5df5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_replicationalertsetting.go @@ -0,0 +1,140 @@ +package replicationalertsettings + +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 = ReplicationAlertSettingId{} + +// ReplicationAlertSettingId is a struct representing the Resource ID for a Replication Alert Setting +type ReplicationAlertSettingId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationAlertSettingName string +} + +// NewReplicationAlertSettingID returns a new ReplicationAlertSettingId struct +func NewReplicationAlertSettingID(subscriptionId string, resourceGroupName string, vaultName string, replicationAlertSettingName string) ReplicationAlertSettingId { + return ReplicationAlertSettingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationAlertSettingName: replicationAlertSettingName, + } +} + +// ParseReplicationAlertSettingID parses 'input' into a ReplicationAlertSettingId +func ParseReplicationAlertSettingID(input string) (*ReplicationAlertSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationAlertSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationAlertSettingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationAlertSettingName, ok = parsed.Parsed["replicationAlertSettingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationAlertSettingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationAlertSettingIDInsensitively parses 'input' case-insensitively into a ReplicationAlertSettingId +// note: this method should only be used for API response data and not user input +func ParseReplicationAlertSettingIDInsensitively(input string) (*ReplicationAlertSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationAlertSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationAlertSettingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationAlertSettingName, ok = parsed.Parsed["replicationAlertSettingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationAlertSettingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationAlertSettingID checks that 'input' can be parsed as a Replication Alert Setting ID +func ValidateReplicationAlertSettingID(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 := ParseReplicationAlertSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Alert Setting ID +func (id ReplicationAlertSettingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationAlertSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationAlertSettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Alert Setting ID +func (id ReplicationAlertSettingId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationAlertSettings", "replicationAlertSettings", "replicationAlertSettings"), + resourceids.UserSpecifiedSegment("replicationAlertSettingName", "replicationAlertSettingValue"), + } +} + +// String returns a human-readable description of this Replication Alert Setting ID +func (id ReplicationAlertSettingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Alert Setting Name: %q", id.ReplicationAlertSettingName), + } + return fmt.Sprintf("Replication Alert Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_replicationalertsetting_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_replicationalertsetting_test.go new file mode 100644 index 00000000000..e0deeb549b9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_replicationalertsetting_test.go @@ -0,0 +1,327 @@ +package replicationalertsettings + +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 = ReplicationAlertSettingId{} + +func TestNewReplicationAlertSettingID(t *testing.T) { + id := NewReplicationAlertSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationAlertSettingValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationAlertSettingName != "replicationAlertSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationAlertSettingName'", id.ReplicationAlertSettingName, "replicationAlertSettingValue") + } +} + +func TestFormatReplicationAlertSettingID(t *testing.T) { + actual := NewReplicationAlertSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationAlertSettingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationAlertSettings/replicationAlertSettingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationAlertSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationAlertSettingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationAlertSettings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationAlertSettings/replicationAlertSettingValue", + Expected: &ReplicationAlertSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationAlertSettingName: "replicationAlertSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationAlertSettings/replicationAlertSettingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationAlertSettingID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationAlertSettingName != v.Expected.ReplicationAlertSettingName { + t.Fatalf("Expected %q but got %q for ReplicationAlertSettingName", v.Expected.ReplicationAlertSettingName, actual.ReplicationAlertSettingName) + } + + } +} + +func TestParseReplicationAlertSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationAlertSettingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationAlertSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnAlErTsEtTiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationAlertSettings/replicationAlertSettingValue", + Expected: &ReplicationAlertSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationAlertSettingName: "replicationAlertSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationAlertSettings/replicationAlertSettingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnAlErTsEtTiNgS/rEpLiCaTiOnAlErTsEtTiNgVaLuE", + Expected: &ReplicationAlertSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationAlertSettingName: "rEpLiCaTiOnAlErTsEtTiNgVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnAlErTsEtTiNgS/rEpLiCaTiOnAlErTsEtTiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationAlertSettingIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationAlertSettingName != v.Expected.ReplicationAlertSettingName { + t.Fatalf("Expected %q but got %q for ReplicationAlertSettingName", v.Expected.ReplicationAlertSettingName, actual.ReplicationAlertSettingName) + } + + } +} + +func TestSegmentsForReplicationAlertSettingId(t *testing.T) { + segments := ReplicationAlertSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationAlertSettingId 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/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_vault.go new file mode 100644 index 00000000000..aa8888d2132 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_vault.go @@ -0,0 +1,127 @@ +package replicationalertsettings + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_vault_test.go new file mode 100644 index 00000000000..cba30661bd3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationalertsettings + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_create_autorest.go new file mode 100644 index 00000000000..54e08d9f12c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_create_autorest.go @@ -0,0 +1,69 @@ +package replicationalertsettings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + Model *Alert +} + +// Create ... +func (c ReplicationAlertSettingsClient) Create(ctx context.Context, id ReplicationAlertSettingId, input ConfigureAlertRequest) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "Create", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "Create", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreate prepares the Create request. +func (c ReplicationAlertSettingsClient) preparerForCreate(ctx context.Context, id ReplicationAlertSettingId, input ConfigureAlertRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreate handles the response to the Create request. The method always +// closes the http.Response Body. +func (c ReplicationAlertSettingsClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_get_autorest.go new file mode 100644 index 00000000000..09a1adc368a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationalertsettings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Alert +} + +// Get ... +func (c ReplicationAlertSettingsClient) Get(ctx context.Context, id ReplicationAlertSettingId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationAlertSettingsClient) preparerForGet(ctx context.Context, id ReplicationAlertSettingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationAlertSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_list_autorest.go new file mode 100644 index 00000000000..e2789fead82 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationalertsettings + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Alert + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Alert +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationAlertSettingsClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationAlertSettingsClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationAlertSettings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationAlertSettingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationAlertSettingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Alert `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationalertsettings.ReplicationAlertSettingsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationAlertSettingsClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationAlertSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate AlertOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Alert, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_alert.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_alert.go new file mode 100644 index 00000000000..003e317d3b9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_alert.go @@ -0,0 +1,12 @@ +package replicationalertsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Alert struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AlertProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_alertproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_alertproperties.go new file mode 100644 index 00000000000..470729facab --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_alertproperties.go @@ -0,0 +1,10 @@ +package replicationalertsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertProperties struct { + CustomEmailAddresses *[]string `json:"customEmailAddresses,omitempty"` + Locale *string `json:"locale,omitempty"` + SendToOwners *string `json:"sendToOwners,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_configurealertrequest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_configurealertrequest.go new file mode 100644 index 00000000000..b914ebe04a9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_configurealertrequest.go @@ -0,0 +1,8 @@ +package replicationalertsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigureAlertRequest struct { + Properties *ConfigureAlertRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_configurealertrequestproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_configurealertrequestproperties.go new file mode 100644 index 00000000000..d5a6752d183 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/model_configurealertrequestproperties.go @@ -0,0 +1,10 @@ +package replicationalertsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigureAlertRequestProperties struct { + CustomEmailAddresses *[]string `json:"customEmailAddresses,omitempty"` + Locale *string `json:"locale,omitempty"` + SendToOwners *string `json:"sendToOwners,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/predicates.go new file mode 100644 index 00000000000..532de0d806f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/predicates.go @@ -0,0 +1,32 @@ +package replicationalertsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p AlertOperationPredicate) Matches(input Alert) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/version.go new file mode 100644 index 00000000000..e588d334de1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationalertsettings/version.go @@ -0,0 +1,12 @@ +package replicationalertsettings + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationalertsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/README.md new file mode 100644 index 00000000000..579cc750af8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances` Documentation + +The `replicationappliances` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationappliances" +``` + + +### Client Initialization + +```go +client := replicationappliances.NewReplicationAppliancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationAppliancesClient.List` + +```go +ctx := context.TODO() +id := replicationappliances.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, replicationappliances.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, replicationappliances.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/client.go new file mode 100644 index 00000000000..8820655404e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/client.go @@ -0,0 +1,18 @@ +package replicationappliances + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationAppliancesClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationAppliancesClientWithBaseURI(endpoint string) ReplicationAppliancesClient { + return ReplicationAppliancesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/constants.go new file mode 100644 index 00000000000..9e999bfec64 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/constants.go @@ -0,0 +1,102 @@ +package replicationappliances + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} + +type ProtectionHealth string + +const ( + ProtectionHealthCritical ProtectionHealth = "Critical" + ProtectionHealthNone ProtectionHealth = "None" + ProtectionHealthNormal ProtectionHealth = "Normal" + ProtectionHealthWarning ProtectionHealth = "Warning" +) + +func PossibleValuesForProtectionHealth() []string { + return []string{ + string(ProtectionHealthCritical), + string(ProtectionHealthNone), + string(ProtectionHealthNormal), + string(ProtectionHealthWarning), + } +} + +func parseProtectionHealth(input string) (*ProtectionHealth, error) { + vals := map[string]ProtectionHealth{ + "critical": ProtectionHealthCritical, + "none": ProtectionHealthNone, + "normal": ProtectionHealthNormal, + "warning": ProtectionHealthWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionHealth(input) + return &out, nil +} + +type RcmComponentStatus string + +const ( + RcmComponentStatusCritical RcmComponentStatus = "Critical" + RcmComponentStatusHealthy RcmComponentStatus = "Healthy" + RcmComponentStatusUnknown RcmComponentStatus = "Unknown" + RcmComponentStatusWarning RcmComponentStatus = "Warning" +) + +func PossibleValuesForRcmComponentStatus() []string { + return []string{ + string(RcmComponentStatusCritical), + string(RcmComponentStatusHealthy), + string(RcmComponentStatusUnknown), + string(RcmComponentStatusWarning), + } +} + +func parseRcmComponentStatus(input string) (*RcmComponentStatus, error) { + vals := map[string]RcmComponentStatus{ + "critical": RcmComponentStatusCritical, + "healthy": RcmComponentStatusHealthy, + "unknown": RcmComponentStatusUnknown, + "warning": RcmComponentStatusWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RcmComponentStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/id_vault.go new file mode 100644 index 00000000000..91024fef906 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/id_vault.go @@ -0,0 +1,127 @@ +package replicationappliances + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/id_vault_test.go new file mode 100644 index 00000000000..8caa575bca7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationappliances + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationappliances/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/method_list_autorest.go new file mode 100644 index 00000000000..2154e84afa5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/method_list_autorest.go @@ -0,0 +1,215 @@ +package replicationappliances + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ReplicationAppliance + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ReplicationAppliance +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c ReplicationAppliancesClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationappliances.ReplicationAppliancesClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationappliances.ReplicationAppliancesClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationappliances.ReplicationAppliancesClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationAppliancesClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationAppliances", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationAppliancesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationAppliancesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ReplicationAppliance `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationappliances.ReplicationAppliancesClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationappliances.ReplicationAppliancesClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationappliances.ReplicationAppliancesClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationAppliancesClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ReplicationApplianceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationAppliancesClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate ReplicationApplianceOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ReplicationAppliance, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_appliancespecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_appliancespecificdetails.go new file mode 100644 index 00000000000..928bce8f49d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_appliancespecificdetails.go @@ -0,0 +1,48 @@ +package replicationappliances + +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 ApplianceSpecificDetails interface { +} + +func unmarshalApplianceSpecificDetailsImplementation(input []byte) (ApplianceSpecificDetails, 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 ApplianceSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmApplianceSpecificDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmApplianceSpecificDetails: %+v", err) + } + return out, nil + } + + type RawApplianceSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawApplianceSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_dradetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_dradetails.go new file mode 100644 index 00000000000..fcde153537f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_dradetails.go @@ -0,0 +1,34 @@ +package replicationappliances + +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 DraDetails struct { + BiosId *string `json:"biosId,omitempty"` + ForwardProtectedItemCount *int64 `json:"forwardProtectedItemCount,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + ReverseProtectedItemCount *int64 `json:"reverseProtectedItemCount,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *DraDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *DraDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_healtherror.go new file mode 100644 index 00000000000..1780f919219 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationappliances + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmappliancedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmappliancedetails.go new file mode 100644 index 00000000000..df2d5e14881 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmappliancedetails.go @@ -0,0 +1,18 @@ +package replicationappliances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmApplianceDetails struct { + Dra *DraDetails `json:"dra,omitempty"` + FabricArmId *string `json:"fabricArmId,omitempty"` + Id *string `json:"id,omitempty"` + MarsAgent *MarsAgentDetails `json:"marsAgent,omitempty"` + Name *string `json:"name,omitempty"` + ProcessServer *ProcessServerDetails `json:"processServer,omitempty"` + PushInstaller *PushInstallerDetails `json:"pushInstaller,omitempty"` + RcmProxy *RcmProxyDetails `json:"rcmProxy,omitempty"` + ReplicationAgent *ReplicationAgentDetails `json:"replicationAgent,omitempty"` + ReprotectAgent *ReprotectAgentDetails `json:"reprotectAgent,omitempty"` + SwitchProviderBlockingErrorDetails *[]InMageRcmFabricSwitchProviderBlockingErrorDetails `json:"switchProviderBlockingErrorDetails,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmappliancespecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmappliancespecificdetails.go new file mode 100644 index 00000000000..063308d1671 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmappliancespecificdetails.go @@ -0,0 +1,41 @@ +package replicationappliances + +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 _ ApplianceSpecificDetails = InMageRcmApplianceSpecificDetails{} + +type InMageRcmApplianceSpecificDetails struct { + Appliances *[]InMageRcmApplianceDetails `json:"appliances,omitempty"` + + // Fields inherited from ApplianceSpecificDetails +} + +var _ json.Marshaler = InMageRcmApplianceSpecificDetails{} + +func (s InMageRcmApplianceSpecificDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmApplianceSpecificDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmApplianceSpecificDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmApplianceSpecificDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmApplianceSpecificDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmfabricswitchproviderblockingerrordetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmfabricswitchproviderblockingerrordetails.go new file mode 100644 index 00000000000..84a5830cb6b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_inmagercmfabricswitchproviderblockingerrordetails.go @@ -0,0 +1,13 @@ +package replicationappliances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmFabricSwitchProviderBlockingErrorDetails struct { + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorMessageParameters *map[string]string `json:"errorMessageParameters,omitempty"` + ErrorTags *map[string]string `json:"errorTags,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_innerhealtherror.go new file mode 100644 index 00000000000..76f31c711be --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationappliances + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_marsagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_marsagentdetails.go new file mode 100644 index 00000000000..edf0158b990 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_marsagentdetails.go @@ -0,0 +1,34 @@ +package replicationappliances + +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 MarsAgentDetails struct { + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *MarsAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *MarsAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_processserverdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_processserverdetails.go new file mode 100644 index 00000000000..43de3ca2697 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_processserverdetails.go @@ -0,0 +1,54 @@ +package replicationappliances + +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 ProcessServerDetails struct { + AvailableMemoryInBytes *int64 `json:"availableMemoryInBytes,omitempty"` + AvailableSpaceInBytes *int64 `json:"availableSpaceInBytes,omitempty"` + BiosId *string `json:"biosId,omitempty"` + DiskUsageStatus *RcmComponentStatus `json:"diskUsageStatus,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + FreeSpacePercentage *float64 `json:"freeSpacePercentage,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + HistoricHealth *ProtectionHealth `json:"historicHealth,omitempty"` + IPAddresses *[]string `json:"ipAddresses,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + MemoryUsagePercentage *float64 `json:"memoryUsagePercentage,omitempty"` + MemoryUsageStatus *RcmComponentStatus `json:"memoryUsageStatus,omitempty"` + Name *string `json:"name,omitempty"` + ProcessorUsagePercentage *float64 `json:"processorUsagePercentage,omitempty"` + ProcessorUsageStatus *RcmComponentStatus `json:"processorUsageStatus,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + SystemLoad *int64 `json:"systemLoad,omitempty"` + SystemLoadStatus *RcmComponentStatus `json:"systemLoadStatus,omitempty"` + ThroughputInBytes *int64 `json:"throughputInBytes,omitempty"` + ThroughputStatus *RcmComponentStatus `json:"throughputStatus,omitempty"` + ThroughputUploadPendingDataInBytes *int64 `json:"throughputUploadPendingDataInBytes,omitempty"` + TotalMemoryInBytes *int64 `json:"totalMemoryInBytes,omitempty"` + TotalSpaceInBytes *int64 `json:"totalSpaceInBytes,omitempty"` + UsedMemoryInBytes *int64 `json:"usedMemoryInBytes,omitempty"` + UsedSpaceInBytes *int64 `json:"usedSpaceInBytes,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ProcessServerDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProcessServerDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_pushinstallerdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_pushinstallerdetails.go new file mode 100644 index 00000000000..485a5173ab5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_pushinstallerdetails.go @@ -0,0 +1,34 @@ +package replicationappliances + +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 PushInstallerDetails struct { + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *PushInstallerDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *PushInstallerDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_rcmproxydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_rcmproxydetails.go new file mode 100644 index 00000000000..1d29ef4a653 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_rcmproxydetails.go @@ -0,0 +1,35 @@ +package replicationappliances + +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 RcmProxyDetails struct { + BiosId *string `json:"biosId,omitempty"` + ClientAuthenticationType *string `json:"clientAuthenticationType,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *RcmProxyDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *RcmProxyDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationagentdetails.go new file mode 100644 index 00000000000..5147a2d9142 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationagentdetails.go @@ -0,0 +1,34 @@ +package replicationappliances + +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 ReplicationAgentDetails struct { + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ReplicationAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReplicationAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationappliance.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationappliance.go new file mode 100644 index 00000000000..65955cd695d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationappliance.go @@ -0,0 +1,8 @@ +package replicationappliances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationAppliance struct { + Properties *ReplicationApplianceProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationapplianceproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationapplianceproperties.go new file mode 100644 index 00000000000..d814f948d89 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_replicationapplianceproperties.go @@ -0,0 +1,32 @@ +package replicationappliances + +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 ReplicationApplianceProperties struct { + ProviderSpecificDetails ApplianceSpecificDetails `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &ReplicationApplianceProperties{} + +func (s *ReplicationApplianceProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ReplicationApplianceProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalApplianceSpecificDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ReplicationApplianceProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_reprotectagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_reprotectagentdetails.go new file mode 100644 index 00000000000..da40fca482c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/model_reprotectagentdetails.go @@ -0,0 +1,50 @@ +package replicationappliances + +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 ReprotectAgentDetails struct { + AccessibleDatastores *[]string `json:"accessibleDatastores,omitempty"` + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastDiscoveryInUtc *string `json:"lastDiscoveryInUtc,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + VcenterId *string `json:"vcenterId,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ReprotectAgentDetails) GetLastDiscoveryInUtcAsTime() (*time.Time, error) { + if o.LastDiscoveryInUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastDiscoveryInUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReprotectAgentDetails) SetLastDiscoveryInUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastDiscoveryInUtc = &formatted +} + +func (o *ReprotectAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReprotectAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/predicates.go new file mode 100644 index 00000000000..58258537c8d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/predicates.go @@ -0,0 +1,12 @@ +package replicationappliances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationApplianceOperationPredicate struct { +} + +func (p ReplicationApplianceOperationPredicate) Matches(input ReplicationAppliance) bool { + + return true +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/version.go new file mode 100644 index 00000000000..3d61dad810b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationappliances/version.go @@ -0,0 +1,12 @@ +package replicationappliances + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationappliances/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/README.md new file mode 100644 index 00000000000..a58fba3cdc3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults` Documentation + +The `replicationeligibilityresults` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults" +``` + + +### Client Initialization + +```go +client := replicationeligibilityresults.NewReplicationEligibilityResultsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationEligibilityResultsClient.Get` + +```go +ctx := context.TODO() +id := replicationeligibilityresults.NewVirtualMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualMachineValue") + +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: `ReplicationEligibilityResultsClient.List` + +```go +ctx := context.TODO() +id := replicationeligibilityresults.NewVirtualMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualMachineValue") + +read, err := client.List(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/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/client.go new file mode 100644 index 00000000000..1e550b5a8b9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/client.go @@ -0,0 +1,18 @@ +package replicationeligibilityresults + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationEligibilityResultsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationEligibilityResultsClientWithBaseURI(endpoint string) ReplicationEligibilityResultsClient { + return ReplicationEligibilityResultsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/id_virtualmachine.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/id_virtualmachine.go new file mode 100644 index 00000000000..75404196f46 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/id_virtualmachine.go @@ -0,0 +1,127 @@ +package replicationeligibilityresults + +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 = VirtualMachineId{} + +// VirtualMachineId is a struct representing the Resource ID for a Virtual Machine +type VirtualMachineId struct { + SubscriptionId string + ResourceGroupName string + VirtualMachineName string +} + +// NewVirtualMachineID returns a new VirtualMachineId struct +func NewVirtualMachineID(subscriptionId string, resourceGroupName string, virtualMachineName string) VirtualMachineId { + return VirtualMachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VirtualMachineName: virtualMachineName, + } +} + +// ParseVirtualMachineID parses 'input' into a VirtualMachineId +func ParseVirtualMachineID(input string) (*VirtualMachineId, error) { + parser := resourceids.NewParserFromResourceIdType(VirtualMachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VirtualMachineId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VirtualMachineName, ok = parsed.Parsed["virtualMachineName"]; !ok { + return nil, fmt.Errorf("the segment 'virtualMachineName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVirtualMachineIDInsensitively parses 'input' case-insensitively into a VirtualMachineId +// note: this method should only be used for API response data and not user input +func ParseVirtualMachineIDInsensitively(input string) (*VirtualMachineId, error) { + parser := resourceids.NewParserFromResourceIdType(VirtualMachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VirtualMachineId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VirtualMachineName, ok = parsed.Parsed["virtualMachineName"]; !ok { + return nil, fmt.Errorf("the segment 'virtualMachineName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVirtualMachineID checks that 'input' can be parsed as a Virtual Machine ID +func ValidateVirtualMachineID(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 := ParseVirtualMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Virtual Machine ID +func (id VirtualMachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VirtualMachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Virtual Machine ID +func (id VirtualMachineId) 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("staticMicrosoftCompute", "Microsoft.Compute", "Microsoft.Compute"), + resourceids.StaticSegment("staticVirtualMachines", "virtualMachines", "virtualMachines"), + resourceids.UserSpecifiedSegment("virtualMachineName", "virtualMachineValue"), + } +} + +// String returns a human-readable description of this Virtual Machine ID +func (id VirtualMachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Virtual Machine Name: %q", id.VirtualMachineName), + } + return fmt.Sprintf("Virtual Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/id_virtualmachine_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/id_virtualmachine_test.go new file mode 100644 index 00000000000..bca7c179191 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/id_virtualmachine_test.go @@ -0,0 +1,282 @@ +package replicationeligibilityresults + +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 = VirtualMachineId{} + +func TestNewVirtualMachineID(t *testing.T) { + id := NewVirtualMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualMachineValue") + + 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.VirtualMachineName != "virtualMachineValue" { + t.Fatalf("Expected %q but got %q for Segment 'VirtualMachineName'", id.VirtualMachineName, "virtualMachineValue") + } +} + +func TestFormatVirtualMachineID(t *testing.T) { + actual := NewVirtualMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualMachineValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines/virtualMachineValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVirtualMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualMachineId + }{ + { + // 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.Compute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines/virtualMachineValue", + Expected: &VirtualMachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VirtualMachineName: "virtualMachineValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines/virtualMachineValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualMachineID(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.VirtualMachineName != v.Expected.VirtualMachineName { + t.Fatalf("Expected %q but got %q for VirtualMachineName", v.Expected.VirtualMachineName, actual.VirtualMachineName) + } + + } +} + +func TestParseVirtualMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualMachineId + }{ + { + // 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.Compute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOmPuTe/vIrTuAlMaChInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines/virtualMachineValue", + Expected: &VirtualMachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VirtualMachineName: "virtualMachineValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines/virtualMachineValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOmPuTe/vIrTuAlMaChInEs/vIrTuAlMaChInEvAlUe", + Expected: &VirtualMachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VirtualMachineName: "vIrTuAlMaChInEvAlUe", + }, + }, + { + // 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.cOmPuTe/vIrTuAlMaChInEs/vIrTuAlMaChInEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualMachineIDInsensitively(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.VirtualMachineName != v.Expected.VirtualMachineName { + t.Fatalf("Expected %q but got %q for VirtualMachineName", v.Expected.VirtualMachineName, actual.VirtualMachineName) + } + + } +} + +func TestSegmentsForVirtualMachineId(t *testing.T) { + segments := VirtualMachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VirtualMachineId 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/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/method_get_autorest.go new file mode 100644 index 00000000000..4a0c75e2345 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/method_get_autorest.go @@ -0,0 +1,69 @@ +package replicationeligibilityresults + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ReplicationEligibilityResults +} + +// Get ... +func (c ReplicationEligibilityResultsClient) Get(ctx context.Context, id VirtualMachineId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationeligibilityresults.ReplicationEligibilityResultsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationeligibilityresults.ReplicationEligibilityResultsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationeligibilityresults.ReplicationEligibilityResultsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationEligibilityResultsClient) preparerForGet(ctx context.Context, id VirtualMachineId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.RecoveryServices/replicationEligibilityResults/default", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationEligibilityResultsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/method_list_autorest.go new file mode 100644 index 00000000000..0ea5220610e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/method_list_autorest.go @@ -0,0 +1,69 @@ +package replicationeligibilityresults + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *ReplicationEligibilityResultsCollection +} + +// List ... +func (c ReplicationEligibilityResultsClient) List(ctx context.Context, id VirtualMachineId) (result ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationeligibilityresults.ReplicationEligibilityResultsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationeligibilityresults.ReplicationEligibilityResultsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationeligibilityresults.ReplicationEligibilityResultsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForList prepares the List request. +func (c ReplicationEligibilityResultsClient) preparerForList(ctx context.Context, id VirtualMachineId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.RecoveryServices/replicationEligibilityResults", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationEligibilityResultsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresults.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresults.go new file mode 100644 index 00000000000..c14c19713c9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresults.go @@ -0,0 +1,11 @@ +package replicationeligibilityresults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationEligibilityResults struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ReplicationEligibilityResultsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultscollection.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultscollection.go new file mode 100644 index 00000000000..2dc729eb1ca --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultscollection.go @@ -0,0 +1,8 @@ +package replicationeligibilityresults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationEligibilityResultsCollection struct { + Value *[]ReplicationEligibilityResults `json:"value,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultserrorinfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultserrorinfo.go new file mode 100644 index 00000000000..a81d7856188 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultserrorinfo.go @@ -0,0 +1,12 @@ +package replicationeligibilityresults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationEligibilityResultsErrorInfo struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultsproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultsproperties.go new file mode 100644 index 00000000000..ebc67f22629 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/model_replicationeligibilityresultsproperties.go @@ -0,0 +1,9 @@ +package replicationeligibilityresults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationEligibilityResultsProperties struct { + ClientRequestId *string `json:"clientRequestId,omitempty"` + Errors *[]ReplicationEligibilityResultsErrorInfo `json:"errors,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/version.go new file mode 100644 index 00000000000..fd4a8440aa8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationeligibilityresults/version.go @@ -0,0 +1,12 @@ +package replicationeligibilityresults + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationeligibilityresults/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/README.md new file mode 100644 index 00000000000..422d2ed8913 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents` Documentation + +The `replicationevents` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationevents" +``` + + +### Client Initialization + +```go +client := replicationevents.NewReplicationEventsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationEventsClient.Get` + +```go +ctx := context.TODO() +id := replicationevents.NewReplicationEventID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationEventValue") + +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: `ReplicationEventsClient.List` + +```go +ctx := context.TODO() +id := replicationevents.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, replicationevents.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, replicationevents.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/client.go new file mode 100644 index 00000000000..a74054714f4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/client.go @@ -0,0 +1,18 @@ +package replicationevents + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationEventsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationEventsClientWithBaseURI(endpoint string) ReplicationEventsClient { + return ReplicationEventsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/constants.go new file mode 100644 index 00000000000..db482c5671e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/constants.go @@ -0,0 +1,34 @@ +package replicationevents + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_replicationevent.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_replicationevent.go new file mode 100644 index 00000000000..f4d2e32255c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_replicationevent.go @@ -0,0 +1,140 @@ +package replicationevents + +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 = ReplicationEventId{} + +// ReplicationEventId is a struct representing the Resource ID for a Replication Event +type ReplicationEventId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationEventName string +} + +// NewReplicationEventID returns a new ReplicationEventId struct +func NewReplicationEventID(subscriptionId string, resourceGroupName string, vaultName string, replicationEventName string) ReplicationEventId { + return ReplicationEventId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationEventName: replicationEventName, + } +} + +// ParseReplicationEventID parses 'input' into a ReplicationEventId +func ParseReplicationEventID(input string) (*ReplicationEventId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationEventId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationEventId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationEventName, ok = parsed.Parsed["replicationEventName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationEventName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationEventIDInsensitively parses 'input' case-insensitively into a ReplicationEventId +// note: this method should only be used for API response data and not user input +func ParseReplicationEventIDInsensitively(input string) (*ReplicationEventId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationEventId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationEventId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationEventName, ok = parsed.Parsed["replicationEventName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationEventName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationEventID checks that 'input' can be parsed as a Replication Event ID +func ValidateReplicationEventID(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 := ParseReplicationEventID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Event ID +func (id ReplicationEventId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationEvents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationEventName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Event ID +func (id ReplicationEventId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationEvents", "replicationEvents", "replicationEvents"), + resourceids.UserSpecifiedSegment("replicationEventName", "replicationEventValue"), + } +} + +// String returns a human-readable description of this Replication Event ID +func (id ReplicationEventId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Event Name: %q", id.ReplicationEventName), + } + return fmt.Sprintf("Replication Event (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_replicationevent_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_replicationevent_test.go new file mode 100644 index 00000000000..10bf226ee2b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_replicationevent_test.go @@ -0,0 +1,327 @@ +package replicationevents + +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 = ReplicationEventId{} + +func TestNewReplicationEventID(t *testing.T) { + id := NewReplicationEventID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationEventValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationEventName != "replicationEventValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationEventName'", id.ReplicationEventName, "replicationEventValue") + } +} + +func TestFormatReplicationEventID(t *testing.T) { + actual := NewReplicationEventID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationEventValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationEvents/replicationEventValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationEventID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationEventId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationEvents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationEvents/replicationEventValue", + Expected: &ReplicationEventId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationEventName: "replicationEventValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationEvents/replicationEventValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationEventID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationEventName != v.Expected.ReplicationEventName { + t.Fatalf("Expected %q but got %q for ReplicationEventName", v.Expected.ReplicationEventName, actual.ReplicationEventName) + } + + } +} + +func TestParseReplicationEventIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationEventId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationEvents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnEvEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationEvents/replicationEventValue", + Expected: &ReplicationEventId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationEventName: "replicationEventValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationEvents/replicationEventValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnEvEnTs/rEpLiCaTiOnEvEnTvAlUe", + Expected: &ReplicationEventId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationEventName: "rEpLiCaTiOnEvEnTvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnEvEnTs/rEpLiCaTiOnEvEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationEventIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationEventName != v.Expected.ReplicationEventName { + t.Fatalf("Expected %q but got %q for ReplicationEventName", v.Expected.ReplicationEventName, actual.ReplicationEventName) + } + + } +} + +func TestSegmentsForReplicationEventId(t *testing.T) { + segments := ReplicationEventId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationEventId 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/recoveryservicessiterecovery/2023-01-01/replicationevents/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_vault.go new file mode 100644 index 00000000000..e80c0c2c8c5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_vault.go @@ -0,0 +1,127 @@ +package replicationevents + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_vault_test.go new file mode 100644 index 00000000000..46c9ef84cd1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationevents + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationevents/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/method_get_autorest.go new file mode 100644 index 00000000000..2d526890c17 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationevents + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Event +} + +// Get ... +func (c ReplicationEventsClient) Get(ctx context.Context, id ReplicationEventId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationEventsClient) preparerForGet(ctx context.Context, id ReplicationEventId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationEventsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/method_list_autorest.go new file mode 100644 index 00000000000..acbac69a04a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/method_list_autorest.go @@ -0,0 +1,215 @@ +package replicationevents + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Event + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Event +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c ReplicationEventsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationEventsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationEvents", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationEventsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationEventsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Event `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationevents.ReplicationEventsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationEventsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, EventOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationEventsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate EventOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Event, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_a2aeventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_a2aeventdetails.go new file mode 100644 index 00000000000..367f037825d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_a2aeventdetails.go @@ -0,0 +1,46 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = A2AEventDetails{} + +type A2AEventDetails struct { + FabricLocation *string `json:"fabricLocation,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + ProtectedItemName *string `json:"protectedItemName,omitempty"` + RemoteFabricLocation *string `json:"remoteFabricLocation,omitempty"` + RemoteFabricName *string `json:"remoteFabricName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = A2AEventDetails{} + +func (s A2AEventDetails) MarshalJSON() ([]byte, error) { + type wrapper A2AEventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AEventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AEventDetails: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AEventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_event.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_event.go new file mode 100644 index 00000000000..e80daa64ebb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_event.go @@ -0,0 +1,12 @@ +package replicationevents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Event struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EventProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventproperties.go new file mode 100644 index 00000000000..0f9a16c5443 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventproperties.go @@ -0,0 +1,80 @@ +package replicationevents + +import ( + "encoding/json" + "fmt" + "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 EventProperties struct { + AffectedObjectCorrelationId *string `json:"affectedObjectCorrelationId,omitempty"` + AffectedObjectFriendlyName *string `json:"affectedObjectFriendlyName,omitempty"` + Description *string `json:"description,omitempty"` + EventCode *string `json:"eventCode,omitempty"` + EventSpecificDetails EventSpecificDetails `json:"eventSpecificDetails"` + EventType *string `json:"eventType,omitempty"` + FabricId *string `json:"fabricId,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + ProviderSpecificDetails EventProviderSpecificDetails `json:"providerSpecificDetails"` + Severity *string `json:"severity,omitempty"` + TimeOfOccurrence *string `json:"timeOfOccurrence,omitempty"` +} + +func (o *EventProperties) GetTimeOfOccurrenceAsTime() (*time.Time, error) { + if o.TimeOfOccurrence == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeOfOccurrence, "2006-01-02T15:04:05Z07:00") +} + +func (o *EventProperties) SetTimeOfOccurrenceAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeOfOccurrence = &formatted +} + +var _ json.Unmarshaler = &EventProperties{} + +func (s *EventProperties) UnmarshalJSON(bytes []byte) error { + type alias EventProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into EventProperties: %+v", err) + } + + s.AffectedObjectCorrelationId = decoded.AffectedObjectCorrelationId + s.AffectedObjectFriendlyName = decoded.AffectedObjectFriendlyName + s.Description = decoded.Description + s.EventCode = decoded.EventCode + s.EventType = decoded.EventType + s.FabricId = decoded.FabricId + s.HealthErrors = decoded.HealthErrors + s.Severity = decoded.Severity + s.TimeOfOccurrence = decoded.TimeOfOccurrence + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EventProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["eventSpecificDetails"]; ok { + impl, err := unmarshalEventSpecificDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'EventSpecificDetails' for 'EventProperties': %+v", err) + } + s.EventSpecificDetails = impl + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalEventProviderSpecificDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'EventProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventproviderspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventproviderspecificdetails.go new file mode 100644 index 00000000000..1cac852b249 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventproviderspecificdetails.go @@ -0,0 +1,112 @@ +package replicationevents + +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 EventProviderSpecificDetails interface { +} + +func unmarshalEventProviderSpecificDetailsImplementation(input []byte) (EventProviderSpecificDetails, 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 EventProviderSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AEventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AEventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplica2012") { + var out HyperVReplica2012EventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplica2012EventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplica2012R2") { + var out HyperVReplica2012R2EventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplica2012R2EventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureEventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureEventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaBaseEventDetails") { + var out HyperVReplicaBaseEventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaBaseEventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2EventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2EventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmEventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmEventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcmFailback") { + var out InMageRcmFailbackEventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFailbackEventDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtEventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtEventDetails: %+v", err) + } + return out, nil + } + + type RawEventProviderSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawEventProviderSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventspecificdetails.go new file mode 100644 index 00000000000..015401d35f0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_eventspecificdetails.go @@ -0,0 +1,48 @@ +package replicationevents + +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 EventSpecificDetails interface { +} + +func unmarshalEventSpecificDetailsImplementation(input []byte) (EventSpecificDetails, 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 EventSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "JobStatus") { + var out JobStatusEventDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobStatusEventDetails: %+v", err) + } + return out, nil + } + + type RawEventSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawEventSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_healtherror.go new file mode 100644 index 00000000000..7739a4360d6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationevents + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplica2012eventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplica2012eventdetails.go new file mode 100644 index 00000000000..94a69b46715 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplica2012eventdetails.go @@ -0,0 +1,44 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = HyperVReplica2012EventDetails{} + +type HyperVReplica2012EventDetails struct { + ContainerName *string `json:"containerName,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + RemoteContainerName *string `json:"remoteContainerName,omitempty"` + RemoteFabricName *string `json:"remoteFabricName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplica2012EventDetails{} + +func (s HyperVReplica2012EventDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplica2012EventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplica2012EventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplica2012EventDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplica2012EventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplica2012r2eventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplica2012r2eventdetails.go new file mode 100644 index 00000000000..967ef27775b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplica2012r2eventdetails.go @@ -0,0 +1,44 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = HyperVReplica2012R2EventDetails{} + +type HyperVReplica2012R2EventDetails struct { + ContainerName *string `json:"containerName,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + RemoteContainerName *string `json:"remoteContainerName,omitempty"` + RemoteFabricName *string `json:"remoteFabricName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplica2012R2EventDetails{} + +func (s HyperVReplica2012R2EventDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplica2012R2EventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplica2012R2EventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplica2012R2EventDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012R2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplica2012R2EventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplicaazureeventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplicaazureeventdetails.go new file mode 100644 index 00000000000..6294a98f428 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplicaazureeventdetails.go @@ -0,0 +1,43 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = HyperVReplicaAzureEventDetails{} + +type HyperVReplicaAzureEventDetails struct { + ContainerName *string `json:"containerName,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + RemoteContainerName *string `json:"remoteContainerName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplicaAzureEventDetails{} + +func (s HyperVReplicaAzureEventDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureEventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureEventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureEventDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureEventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplicabaseeventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplicabaseeventdetails.go new file mode 100644 index 00000000000..910ff1b95e8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_hypervreplicabaseeventdetails.go @@ -0,0 +1,44 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = HyperVReplicaBaseEventDetails{} + +type HyperVReplicaBaseEventDetails struct { + ContainerName *string `json:"containerName,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + RemoteContainerName *string `json:"remoteContainerName,omitempty"` + RemoteFabricName *string `json:"remoteFabricName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplicaBaseEventDetails{} + +func (s HyperVReplicaBaseEventDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaBaseEventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaBaseEventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaBaseEventDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaBaseEventDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaBaseEventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmageazurev2eventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmageazurev2eventdetails.go new file mode 100644 index 00000000000..57570a28989 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmageazurev2eventdetails.go @@ -0,0 +1,47 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = InMageAzureV2EventDetails{} + +type InMageAzureV2EventDetails struct { + Category *string `json:"category,omitempty"` + Component *string `json:"component,omitempty"` + CorrectiveAction *string `json:"correctiveAction,omitempty"` + Details *string `json:"details,omitempty"` + EventType *string `json:"eventType,omitempty"` + SiteName *string `json:"siteName,omitempty"` + Summary *string `json:"summary,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = InMageAzureV2EventDetails{} + +func (s InMageAzureV2EventDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2EventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2EventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2EventDetails: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2EventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmagercmeventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmagercmeventdetails.go new file mode 100644 index 00000000000..4e7e36ac753 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmagercmeventdetails.go @@ -0,0 +1,48 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = InMageRcmEventDetails{} + +type InMageRcmEventDetails struct { + ApplianceName *string `json:"applianceName,omitempty"` + ComponentDisplayName *string `json:"componentDisplayName,omitempty"` + FabricName *string `json:"fabricName,omitempty"` + JobId *string `json:"jobId,omitempty"` + LatestAgentVersion *string `json:"latestAgentVersion,omitempty"` + ProtectedItemName *string `json:"protectedItemName,omitempty"` + ServerType *string `json:"serverType,omitempty"` + VirtualMachineName *string `json:"vmName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = InMageRcmEventDetails{} + +func (s InMageRcmEventDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmEventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmEventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmEventDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmEventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmagercmfailbackeventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmagercmfailbackeventdetails.go new file mode 100644 index 00000000000..353002fa657 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_inmagercmfailbackeventdetails.go @@ -0,0 +1,45 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = InMageRcmFailbackEventDetails{} + +type InMageRcmFailbackEventDetails struct { + ApplianceName *string `json:"applianceName,omitempty"` + ComponentDisplayName *string `json:"componentDisplayName,omitempty"` + ProtectedItemName *string `json:"protectedItemName,omitempty"` + ServerType *string `json:"serverType,omitempty"` + VirtualMachineName *string `json:"vmName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = InMageRcmFailbackEventDetails{} + +func (s InMageRcmFailbackEventDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFailbackEventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFailbackEventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFailbackEventDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcmFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFailbackEventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_innerhealtherror.go new file mode 100644 index 00000000000..357c416c2ff --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationevents + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_jobstatuseventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_jobstatuseventdetails.go new file mode 100644 index 00000000000..26e8104f7cd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_jobstatuseventdetails.go @@ -0,0 +1,44 @@ +package replicationevents + +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 _ EventSpecificDetails = JobStatusEventDetails{} + +type JobStatusEventDetails struct { + AffectedObjectType *string `json:"affectedObjectType,omitempty"` + JobFriendlyName *string `json:"jobFriendlyName,omitempty"` + JobId *string `json:"jobId,omitempty"` + JobStatus *string `json:"jobStatus,omitempty"` + + // Fields inherited from EventSpecificDetails +} + +var _ json.Marshaler = JobStatusEventDetails{} + +func (s JobStatusEventDetails) MarshalJSON() ([]byte, error) { + type wrapper JobStatusEventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobStatusEventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobStatusEventDetails: %+v", err) + } + decoded["instanceType"] = "JobStatus" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobStatusEventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_vmwarecbteventdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_vmwarecbteventdetails.go new file mode 100644 index 00000000000..fac0b6257cd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/model_vmwarecbteventdetails.go @@ -0,0 +1,41 @@ +package replicationevents + +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 _ EventProviderSpecificDetails = VMwareCbtEventDetails{} + +type VMwareCbtEventDetails struct { + MigrationItemName *string `json:"migrationItemName,omitempty"` + + // Fields inherited from EventProviderSpecificDetails +} + +var _ json.Marshaler = VMwareCbtEventDetails{} + +func (s VMwareCbtEventDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtEventDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtEventDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtEventDetails: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtEventDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/predicates.go new file mode 100644 index 00000000000..2c9f5c9cae0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/predicates.go @@ -0,0 +1,32 @@ +package replicationevents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p EventOperationPredicate) Matches(input Event) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationevents/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/version.go new file mode 100644 index 00000000000..062800335d9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationevents/version.go @@ -0,0 +1,12 @@ +package replicationevents + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationevents/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/README.md new file mode 100644 index 00000000000..64f1c92824c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/README.md @@ -0,0 +1,152 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics` Documentation + +The `replicationfabrics` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationfabrics" +``` + + +### Client Initialization + +```go +client := replicationfabrics.NewReplicationFabricsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationFabricsClient.CheckConsistency` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +if err := client.CheckConsistencyThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationFabricsClient.Create` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +payload := replicationfabrics.FabricCreationInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationFabricsClient.Delete` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationFabricsClient.Get` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +read, err := client.Get(ctx, id, replicationfabrics.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ReplicationFabricsClient.List` + +```go +ctx := context.TODO() +id := replicationfabrics.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationFabricsClient.MigrateToAad` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +if err := client.MigrateToAadThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationFabricsClient.Purge` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +if err := client.PurgeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationFabricsClient.ReassociateGateway` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +payload := replicationfabrics.FailoverProcessServerRequest{ + // ... +} + + +if err := client.ReassociateGatewayThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationFabricsClient.RenewCertificate` + +```go +ctx := context.TODO() +id := replicationfabrics.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +payload := replicationfabrics.RenewCertificateInput{ + // ... +} + + +if err := client.RenewCertificateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/client.go new file mode 100644 index 00000000000..f14e0791113 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/client.go @@ -0,0 +1,18 @@ +package replicationfabrics + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationFabricsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationFabricsClientWithBaseURI(endpoint string) ReplicationFabricsClient { + return ReplicationFabricsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/constants.go new file mode 100644 index 00000000000..794dfaaf78b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/constants.go @@ -0,0 +1,139 @@ +package replicationfabrics + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentVersionStatus string + +const ( + AgentVersionStatusDeprecated AgentVersionStatus = "Deprecated" + AgentVersionStatusNotSupported AgentVersionStatus = "NotSupported" + AgentVersionStatusSecurityUpdateRequired AgentVersionStatus = "SecurityUpdateRequired" + AgentVersionStatusSupported AgentVersionStatus = "Supported" + AgentVersionStatusUpdateRequired AgentVersionStatus = "UpdateRequired" +) + +func PossibleValuesForAgentVersionStatus() []string { + return []string{ + string(AgentVersionStatusDeprecated), + string(AgentVersionStatusNotSupported), + string(AgentVersionStatusSecurityUpdateRequired), + string(AgentVersionStatusSupported), + string(AgentVersionStatusUpdateRequired), + } +} + +func parseAgentVersionStatus(input string) (*AgentVersionStatus, error) { + vals := map[string]AgentVersionStatus{ + "deprecated": AgentVersionStatusDeprecated, + "notsupported": AgentVersionStatusNotSupported, + "securityupdaterequired": AgentVersionStatusSecurityUpdateRequired, + "supported": AgentVersionStatusSupported, + "updaterequired": AgentVersionStatusUpdateRequired, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AgentVersionStatus(input) + return &out, nil +} + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} + +type ProtectionHealth string + +const ( + ProtectionHealthCritical ProtectionHealth = "Critical" + ProtectionHealthNone ProtectionHealth = "None" + ProtectionHealthNormal ProtectionHealth = "Normal" + ProtectionHealthWarning ProtectionHealth = "Warning" +) + +func PossibleValuesForProtectionHealth() []string { + return []string{ + string(ProtectionHealthCritical), + string(ProtectionHealthNone), + string(ProtectionHealthNormal), + string(ProtectionHealthWarning), + } +} + +func parseProtectionHealth(input string) (*ProtectionHealth, error) { + vals := map[string]ProtectionHealth{ + "critical": ProtectionHealthCritical, + "none": ProtectionHealthNone, + "normal": ProtectionHealthNormal, + "warning": ProtectionHealthWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionHealth(input) + return &out, nil +} + +type RcmComponentStatus string + +const ( + RcmComponentStatusCritical RcmComponentStatus = "Critical" + RcmComponentStatusHealthy RcmComponentStatus = "Healthy" + RcmComponentStatusUnknown RcmComponentStatus = "Unknown" + RcmComponentStatusWarning RcmComponentStatus = "Warning" +) + +func PossibleValuesForRcmComponentStatus() []string { + return []string{ + string(RcmComponentStatusCritical), + string(RcmComponentStatusHealthy), + string(RcmComponentStatusUnknown), + string(RcmComponentStatusWarning), + } +} + +func parseRcmComponentStatus(input string) (*RcmComponentStatus, error) { + vals := map[string]RcmComponentStatus{ + "critical": RcmComponentStatusCritical, + "healthy": RcmComponentStatusHealthy, + "unknown": RcmComponentStatusUnknown, + "warning": RcmComponentStatusWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RcmComponentStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_replicationfabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_replicationfabric.go new file mode 100644 index 00000000000..30b371b923b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationfabrics + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_replicationfabric_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_replicationfabric_test.go new file mode 100644 index 00000000000..dc4f3caf3c2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_replicationfabric_test.go @@ -0,0 +1,327 @@ +package replicationfabrics + +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 = ReplicationFabricId{} + +func TestNewReplicationFabricID(t *testing.T) { + id := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } +} + +func TestFormatReplicationFabricID(t *testing.T) { + actual := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestParseReplicationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestSegmentsForReplicationFabricId(t *testing.T) { + segments := ReplicationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationFabricId 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/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_vault.go new file mode 100644 index 00000000000..c72efd47e79 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_vault.go @@ -0,0 +1,127 @@ +package replicationfabrics + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_vault_test.go new file mode 100644 index 00000000000..0b8bad516bf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationfabrics + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_checkconsistency_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_checkconsistency_autorest.go new file mode 100644 index 00000000000..2f47001a55a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_checkconsistency_autorest.go @@ -0,0 +1,78 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckConsistencyOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CheckConsistency ... +func (c ReplicationFabricsClient) CheckConsistency(ctx context.Context, id ReplicationFabricId) (result CheckConsistencyOperationResponse, err error) { + req, err := c.preparerForCheckConsistency(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "CheckConsistency", nil, "Failure preparing request") + return + } + + result, err = c.senderForCheckConsistency(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "CheckConsistency", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CheckConsistencyThenPoll performs CheckConsistency then polls until it's completed +func (c ReplicationFabricsClient) CheckConsistencyThenPoll(ctx context.Context, id ReplicationFabricId) error { + result, err := c.CheckConsistency(ctx, id) + if err != nil { + return fmt.Errorf("performing CheckConsistency: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CheckConsistency: %+v", err) + } + + return nil +} + +// preparerForCheckConsistency prepares the CheckConsistency request. +func (c ReplicationFabricsClient) preparerForCheckConsistency(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/checkConsistency", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCheckConsistency sends the CheckConsistency request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationFabricsClient) senderForCheckConsistency(ctx context.Context, req *http.Request) (future CheckConsistencyOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_create_autorest.go new file mode 100644 index 00000000000..c9c6a6bcbaa --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationFabricsClient) Create(ctx context.Context, id ReplicationFabricId, input FabricCreationInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationFabricsClient) CreateThenPoll(ctx context.Context, id ReplicationFabricId, input FabricCreationInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationFabricsClient) preparerForCreate(ctx context.Context, id ReplicationFabricId, input FabricCreationInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationFabricsClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_delete_autorest.go new file mode 100644 index 00000000000..b72f3191e43 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationFabricsClient) Delete(ctx context.Context, id ReplicationFabricId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationFabricsClient) DeleteThenPoll(ctx context.Context, id ReplicationFabricId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationFabricsClient) preparerForDelete(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/remove", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationFabricsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_get_autorest.go new file mode 100644 index 00000000000..476056a899a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_get_autorest.go @@ -0,0 +1,97 @@ +package replicationfabrics + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Fabric +} + +type GetOperationOptions struct { + Filter *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o GetOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// Get ... +func (c ReplicationFabricsClient) Get(ctx context.Context, id ReplicationFabricId, options GetOperationOptions) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationFabricsClient) preparerForGet(ctx context.Context, id ReplicationFabricId, options GetOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationFabricsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_list_autorest.go new file mode 100644 index 00000000000..a37ca0867e6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Fabric + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Fabric +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationFabricsClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationFabricsClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationFabrics", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationFabricsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationFabricsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Fabric `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationFabricsClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, FabricOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationFabricsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate FabricOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Fabric, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_migratetoaad_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_migratetoaad_autorest.go new file mode 100644 index 00000000000..3442bebe925 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_migratetoaad_autorest.go @@ -0,0 +1,78 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateToAadOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// MigrateToAad ... +func (c ReplicationFabricsClient) MigrateToAad(ctx context.Context, id ReplicationFabricId) (result MigrateToAadOperationResponse, err error) { + req, err := c.preparerForMigrateToAad(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "MigrateToAad", nil, "Failure preparing request") + return + } + + result, err = c.senderForMigrateToAad(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "MigrateToAad", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// MigrateToAadThenPoll performs MigrateToAad then polls until it's completed +func (c ReplicationFabricsClient) MigrateToAadThenPoll(ctx context.Context, id ReplicationFabricId) error { + result, err := c.MigrateToAad(ctx, id) + if err != nil { + return fmt.Errorf("performing MigrateToAad: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after MigrateToAad: %+v", err) + } + + return nil +} + +// preparerForMigrateToAad prepares the MigrateToAad request. +func (c ReplicationFabricsClient) preparerForMigrateToAad(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/migratetoaad", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForMigrateToAad sends the MigrateToAad request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationFabricsClient) senderForMigrateToAad(ctx context.Context, req *http.Request) (future MigrateToAadOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_purge_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_purge_autorest.go new file mode 100644 index 00000000000..b3a0a25063c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_purge_autorest.go @@ -0,0 +1,78 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurgeOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Purge ... +func (c ReplicationFabricsClient) Purge(ctx context.Context, id ReplicationFabricId) (result PurgeOperationResponse, err error) { + req, err := c.preparerForPurge(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Purge", nil, "Failure preparing request") + return + } + + result, err = c.senderForPurge(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "Purge", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PurgeThenPoll performs Purge then polls until it's completed +func (c ReplicationFabricsClient) PurgeThenPoll(ctx context.Context, id ReplicationFabricId) error { + result, err := c.Purge(ctx, id) + if err != nil { + return fmt.Errorf("performing Purge: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Purge: %+v", err) + } + + return nil +} + +// preparerForPurge prepares the Purge request. +func (c ReplicationFabricsClient) preparerForPurge(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPurge sends the Purge request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationFabricsClient) senderForPurge(ctx context.Context, req *http.Request) (future PurgeOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_reassociategateway_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_reassociategateway_autorest.go new file mode 100644 index 00000000000..5205c6bec9e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_reassociategateway_autorest.go @@ -0,0 +1,79 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReassociateGatewayOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ReassociateGateway ... +func (c ReplicationFabricsClient) ReassociateGateway(ctx context.Context, id ReplicationFabricId, input FailoverProcessServerRequest) (result ReassociateGatewayOperationResponse, err error) { + req, err := c.preparerForReassociateGateway(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "ReassociateGateway", nil, "Failure preparing request") + return + } + + result, err = c.senderForReassociateGateway(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "ReassociateGateway", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ReassociateGatewayThenPoll performs ReassociateGateway then polls until it's completed +func (c ReplicationFabricsClient) ReassociateGatewayThenPoll(ctx context.Context, id ReplicationFabricId, input FailoverProcessServerRequest) error { + result, err := c.ReassociateGateway(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ReassociateGateway: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ReassociateGateway: %+v", err) + } + + return nil +} + +// preparerForReassociateGateway prepares the ReassociateGateway request. +func (c ReplicationFabricsClient) preparerForReassociateGateway(ctx context.Context, id ReplicationFabricId, input FailoverProcessServerRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/reassociateGateway", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForReassociateGateway sends the ReassociateGateway request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationFabricsClient) senderForReassociateGateway(ctx context.Context, req *http.Request) (future ReassociateGatewayOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_renewcertificate_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_renewcertificate_autorest.go new file mode 100644 index 00000000000..00768d9785b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/method_renewcertificate_autorest.go @@ -0,0 +1,79 @@ +package replicationfabrics + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RenewCertificateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// RenewCertificate ... +func (c ReplicationFabricsClient) RenewCertificate(ctx context.Context, id ReplicationFabricId, input RenewCertificateInput) (result RenewCertificateOperationResponse, err error) { + req, err := c.preparerForRenewCertificate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "RenewCertificate", nil, "Failure preparing request") + return + } + + result, err = c.senderForRenewCertificate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationfabrics.ReplicationFabricsClient", "RenewCertificate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RenewCertificateThenPoll performs RenewCertificate then polls until it's completed +func (c ReplicationFabricsClient) RenewCertificateThenPoll(ctx context.Context, id ReplicationFabricId, input RenewCertificateInput) error { + result, err := c.RenewCertificate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RenewCertificate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after RenewCertificate: %+v", err) + } + + return nil +} + +// preparerForRenewCertificate prepares the RenewCertificate request. +func (c ReplicationFabricsClient) preparerForRenewCertificate(ctx context.Context, id ReplicationFabricId, input RenewCertificateInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/renewCertificate", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRenewCertificate sends the RenewCertificate request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationFabricsClient) senderForRenewCertificate(ctx context.Context, req *http.Request) (future RenewCertificateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_a2aextendedlocationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_a2aextendedlocationdetails.go new file mode 100644 index 00000000000..4c3f270376d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_a2aextendedlocationdetails.go @@ -0,0 +1,13 @@ +package replicationfabrics + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AExtendedLocationDetails struct { + PrimaryExtendedLocation *edgezones.Model `json:"primaryExtendedLocation,omitempty"` + RecoveryExtendedLocation *edgezones.Model `json:"recoveryExtendedLocation,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_a2azonedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_a2azonedetails.go new file mode 100644 index 00000000000..f4ad23d1c8c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_a2azonedetails.go @@ -0,0 +1,9 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AZoneDetails struct { + Source *string `json:"source,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_agentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_agentdetails.go new file mode 100644 index 00000000000..ec30bdfa82c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_agentdetails.go @@ -0,0 +1,12 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentDetails struct { + AgentId *string `json:"agentId,omitempty"` + BiosId *string `json:"biosId,omitempty"` + Disks *[]AgentDiskDetails `json:"disks,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + MachineId *string `json:"machineId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_agentdiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_agentdiskdetails.go new file mode 100644 index 00000000000..be3e096778e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_agentdiskdetails.go @@ -0,0 +1,12 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentDiskDetails struct { + CapacityInBytes *int64 `json:"capacityInBytes,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + IsOSDisk *string `json:"isOSDisk,omitempty"` + LunId *int64 `json:"lunId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_azurefabriccreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_azurefabriccreationinput.go new file mode 100644 index 00000000000..916dcdb0b32 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_azurefabriccreationinput.go @@ -0,0 +1,41 @@ +package replicationfabrics + +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 _ FabricSpecificCreationInput = AzureFabricCreationInput{} + +type AzureFabricCreationInput struct { + Location *string `json:"location,omitempty"` + + // Fields inherited from FabricSpecificCreationInput +} + +var _ json.Marshaler = AzureFabricCreationInput{} + +func (s AzureFabricCreationInput) MarshalJSON() ([]byte, error) { + type wrapper AzureFabricCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFabricCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFabricCreationInput: %+v", err) + } + decoded["instanceType"] = "Azure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFabricCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_azurefabricspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_azurefabricspecificdetails.go new file mode 100644 index 00000000000..ddccad4b478 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_azurefabricspecificdetails.go @@ -0,0 +1,44 @@ +package replicationfabrics + +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 _ FabricSpecificDetails = AzureFabricSpecificDetails{} + +type AzureFabricSpecificDetails struct { + ContainerIds *[]string `json:"containerIds,omitempty"` + ExtendedLocations *[]A2AExtendedLocationDetails `json:"extendedLocations,omitempty"` + Location *string `json:"location,omitempty"` + Zones *[]A2AZoneDetails `json:"zones,omitempty"` + + // Fields inherited from FabricSpecificDetails +} + +var _ json.Marshaler = AzureFabricSpecificDetails{} + +func (s AzureFabricSpecificDetails) MarshalJSON() ([]byte, error) { + type wrapper AzureFabricSpecificDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFabricSpecificDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFabricSpecificDetails: %+v", err) + } + decoded["instanceType"] = "Azure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFabricSpecificDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_datastore.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_datastore.go new file mode 100644 index 00000000000..e20a79fe8fe --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_datastore.go @@ -0,0 +1,12 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataStore struct { + Capacity *string `json:"capacity,omitempty"` + FreeSpace *string `json:"freeSpace,omitempty"` + SymbolicName *string `json:"symbolicName,omitempty"` + Type *string `json:"type,omitempty"` + Uuid *string `json:"uuid,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_dradetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_dradetails.go new file mode 100644 index 00000000000..3e205a58dff --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_dradetails.go @@ -0,0 +1,34 @@ +package replicationfabrics + +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 DraDetails struct { + BiosId *string `json:"biosId,omitempty"` + ForwardProtectedItemCount *int64 `json:"forwardProtectedItemCount,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + ReverseProtectedItemCount *int64 `json:"reverseProtectedItemCount,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *DraDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *DraDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_encryptiondetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_encryptiondetails.go new file mode 100644 index 00000000000..75278c5e8f0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_encryptiondetails.go @@ -0,0 +1,28 @@ +package replicationfabrics + +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 EncryptionDetails struct { + KekCertExpiryDate *string `json:"kekCertExpiryDate,omitempty"` + KekCertThumbprint *string `json:"kekCertThumbprint,omitempty"` + KekState *string `json:"kekState,omitempty"` +} + +func (o *EncryptionDetails) GetKekCertExpiryDateAsTime() (*time.Time, error) { + if o.KekCertExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.KekCertExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *EncryptionDetails) SetKekCertExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.KekCertExpiryDate = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabric.go new file mode 100644 index 00000000000..025c3ea019c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabric.go @@ -0,0 +1,12 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Fabric struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *FabricProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabriccreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabriccreationinput.go new file mode 100644 index 00000000000..33f8bdc704c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabriccreationinput.go @@ -0,0 +1,8 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FabricCreationInput struct { + Properties *FabricCreationInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabriccreationinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabriccreationinputproperties.go new file mode 100644 index 00000000000..5af8a2ed128 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabriccreationinputproperties.go @@ -0,0 +1,32 @@ +package replicationfabrics + +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 FabricCreationInputProperties struct { + CustomDetails FabricSpecificCreationInput `json:"customDetails"` +} + +var _ json.Unmarshaler = &FabricCreationInputProperties{} + +func (s *FabricCreationInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling FabricCreationInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customDetails"]; ok { + impl, err := unmarshalFabricSpecificCreationInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomDetails' for 'FabricCreationInputProperties': %+v", err) + } + s.CustomDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricproperties.go new file mode 100644 index 00000000000..b0392225021 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricproperties.go @@ -0,0 +1,52 @@ +package replicationfabrics + +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 FabricProperties struct { + BcdrState *string `json:"bcdrState,omitempty"` + CustomDetails FabricSpecificDetails `json:"customDetails"` + EncryptionDetails *EncryptionDetails `json:"encryptionDetails,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Health *string `json:"health,omitempty"` + HealthErrorDetails *[]HealthError `json:"healthErrorDetails,omitempty"` + InternalIdentifier *string `json:"internalIdentifier,omitempty"` + RolloverEncryptionDetails *EncryptionDetails `json:"rolloverEncryptionDetails,omitempty"` +} + +var _ json.Unmarshaler = &FabricProperties{} + +func (s *FabricProperties) UnmarshalJSON(bytes []byte) error { + type alias FabricProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into FabricProperties: %+v", err) + } + + s.BcdrState = decoded.BcdrState + s.EncryptionDetails = decoded.EncryptionDetails + s.FriendlyName = decoded.FriendlyName + s.Health = decoded.Health + s.HealthErrorDetails = decoded.HealthErrorDetails + s.InternalIdentifier = decoded.InternalIdentifier + s.RolloverEncryptionDetails = decoded.RolloverEncryptionDetails + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling FabricProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customDetails"]; ok { + impl, err := unmarshalFabricSpecificDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomDetails' for 'FabricProperties': %+v", err) + } + s.CustomDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricspecificcreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricspecificcreationinput.go new file mode 100644 index 00000000000..0358e915ed4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricspecificcreationinput.go @@ -0,0 +1,64 @@ +package replicationfabrics + +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 FabricSpecificCreationInput interface { +} + +func unmarshalFabricSpecificCreationInputImplementation(input []byte) (FabricSpecificCreationInput, 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 FabricSpecificCreationInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Azure") { + var out AzureFabricCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFabricCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmFabricCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFabricCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareV2") { + var out VMwareV2FabricCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareV2FabricCreationInput: %+v", err) + } + return out, nil + } + + type RawFabricSpecificCreationInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawFabricSpecificCreationInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricspecificdetails.go new file mode 100644 index 00000000000..e0204cafb01 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_fabricspecificdetails.go @@ -0,0 +1,88 @@ +package replicationfabrics + +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 FabricSpecificDetails interface { +} + +func unmarshalFabricSpecificDetailsImplementation(input []byte) (FabricSpecificDetails, 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 FabricSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Azure") { + var out AzureFabricSpecificDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFabricSpecificDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVSite") { + var out HyperVSiteDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVSiteDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmFabricSpecificDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFabricSpecificDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMM") { + var out VMmDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMmDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMware") { + var out VMwareDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareV2") { + var out VMwareV2FabricSpecificDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareV2FabricSpecificDetails: %+v", err) + } + return out, nil + } + + type RawFabricSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawFabricSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_failoverprocessserverrequest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_failoverprocessserverrequest.go new file mode 100644 index 00000000000..f782d62e870 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_failoverprocessserverrequest.go @@ -0,0 +1,8 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverProcessServerRequest struct { + Properties *FailoverProcessServerRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_failoverprocessserverrequestproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_failoverprocessserverrequestproperties.go new file mode 100644 index 00000000000..03ea6958e5d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_failoverprocessserverrequestproperties.go @@ -0,0 +1,12 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverProcessServerRequestProperties struct { + ContainerName *string `json:"containerName,omitempty"` + SourceProcessServerId *string `json:"sourceProcessServerId,omitempty"` + TargetProcessServerId *string `json:"targetProcessServerId,omitempty"` + UpdateType *string `json:"updateType,omitempty"` + VMsToMigrate *[]string `json:"vmsToMigrate,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_healtherror.go new file mode 100644 index 00000000000..50dfa0a791d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationfabrics + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_hypervhostdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_hypervhostdetails.go new file mode 100644 index 00000000000..5a5914edea0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_hypervhostdetails.go @@ -0,0 +1,10 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HyperVHostDetails struct { + Id *string `json:"id,omitempty"` + MarsAgentVersion *string `json:"marsAgentVersion,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_hypervsitedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_hypervsitedetails.go new file mode 100644 index 00000000000..293057fa1f0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_hypervsitedetails.go @@ -0,0 +1,41 @@ +package replicationfabrics + +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 _ FabricSpecificDetails = HyperVSiteDetails{} + +type HyperVSiteDetails struct { + HyperVHosts *[]HyperVHostDetails `json:"hyperVHosts,omitempty"` + + // Fields inherited from FabricSpecificDetails +} + +var _ json.Marshaler = HyperVSiteDetails{} + +func (s HyperVSiteDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVSiteDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVSiteDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVSiteDetails: %+v", err) + } + decoded["instanceType"] = "HyperVSite" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVSiteDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_identityproviderdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_identityproviderdetails.go new file mode 100644 index 00000000000..0a005565876 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_identityproviderdetails.go @@ -0,0 +1,12 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderDetails struct { + AadAuthority *string `json:"aadAuthority,omitempty"` + ApplicationId *string `json:"applicationId,omitempty"` + Audience *string `json:"audience,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_identityproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_identityproviderinput.go new file mode 100644 index 00000000000..95277e41cc9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_identityproviderinput.go @@ -0,0 +1,12 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderInput struct { + AadAuthority string `json:"aadAuthority"` + ApplicationId string `json:"applicationId"` + Audience string `json:"audience"` + ObjectId string `json:"objectId"` + TenantId string `json:"tenantId"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagefabricswitchproviderblockingerrordetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagefabricswitchproviderblockingerrordetails.go new file mode 100644 index 00000000000..665f9db6edb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagefabricswitchproviderblockingerrordetails.go @@ -0,0 +1,13 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageFabricSwitchProviderBlockingErrorDetails struct { + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorMessageParameters *map[string]string `json:"errorMessageParameters,omitempty"` + ErrorTags *map[string]string `json:"errorTags,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagercmfabriccreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagercmfabriccreationinput.go new file mode 100644 index 00000000000..6e169783cd2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagercmfabriccreationinput.go @@ -0,0 +1,43 @@ +package replicationfabrics + +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 _ FabricSpecificCreationInput = InMageRcmFabricCreationInput{} + +type InMageRcmFabricCreationInput struct { + PhysicalSiteId string `json:"physicalSiteId"` + SourceAgentIdentity IdentityProviderInput `json:"sourceAgentIdentity"` + VMwareSiteId string `json:"vmwareSiteId"` + + // Fields inherited from FabricSpecificCreationInput +} + +var _ json.Marshaler = InMageRcmFabricCreationInput{} + +func (s InMageRcmFabricCreationInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFabricCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFabricCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFabricCreationInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFabricCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagercmfabricspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagercmfabricspecificdetails.go new file mode 100644 index 00000000000..6d4749c4c1c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_inmagercmfabricspecificdetails.go @@ -0,0 +1,56 @@ +package replicationfabrics + +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 _ FabricSpecificDetails = InMageRcmFabricSpecificDetails{} + +type InMageRcmFabricSpecificDetails struct { + AgentDetails *[]AgentDetails `json:"agentDetails,omitempty"` + ControlPlaneUri *string `json:"controlPlaneUri,omitempty"` + DataPlaneUri *string `json:"dataPlaneUri,omitempty"` + Dras *[]DraDetails `json:"dras,omitempty"` + MarsAgents *[]MarsAgentDetails `json:"marsAgents,omitempty"` + PhysicalSiteId *string `json:"physicalSiteId,omitempty"` + ProcessServers *[]ProcessServerDetails `json:"processServers,omitempty"` + PushInstallers *[]PushInstallerDetails `json:"pushInstallers,omitempty"` + RcmProxies *[]RcmProxyDetails `json:"rcmProxies,omitempty"` + ReplicationAgents *[]ReplicationAgentDetails `json:"replicationAgents,omitempty"` + ReprotectAgents *[]ReprotectAgentDetails `json:"reprotectAgents,omitempty"` + ServiceContainerId *string `json:"serviceContainerId,omitempty"` + ServiceEndpoint *string `json:"serviceEndpoint,omitempty"` + ServiceResourceId *string `json:"serviceResourceId,omitempty"` + SourceAgentIdentityDetails *IdentityProviderDetails `json:"sourceAgentIdentityDetails,omitempty"` + VMwareSiteId *string `json:"vmwareSiteId,omitempty"` + + // Fields inherited from FabricSpecificDetails +} + +var _ json.Marshaler = InMageRcmFabricSpecificDetails{} + +func (s InMageRcmFabricSpecificDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFabricSpecificDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFabricSpecificDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFabricSpecificDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFabricSpecificDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_innerhealtherror.go new file mode 100644 index 00000000000..c14191f79bd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationfabrics + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_marsagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_marsagentdetails.go new file mode 100644 index 00000000000..ed4c6a9d572 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_marsagentdetails.go @@ -0,0 +1,34 @@ +package replicationfabrics + +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 MarsAgentDetails struct { + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *MarsAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *MarsAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_mastertargetserver.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_mastertargetserver.go new file mode 100644 index 00000000000..a5e06f8b4a6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_mastertargetserver.go @@ -0,0 +1,67 @@ +package replicationfabrics + +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 MasterTargetServer struct { + AgentExpiryDate *string `json:"agentExpiryDate,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + AgentVersionDetails *VersionDetails `json:"agentVersionDetails,omitempty"` + DataStores *[]DataStore `json:"dataStores,omitempty"` + DiskCount *int64 `json:"diskCount,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeat *string `json:"lastHeartbeat,omitempty"` + MarsAgentExpiryDate *string `json:"marsAgentExpiryDate,omitempty"` + MarsAgentVersion *string `json:"marsAgentVersion,omitempty"` + MarsAgentVersionDetails *VersionDetails `json:"marsAgentVersionDetails,omitempty"` + Name *string `json:"name,omitempty"` + OsType *string `json:"osType,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + RetentionVolumes *[]RetentionVolume `json:"retentionVolumes,omitempty"` + ValidationErrors *[]HealthError `json:"validationErrors,omitempty"` + VersionStatus *string `json:"versionStatus,omitempty"` +} + +func (o *MasterTargetServer) GetAgentExpiryDateAsTime() (*time.Time, error) { + if o.AgentExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AgentExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *MasterTargetServer) SetAgentExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AgentExpiryDate = &formatted +} + +func (o *MasterTargetServer) GetLastHeartbeatAsTime() (*time.Time, error) { + if o.LastHeartbeat == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeat, "2006-01-02T15:04:05Z07:00") +} + +func (o *MasterTargetServer) SetLastHeartbeatAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeat = &formatted +} + +func (o *MasterTargetServer) GetMarsAgentExpiryDateAsTime() (*time.Time, error) { + if o.MarsAgentExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.MarsAgentExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *MasterTargetServer) SetMarsAgentExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.MarsAgentExpiryDate = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_mobilityserviceupdate.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_mobilityserviceupdate.go new file mode 100644 index 00000000000..aa2c9c06e41 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_mobilityserviceupdate.go @@ -0,0 +1,10 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MobilityServiceUpdate struct { + OsType *string `json:"osType,omitempty"` + RebootStatus *string `json:"rebootStatus,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_processserver.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_processserver.go new file mode 100644 index 00000000000..60022e3bd47 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_processserver.go @@ -0,0 +1,97 @@ +package replicationfabrics + +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 ProcessServer struct { + AgentExpiryDate *string `json:"agentExpiryDate,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + AgentVersionDetails *VersionDetails `json:"agentVersionDetails,omitempty"` + AvailableMemoryInBytes *int64 `json:"availableMemoryInBytes,omitempty"` + AvailableSpaceInBytes *int64 `json:"availableSpaceInBytes,omitempty"` + CpuLoad *string `json:"cpuLoad,omitempty"` + CpuLoadStatus *string `json:"cpuLoadStatus,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + HostId *string `json:"hostId,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeat *string `json:"lastHeartbeat,omitempty"` + MachineCount *string `json:"machineCount,omitempty"` + MarsCommunicationStatus *string `json:"marsCommunicationStatus,omitempty"` + MarsRegistrationStatus *string `json:"marsRegistrationStatus,omitempty"` + MemoryUsageStatus *string `json:"memoryUsageStatus,omitempty"` + MobilityServiceUpdates *[]MobilityServiceUpdate `json:"mobilityServiceUpdates,omitempty"` + OsType *string `json:"osType,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + PsServiceStatus *string `json:"psServiceStatus,omitempty"` + PsStatsRefreshTime *string `json:"psStatsRefreshTime,omitempty"` + ReplicationPairCount *string `json:"replicationPairCount,omitempty"` + SpaceUsageStatus *string `json:"spaceUsageStatus,omitempty"` + SslCertExpiryDate *string `json:"sslCertExpiryDate,omitempty"` + SslCertExpiryRemainingDays *int64 `json:"sslCertExpiryRemainingDays,omitempty"` + SystemLoad *string `json:"systemLoad,omitempty"` + SystemLoadStatus *string `json:"systemLoadStatus,omitempty"` + ThroughputInBytes *int64 `json:"throughputInBytes,omitempty"` + ThroughputInMBps *int64 `json:"throughputInMBps,omitempty"` + ThroughputStatus *string `json:"throughputStatus,omitempty"` + ThroughputUploadPendingDataInBytes *int64 `json:"throughputUploadPendingDataInBytes,omitempty"` + TotalMemoryInBytes *int64 `json:"totalMemoryInBytes,omitempty"` + TotalSpaceInBytes *int64 `json:"totalSpaceInBytes,omitempty"` + VersionStatus *string `json:"versionStatus,omitempty"` +} + +func (o *ProcessServer) GetAgentExpiryDateAsTime() (*time.Time, error) { + if o.AgentExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AgentExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProcessServer) SetAgentExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AgentExpiryDate = &formatted +} + +func (o *ProcessServer) GetLastHeartbeatAsTime() (*time.Time, error) { + if o.LastHeartbeat == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeat, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProcessServer) SetLastHeartbeatAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeat = &formatted +} + +func (o *ProcessServer) GetPsStatsRefreshTimeAsTime() (*time.Time, error) { + if o.PsStatsRefreshTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PsStatsRefreshTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProcessServer) SetPsStatsRefreshTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PsStatsRefreshTime = &formatted +} + +func (o *ProcessServer) GetSslCertExpiryDateAsTime() (*time.Time, error) { + if o.SslCertExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.SslCertExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProcessServer) SetSslCertExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.SslCertExpiryDate = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_processserverdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_processserverdetails.go new file mode 100644 index 00000000000..dd4118b12a9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_processserverdetails.go @@ -0,0 +1,54 @@ +package replicationfabrics + +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 ProcessServerDetails struct { + AvailableMemoryInBytes *int64 `json:"availableMemoryInBytes,omitempty"` + AvailableSpaceInBytes *int64 `json:"availableSpaceInBytes,omitempty"` + BiosId *string `json:"biosId,omitempty"` + DiskUsageStatus *RcmComponentStatus `json:"diskUsageStatus,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + FreeSpacePercentage *float64 `json:"freeSpacePercentage,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + HistoricHealth *ProtectionHealth `json:"historicHealth,omitempty"` + IPAddresses *[]string `json:"ipAddresses,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + MemoryUsagePercentage *float64 `json:"memoryUsagePercentage,omitempty"` + MemoryUsageStatus *RcmComponentStatus `json:"memoryUsageStatus,omitempty"` + Name *string `json:"name,omitempty"` + ProcessorUsagePercentage *float64 `json:"processorUsagePercentage,omitempty"` + ProcessorUsageStatus *RcmComponentStatus `json:"processorUsageStatus,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + SystemLoad *int64 `json:"systemLoad,omitempty"` + SystemLoadStatus *RcmComponentStatus `json:"systemLoadStatus,omitempty"` + ThroughputInBytes *int64 `json:"throughputInBytes,omitempty"` + ThroughputStatus *RcmComponentStatus `json:"throughputStatus,omitempty"` + ThroughputUploadPendingDataInBytes *int64 `json:"throughputUploadPendingDataInBytes,omitempty"` + TotalMemoryInBytes *int64 `json:"totalMemoryInBytes,omitempty"` + TotalSpaceInBytes *int64 `json:"totalSpaceInBytes,omitempty"` + UsedMemoryInBytes *int64 `json:"usedMemoryInBytes,omitempty"` + UsedSpaceInBytes *int64 `json:"usedSpaceInBytes,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ProcessServerDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProcessServerDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_pushinstallerdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_pushinstallerdetails.go new file mode 100644 index 00000000000..e12d0506fab --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_pushinstallerdetails.go @@ -0,0 +1,34 @@ +package replicationfabrics + +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 PushInstallerDetails struct { + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *PushInstallerDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *PushInstallerDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_rcmproxydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_rcmproxydetails.go new file mode 100644 index 00000000000..939904987ef --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_rcmproxydetails.go @@ -0,0 +1,35 @@ +package replicationfabrics + +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 RcmProxyDetails struct { + BiosId *string `json:"biosId,omitempty"` + ClientAuthenticationType *string `json:"clientAuthenticationType,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *RcmProxyDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *RcmProxyDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_renewcertificateinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_renewcertificateinput.go new file mode 100644 index 00000000000..ab4a712f42d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_renewcertificateinput.go @@ -0,0 +1,8 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RenewCertificateInput struct { + Properties *RenewCertificateInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_renewcertificateinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_renewcertificateinputproperties.go new file mode 100644 index 00000000000..bf4f0b8030e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_renewcertificateinputproperties.go @@ -0,0 +1,8 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RenewCertificateInputProperties struct { + RenewCertificateType *string `json:"renewCertificateType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_replicationagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_replicationagentdetails.go new file mode 100644 index 00000000000..0e9ca7038c8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_replicationagentdetails.go @@ -0,0 +1,34 @@ +package replicationfabrics + +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 ReplicationAgentDetails struct { + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ReplicationAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReplicationAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_reprotectagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_reprotectagentdetails.go new file mode 100644 index 00000000000..61e5cf92ba5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_reprotectagentdetails.go @@ -0,0 +1,50 @@ +package replicationfabrics + +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 ReprotectAgentDetails struct { + AccessibleDatastores *[]string `json:"accessibleDatastores,omitempty"` + BiosId *string `json:"biosId,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + Id *string `json:"id,omitempty"` + LastDiscoveryInUtc *string `json:"lastDiscoveryInUtc,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + Name *string `json:"name,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + VcenterId *string `json:"vcenterId,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ReprotectAgentDetails) GetLastDiscoveryInUtcAsTime() (*time.Time, error) { + if o.LastDiscoveryInUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastDiscoveryInUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReprotectAgentDetails) SetLastDiscoveryInUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastDiscoveryInUtc = &formatted +} + +func (o *ReprotectAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReprotectAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_retentionvolume.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_retentionvolume.go new file mode 100644 index 00000000000..7d9aa7c6801 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_retentionvolume.go @@ -0,0 +1,11 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetentionVolume struct { + CapacityInBytes *int64 `json:"capacityInBytes,omitempty"` + FreeSpaceInBytes *int64 `json:"freeSpaceInBytes,omitempty"` + ThresholdPercentage *int64 `json:"thresholdPercentage,omitempty"` + VolumeName *string `json:"volumeName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_runasaccount.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_runasaccount.go new file mode 100644 index 00000000000..2339edd7049 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_runasaccount.go @@ -0,0 +1,9 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunAsAccount struct { + AccountId *string `json:"accountId,omitempty"` + AccountName *string `json:"accountName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_versiondetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_versiondetails.go new file mode 100644 index 00000000000..5d74eb7597e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_versiondetails.go @@ -0,0 +1,28 @@ +package replicationfabrics + +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 VersionDetails struct { + ExpiryDate *string `json:"expiryDate,omitempty"` + Status *AgentVersionStatus `json:"status,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *VersionDetails) GetExpiryDateAsTime() (*time.Time, error) { + if o.ExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *VersionDetails) SetExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryDate = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmmdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmmdetails.go new file mode 100644 index 00000000000..f96234c1306 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmmdetails.go @@ -0,0 +1,40 @@ +package replicationfabrics + +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 _ FabricSpecificDetails = VMmDetails{} + +type VMmDetails struct { + + // Fields inherited from FabricSpecificDetails +} + +var _ json.Marshaler = VMmDetails{} + +func (s VMmDetails) MarshalJSON() ([]byte, error) { + type wrapper VMmDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmDetails: %+v", err) + } + decoded["instanceType"] = "VMM" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwaredetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwaredetails.go new file mode 100644 index 00000000000..ff61dc7f3c5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwaredetails.go @@ -0,0 +1,73 @@ +package replicationfabrics + +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 _ FabricSpecificDetails = VMwareDetails{} + +type VMwareDetails struct { + AgentCount *string `json:"agentCount,omitempty"` + AgentExpiryDate *string `json:"agentExpiryDate,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + AgentVersionDetails *VersionDetails `json:"agentVersionDetails,omitempty"` + AvailableMemoryInBytes *int64 `json:"availableMemoryInBytes,omitempty"` + AvailableSpaceInBytes *int64 `json:"availableSpaceInBytes,omitempty"` + CpuLoad *string `json:"cpuLoad,omitempty"` + CpuLoadStatus *string `json:"cpuLoadStatus,omitempty"` + CsServiceStatus *string `json:"csServiceStatus,omitempty"` + DatabaseServerLoad *string `json:"databaseServerLoad,omitempty"` + DatabaseServerLoadStatus *string `json:"databaseServerLoadStatus,omitempty"` + HostName *string `json:"hostName,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + LastHeartbeat *string `json:"lastHeartbeat,omitempty"` + MasterTargetServers *[]MasterTargetServer `json:"masterTargetServers,omitempty"` + MemoryUsageStatus *string `json:"memoryUsageStatus,omitempty"` + ProcessServerCount *string `json:"processServerCount,omitempty"` + ProcessServers *[]ProcessServer `json:"processServers,omitempty"` + ProtectedServers *string `json:"protectedServers,omitempty"` + PsTemplateVersion *string `json:"psTemplateVersion,omitempty"` + ReplicationPairCount *string `json:"replicationPairCount,omitempty"` + RunAsAccounts *[]RunAsAccount `json:"runAsAccounts,omitempty"` + SpaceUsageStatus *string `json:"spaceUsageStatus,omitempty"` + SslCertExpiryDate *string `json:"sslCertExpiryDate,omitempty"` + SslCertExpiryRemainingDays *int64 `json:"sslCertExpiryRemainingDays,omitempty"` + SwitchProviderBlockingErrorDetails *[]InMageFabricSwitchProviderBlockingErrorDetails `json:"switchProviderBlockingErrorDetails,omitempty"` + SystemLoad *string `json:"systemLoad,omitempty"` + SystemLoadStatus *string `json:"systemLoadStatus,omitempty"` + TotalMemoryInBytes *int64 `json:"totalMemoryInBytes,omitempty"` + TotalSpaceInBytes *int64 `json:"totalSpaceInBytes,omitempty"` + VersionStatus *string `json:"versionStatus,omitempty"` + WebLoad *string `json:"webLoad,omitempty"` + WebLoadStatus *string `json:"webLoadStatus,omitempty"` + + // Fields inherited from FabricSpecificDetails +} + +var _ json.Marshaler = VMwareDetails{} + +func (s VMwareDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareDetails: %+v", err) + } + decoded["instanceType"] = "VMware" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwarev2fabriccreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwarev2fabriccreationinput.go new file mode 100644 index 00000000000..0c0e41a8b05 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwarev2fabriccreationinput.go @@ -0,0 +1,43 @@ +package replicationfabrics + +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 _ FabricSpecificCreationInput = VMwareV2FabricCreationInput{} + +type VMwareV2FabricCreationInput struct { + MigrationSolutionId string `json:"migrationSolutionId"` + PhysicalSiteId *string `json:"physicalSiteId,omitempty"` + VMwareSiteId *string `json:"vmwareSiteId,omitempty"` + + // Fields inherited from FabricSpecificCreationInput +} + +var _ json.Marshaler = VMwareV2FabricCreationInput{} + +func (s VMwareV2FabricCreationInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareV2FabricCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareV2FabricCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareV2FabricCreationInput: %+v", err) + } + decoded["instanceType"] = "VMwareV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareV2FabricCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwarev2fabricspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwarev2fabricspecificdetails.go new file mode 100644 index 00000000000..ea49db85b19 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/model_vmwarev2fabricspecificdetails.go @@ -0,0 +1,47 @@ +package replicationfabrics + +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 _ FabricSpecificDetails = VMwareV2FabricSpecificDetails{} + +type VMwareV2FabricSpecificDetails struct { + MigrationSolutionId *string `json:"migrationSolutionId,omitempty"` + PhysicalSiteId *string `json:"physicalSiteId,omitempty"` + ProcessServers *[]ProcessServerDetails `json:"processServers,omitempty"` + ServiceContainerId *string `json:"serviceContainerId,omitempty"` + ServiceEndpoint *string `json:"serviceEndpoint,omitempty"` + ServiceResourceId *string `json:"serviceResourceId,omitempty"` + VMwareSiteId *string `json:"vmwareSiteId,omitempty"` + + // Fields inherited from FabricSpecificDetails +} + +var _ json.Marshaler = VMwareV2FabricSpecificDetails{} + +func (s VMwareV2FabricSpecificDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareV2FabricSpecificDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareV2FabricSpecificDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareV2FabricSpecificDetails: %+v", err) + } + decoded["instanceType"] = "VMwareV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareV2FabricSpecificDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/predicates.go new file mode 100644 index 00000000000..8b9cb4978ce --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/predicates.go @@ -0,0 +1,32 @@ +package replicationfabrics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FabricOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p FabricOperationPredicate) Matches(input Fabric) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationfabrics/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/version.go new file mode 100644 index 00000000000..682f6bcdf6a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationfabrics/version.go @@ -0,0 +1,12 @@ +package replicationfabrics + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationfabrics/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/README.md new file mode 100644 index 00000000000..d68a9a30c16 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs` Documentation + +The `replicationjobs` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationjobs" +``` + + +### Client Initialization + +```go +client := replicationjobs.NewReplicationJobsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationJobsClient.Cancel` + +```go +ctx := context.TODO() +id := replicationjobs.NewReplicationJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationJobValue") + +if err := client.CancelThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationJobsClient.Export` + +```go +ctx := context.TODO() +id := replicationjobs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +payload := replicationjobs.JobQueryParameter{ + // ... +} + + +if err := client.ExportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationJobsClient.Get` + +```go +ctx := context.TODO() +id := replicationjobs.NewReplicationJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationJobValue") + +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: `ReplicationJobsClient.List` + +```go +ctx := context.TODO() +id := replicationjobs.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, replicationjobs.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, replicationjobs.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationJobsClient.Restart` + +```go +ctx := context.TODO() +id := replicationjobs.NewReplicationJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationJobValue") + +if err := client.RestartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationJobsClient.Resume` + +```go +ctx := context.TODO() +id := replicationjobs.NewReplicationJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationJobValue") + +payload := replicationjobs.ResumeJobParams{ + // ... +} + + +if err := client.ResumeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/client.go new file mode 100644 index 00000000000..01d23114dca --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/client.go @@ -0,0 +1,18 @@ +package replicationjobs + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationJobsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationJobsClientWithBaseURI(endpoint string) ReplicationJobsClient { + return ReplicationJobsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/constants.go new file mode 100644 index 00000000000..16d7fb774a3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/constants.go @@ -0,0 +1,37 @@ +package replicationjobs + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportJobOutputSerializationType string + +const ( + ExportJobOutputSerializationTypeExcel ExportJobOutputSerializationType = "Excel" + ExportJobOutputSerializationTypeJson ExportJobOutputSerializationType = "Json" + ExportJobOutputSerializationTypeXml ExportJobOutputSerializationType = "Xml" +) + +func PossibleValuesForExportJobOutputSerializationType() []string { + return []string{ + string(ExportJobOutputSerializationTypeExcel), + string(ExportJobOutputSerializationTypeJson), + string(ExportJobOutputSerializationTypeXml), + } +} + +func parseExportJobOutputSerializationType(input string) (*ExportJobOutputSerializationType, error) { + vals := map[string]ExportJobOutputSerializationType{ + "excel": ExportJobOutputSerializationTypeExcel, + "json": ExportJobOutputSerializationTypeJson, + "xml": ExportJobOutputSerializationTypeXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExportJobOutputSerializationType(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_replicationjob.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_replicationjob.go new file mode 100644 index 00000000000..7da0770af42 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_replicationjob.go @@ -0,0 +1,140 @@ +package replicationjobs + +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 = ReplicationJobId{} + +// ReplicationJobId is a struct representing the Resource ID for a Replication Job +type ReplicationJobId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationJobName string +} + +// NewReplicationJobID returns a new ReplicationJobId struct +func NewReplicationJobID(subscriptionId string, resourceGroupName string, vaultName string, replicationJobName string) ReplicationJobId { + return ReplicationJobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationJobName: replicationJobName, + } +} + +// ParseReplicationJobID parses 'input' into a ReplicationJobId +func ParseReplicationJobID(input string) (*ReplicationJobId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationJobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationJobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationJobName, ok = parsed.Parsed["replicationJobName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationJobName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationJobIDInsensitively parses 'input' case-insensitively into a ReplicationJobId +// note: this method should only be used for API response data and not user input +func ParseReplicationJobIDInsensitively(input string) (*ReplicationJobId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationJobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationJobId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationJobName, ok = parsed.Parsed["replicationJobName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationJobName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationJobID checks that 'input' can be parsed as a Replication Job ID +func ValidateReplicationJobID(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 := ParseReplicationJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Job ID +func (id ReplicationJobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationJobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationJobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Job ID +func (id ReplicationJobId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationJobs", "replicationJobs", "replicationJobs"), + resourceids.UserSpecifiedSegment("replicationJobName", "replicationJobValue"), + } +} + +// String returns a human-readable description of this Replication Job ID +func (id ReplicationJobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Job Name: %q", id.ReplicationJobName), + } + return fmt.Sprintf("Replication Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_replicationjob_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_replicationjob_test.go new file mode 100644 index 00000000000..47609dc34a4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_replicationjob_test.go @@ -0,0 +1,327 @@ +package replicationjobs + +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 = ReplicationJobId{} + +func TestNewReplicationJobID(t *testing.T) { + id := NewReplicationJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationJobValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationJobName != "replicationJobValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationJobName'", id.ReplicationJobName, "replicationJobValue") + } +} + +func TestFormatReplicationJobID(t *testing.T) { + actual := NewReplicationJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationJobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationJobs/replicationJobValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationJobId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationJobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationJobs/replicationJobValue", + Expected: &ReplicationJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationJobName: "replicationJobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationJobs/replicationJobValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationJobID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationJobName != v.Expected.ReplicationJobName { + t.Fatalf("Expected %q but got %q for ReplicationJobName", v.Expected.ReplicationJobName, actual.ReplicationJobName) + } + + } +} + +func TestParseReplicationJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationJobId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationJobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnJoBs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationJobs/replicationJobValue", + Expected: &ReplicationJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationJobName: "replicationJobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationJobs/replicationJobValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnJoBs/rEpLiCaTiOnJoBvAlUe", + Expected: &ReplicationJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationJobName: "rEpLiCaTiOnJoBvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnJoBs/rEpLiCaTiOnJoBvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationJobIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationJobName != v.Expected.ReplicationJobName { + t.Fatalf("Expected %q but got %q for ReplicationJobName", v.Expected.ReplicationJobName, actual.ReplicationJobName) + } + + } +} + +func TestSegmentsForReplicationJobId(t *testing.T) { + segments := ReplicationJobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationJobId 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/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_vault.go new file mode 100644 index 00000000000..870163be472 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_vault.go @@ -0,0 +1,127 @@ +package replicationjobs + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_vault_test.go new file mode 100644 index 00000000000..e8baf16e8c5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationjobs + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_cancel_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_cancel_autorest.go new file mode 100644 index 00000000000..2647df87471 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_cancel_autorest.go @@ -0,0 +1,78 @@ +package replicationjobs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CancelOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Cancel ... +func (c ReplicationJobsClient) Cancel(ctx context.Context, id ReplicationJobId) (result CancelOperationResponse, err error) { + req, err := c.preparerForCancel(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Cancel", nil, "Failure preparing request") + return + } + + result, err = c.senderForCancel(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Cancel", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CancelThenPoll performs Cancel then polls until it's completed +func (c ReplicationJobsClient) CancelThenPoll(ctx context.Context, id ReplicationJobId) error { + result, err := c.Cancel(ctx, id) + if err != nil { + return fmt.Errorf("performing Cancel: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Cancel: %+v", err) + } + + return nil +} + +// preparerForCancel prepares the Cancel request. +func (c ReplicationJobsClient) preparerForCancel(ctx context.Context, id ReplicationJobId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/cancel", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCancel sends the Cancel request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationJobsClient) senderForCancel(ctx context.Context, req *http.Request) (future CancelOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_export_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_export_autorest.go new file mode 100644 index 00000000000..127c729437f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_export_autorest.go @@ -0,0 +1,79 @@ +package replicationjobs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Export ... +func (c ReplicationJobsClient) Export(ctx context.Context, id VaultId, input JobQueryParameter) (result ExportOperationResponse, err error) { + req, err := c.preparerForExport(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Export", nil, "Failure preparing request") + return + } + + result, err = c.senderForExport(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Export", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ExportThenPoll performs Export then polls until it's completed +func (c ReplicationJobsClient) ExportThenPoll(ctx context.Context, id VaultId, input JobQueryParameter) error { + result, err := c.Export(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Export: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Export: %+v", err) + } + + return nil +} + +// preparerForExport prepares the Export request. +func (c ReplicationJobsClient) preparerForExport(ctx context.Context, id VaultId, input JobQueryParameter) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationJobs/export", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForExport sends the Export request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationJobsClient) senderForExport(ctx context.Context, req *http.Request) (future ExportOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_get_autorest.go new file mode 100644 index 00000000000..35e5be6fc2a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationjobs + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Job +} + +// Get ... +func (c ReplicationJobsClient) Get(ctx context.Context, id ReplicationJobId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationJobsClient) preparerForGet(ctx context.Context, id ReplicationJobId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationJobsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_list_autorest.go new file mode 100644 index 00000000000..66d9546c4df --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_list_autorest.go @@ -0,0 +1,215 @@ +package replicationjobs + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Job + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Job +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + return out +} + +// List ... +func (c ReplicationJobsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationJobsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationJobs", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationJobsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationJobsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Job `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationJobsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, JobOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationJobsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate JobOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Job, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_restart_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_restart_autorest.go new file mode 100644 index 00000000000..7bd12ac0d22 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_restart_autorest.go @@ -0,0 +1,78 @@ +package replicationjobs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestartOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Restart ... +func (c ReplicationJobsClient) Restart(ctx context.Context, id ReplicationJobId) (result RestartOperationResponse, err error) { + req, err := c.preparerForRestart(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Restart", nil, "Failure preparing request") + return + } + + result, err = c.senderForRestart(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Restart", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RestartThenPoll performs Restart then polls until it's completed +func (c ReplicationJobsClient) RestartThenPoll(ctx context.Context, id ReplicationJobId) error { + result, err := c.Restart(ctx, id) + if err != nil { + return fmt.Errorf("performing Restart: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Restart: %+v", err) + } + + return nil +} + +// preparerForRestart prepares the Restart request. +func (c ReplicationJobsClient) preparerForRestart(ctx context.Context, id ReplicationJobId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/restart", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRestart sends the Restart request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationJobsClient) senderForRestart(ctx context.Context, req *http.Request) (future RestartOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_resume_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_resume_autorest.go new file mode 100644 index 00000000000..1cd5a3076d3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/method_resume_autorest.go @@ -0,0 +1,79 @@ +package replicationjobs + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Resume ... +func (c ReplicationJobsClient) Resume(ctx context.Context, id ReplicationJobId, input ResumeJobParams) (result ResumeOperationResponse, err error) { + req, err := c.preparerForResume(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Resume", nil, "Failure preparing request") + return + } + + result, err = c.senderForResume(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationjobs.ReplicationJobsClient", "Resume", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ResumeThenPoll performs Resume then polls until it's completed +func (c ReplicationJobsClient) ResumeThenPoll(ctx context.Context, id ReplicationJobId, input ResumeJobParams) error { + result, err := c.Resume(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Resume: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Resume: %+v", err) + } + + return nil +} + +// preparerForResume prepares the Resume request. +func (c ReplicationJobsClient) preparerForResume(ctx context.Context, id ReplicationJobId, input ResumeJobParams) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/resume", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForResume sends the Resume request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationJobsClient) senderForResume(ctx context.Context, req *http.Request) (future ResumeOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_asrjobdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_asrjobdetails.go new file mode 100644 index 00000000000..613b2519e8b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_asrjobdetails.go @@ -0,0 +1,41 @@ +package replicationjobs + +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 _ JobDetails = AsrJobDetails{} + +type AsrJobDetails struct { + + // Fields inherited from JobDetails + AffectedObjectDetails *map[string]string `json:"affectedObjectDetails,omitempty"` +} + +var _ json.Marshaler = AsrJobDetails{} + +func (s AsrJobDetails) MarshalJSON() ([]byte, error) { + type wrapper AsrJobDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AsrJobDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AsrJobDetails: %+v", err) + } + decoded["instanceType"] = "AsrJobDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AsrJobDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_asrtask.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_asrtask.go new file mode 100644 index 00000000000..6837661d7bf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_asrtask.go @@ -0,0 +1,94 @@ +package replicationjobs + +import ( + "encoding/json" + "fmt" + "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 ASRTask struct { + AllowedActions *[]string `json:"allowedActions,omitempty"` + CustomDetails TaskTypeDetails `json:"customDetails"` + EndTime *string `json:"endTime,omitempty"` + Errors *[]JobErrorDetails `json:"errors,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + GroupTaskCustomDetails GroupTaskDetails `json:"groupTaskCustomDetails"` + Name *string `json:"name,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *string `json:"state,omitempty"` + StateDescription *string `json:"stateDescription,omitempty"` + TaskId *string `json:"taskId,omitempty"` + TaskType *string `json:"taskType,omitempty"` +} + +func (o *ASRTask) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ASRTask) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *ASRTask) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ASRTask) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Unmarshaler = &ASRTask{} + +func (s *ASRTask) UnmarshalJSON(bytes []byte) error { + type alias ASRTask + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ASRTask: %+v", err) + } + + s.AllowedActions = decoded.AllowedActions + s.EndTime = decoded.EndTime + s.Errors = decoded.Errors + s.FriendlyName = decoded.FriendlyName + s.Name = decoded.Name + s.StartTime = decoded.StartTime + s.State = decoded.State + s.StateDescription = decoded.StateDescription + s.TaskId = decoded.TaskId + s.TaskType = decoded.TaskType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ASRTask into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customDetails"]; ok { + impl, err := unmarshalTaskTypeDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomDetails' for 'ASRTask': %+v", err) + } + s.CustomDetails = impl + } + + if v, ok := temp["groupTaskCustomDetails"]; ok { + impl, err := unmarshalGroupTaskDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'GroupTaskCustomDetails' for 'ASRTask': %+v", err) + } + s.GroupTaskCustomDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_automationrunbooktaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_automationrunbooktaskdetails.go new file mode 100644 index 00000000000..902491069ab --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_automationrunbooktaskdetails.go @@ -0,0 +1,49 @@ +package replicationjobs + +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 _ TaskTypeDetails = AutomationRunbookTaskDetails{} + +type AutomationRunbookTaskDetails struct { + AccountName *string `json:"accountName,omitempty"` + CloudServiceName *string `json:"cloudServiceName,omitempty"` + IsPrimarySideScript *bool `json:"isPrimarySideScript,omitempty"` + JobId *string `json:"jobId,omitempty"` + JobOutput *string `json:"jobOutput,omitempty"` + Name *string `json:"name,omitempty"` + RunbookId *string `json:"runbookId,omitempty"` + RunbookName *string `json:"runbookName,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + + // Fields inherited from TaskTypeDetails +} + +var _ json.Marshaler = AutomationRunbookTaskDetails{} + +func (s AutomationRunbookTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper AutomationRunbookTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AutomationRunbookTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AutomationRunbookTaskDetails: %+v", err) + } + decoded["instanceType"] = "AutomationRunbookTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AutomationRunbookTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_consistencychecktaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_consistencychecktaskdetails.go new file mode 100644 index 00000000000..2a2ee8d055d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_consistencychecktaskdetails.go @@ -0,0 +1,41 @@ +package replicationjobs + +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 _ TaskTypeDetails = ConsistencyCheckTaskDetails{} + +type ConsistencyCheckTaskDetails struct { + VMDetails *[]InconsistentVMDetails `json:"vmDetails,omitempty"` + + // Fields inherited from TaskTypeDetails +} + +var _ json.Marshaler = ConsistencyCheckTaskDetails{} + +func (s ConsistencyCheckTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper ConsistencyCheckTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ConsistencyCheckTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ConsistencyCheckTaskDetails: %+v", err) + } + decoded["instanceType"] = "ConsistencyCheckTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ConsistencyCheckTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_exportjobdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_exportjobdetails.go new file mode 100644 index 00000000000..eb560e96f4f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_exportjobdetails.go @@ -0,0 +1,43 @@ +package replicationjobs + +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 _ JobDetails = ExportJobDetails{} + +type ExportJobDetails struct { + BlobUri *string `json:"blobUri,omitempty"` + SasToken *string `json:"sasToken,omitempty"` + + // Fields inherited from JobDetails + AffectedObjectDetails *map[string]string `json:"affectedObjectDetails,omitempty"` +} + +var _ json.Marshaler = ExportJobDetails{} + +func (s ExportJobDetails) MarshalJSON() ([]byte, error) { + type wrapper ExportJobDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ExportJobDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ExportJobDetails: %+v", err) + } + decoded["instanceType"] = "ExportJobDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ExportJobDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_fabricreplicationgrouptaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_fabricreplicationgrouptaskdetails.go new file mode 100644 index 00000000000..36b762f33e1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_fabricreplicationgrouptaskdetails.go @@ -0,0 +1,43 @@ +package replicationjobs + +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 _ TaskTypeDetails = FabricReplicationGroupTaskDetails{} + +type FabricReplicationGroupTaskDetails struct { + SkippedReason *string `json:"skippedReason,omitempty"` + SkippedReasonString *string `json:"skippedReasonString,omitempty"` + + // Fields inherited from JobTaskDetails + JobTask *JobEntity `json:"jobTask,omitempty"` +} + +var _ json.Marshaler = FabricReplicationGroupTaskDetails{} + +func (s FabricReplicationGroupTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper FabricReplicationGroupTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FabricReplicationGroupTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FabricReplicationGroupTaskDetails: %+v", err) + } + decoded["instanceType"] = "FabricReplicationGroupTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FabricReplicationGroupTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_failoverjobdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_failoverjobdetails.go new file mode 100644 index 00000000000..ef618276ce2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_failoverjobdetails.go @@ -0,0 +1,42 @@ +package replicationjobs + +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 _ JobDetails = FailoverJobDetails{} + +type FailoverJobDetails struct { + ProtectedItemDetails *[]FailoverReplicationProtectedItemDetails `json:"protectedItemDetails,omitempty"` + + // Fields inherited from JobDetails + AffectedObjectDetails *map[string]string `json:"affectedObjectDetails,omitempty"` +} + +var _ json.Marshaler = FailoverJobDetails{} + +func (s FailoverJobDetails) MarshalJSON() ([]byte, error) { + type wrapper FailoverJobDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FailoverJobDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FailoverJobDetails: %+v", err) + } + decoded["instanceType"] = "FailoverJobDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FailoverJobDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_failoverreplicationprotecteditemdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_failoverreplicationprotecteditemdetails.go new file mode 100644 index 00000000000..8f28aeba2ed --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_failoverreplicationprotecteditemdetails.go @@ -0,0 +1,34 @@ +package replicationjobs + +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 FailoverReplicationProtectedItemDetails struct { + FriendlyName *string `json:"friendlyName,omitempty"` + Name *string `json:"name,omitempty"` + NetworkConnectionStatus *string `json:"networkConnectionStatus,omitempty"` + NetworkFriendlyName *string `json:"networkFriendlyName,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` + Subnet *string `json:"subnet,omitempty"` + TestVMFriendlyName *string `json:"testVmFriendlyName,omitempty"` + TestVMName *string `json:"testVmName,omitempty"` +} + +func (o *FailoverReplicationProtectedItemDetails) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *FailoverReplicationProtectedItemDetails) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_grouptaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_grouptaskdetails.go new file mode 100644 index 00000000000..a246e485454 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_grouptaskdetails.go @@ -0,0 +1,56 @@ +package replicationjobs + +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 GroupTaskDetails interface { +} + +func unmarshalGroupTaskDetailsImplementation(input []byte) (GroupTaskDetails, 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 GroupTaskDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "InlineWorkflowTaskDetails") { + var out InlineWorkflowTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InlineWorkflowTaskDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RecoveryPlanGroupTaskDetails") { + var out RecoveryPlanGroupTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanGroupTaskDetails: %+v", err) + } + return out, nil + } + + type RawGroupTaskDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawGroupTaskDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_inconsistentvmdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_inconsistentvmdetails.go new file mode 100644 index 00000000000..04192118e25 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_inconsistentvmdetails.go @@ -0,0 +1,11 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InconsistentVMDetails struct { + CloudName *string `json:"cloudName,omitempty"` + Details *[]string `json:"details,omitempty"` + ErrorIds *[]string `json:"errorIds,omitempty"` + VirtualMachineName *string `json:"vmName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_inlineworkflowtaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_inlineworkflowtaskdetails.go new file mode 100644 index 00000000000..1f7381153e8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_inlineworkflowtaskdetails.go @@ -0,0 +1,42 @@ +package replicationjobs + +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 _ GroupTaskDetails = InlineWorkflowTaskDetails{} + +type InlineWorkflowTaskDetails struct { + WorkflowIds *[]string `json:"workflowIds,omitempty"` + + // Fields inherited from GroupTaskDetails + ChildTasks *[]ASRTask `json:"childTasks,omitempty"` +} + +var _ json.Marshaler = InlineWorkflowTaskDetails{} + +func (s InlineWorkflowTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper InlineWorkflowTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InlineWorkflowTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InlineWorkflowTaskDetails: %+v", err) + } + decoded["instanceType"] = "InlineWorkflowTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InlineWorkflowTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_job.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_job.go new file mode 100644 index 00000000000..74a9debce1f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_job.go @@ -0,0 +1,12 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Job struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobdetails.go new file mode 100644 index 00000000000..0886ba5e263 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobdetails.go @@ -0,0 +1,80 @@ +package replicationjobs + +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 JobDetails interface { +} + +func unmarshalJobDetailsImplementation(input []byte) (JobDetails, 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 JobDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AsrJobDetails") { + var out AsrJobDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AsrJobDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ExportJobDetails") { + var out ExportJobDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ExportJobDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "FailoverJobDetails") { + var out FailoverJobDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FailoverJobDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SwitchProtectionJobDetails") { + var out SwitchProtectionJobDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SwitchProtectionJobDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "TestFailoverJobDetails") { + var out TestFailoverJobDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into TestFailoverJobDetails: %+v", err) + } + return out, nil + } + + type RawJobDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawJobDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobentity.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobentity.go new file mode 100644 index 00000000000..e3cbaea444e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobentity.go @@ -0,0 +1,13 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobEntity struct { + JobFriendlyName *string `json:"jobFriendlyName,omitempty"` + JobId *string `json:"jobId,omitempty"` + JobScenarioName *string `json:"jobScenarioName,omitempty"` + TargetInstanceType *string `json:"targetInstanceType,omitempty"` + TargetObjectId *string `json:"targetObjectId,omitempty"` + TargetObjectName *string `json:"targetObjectName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_joberrordetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_joberrordetails.go new file mode 100644 index 00000000000..797e2dc1bd1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_joberrordetails.go @@ -0,0 +1,30 @@ +package replicationjobs + +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 JobErrorDetails struct { + CreationTime *string `json:"creationTime,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ProviderErrorDetails *ProviderError `json:"providerErrorDetails,omitempty"` + ServiceErrorDetails *ServiceError `json:"serviceErrorDetails,omitempty"` + TaskId *string `json:"taskId,omitempty"` +} + +func (o *JobErrorDetails) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobErrorDetails) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobproperties.go new file mode 100644 index 00000000000..8e5b41fb325 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobproperties.go @@ -0,0 +1,91 @@ +package replicationjobs + +import ( + "encoding/json" + "fmt" + "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 JobProperties struct { + ActivityId *string `json:"activityId,omitempty"` + AllowedActions *[]string `json:"allowedActions,omitempty"` + CustomDetails JobDetails `json:"customDetails"` + EndTime *string `json:"endTime,omitempty"` + Errors *[]JobErrorDetails `json:"errors,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ScenarioName *string `json:"scenarioName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *string `json:"state,omitempty"` + StateDescription *string `json:"stateDescription,omitempty"` + TargetInstanceType *string `json:"targetInstanceType,omitempty"` + TargetObjectId *string `json:"targetObjectId,omitempty"` + TargetObjectName *string `json:"targetObjectName,omitempty"` + Tasks *[]ASRTask `json:"tasks,omitempty"` +} + +func (o *JobProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} + +var _ json.Unmarshaler = &JobProperties{} + +func (s *JobProperties) UnmarshalJSON(bytes []byte) error { + type alias JobProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into JobProperties: %+v", err) + } + + s.ActivityId = decoded.ActivityId + s.AllowedActions = decoded.AllowedActions + s.EndTime = decoded.EndTime + s.Errors = decoded.Errors + s.FriendlyName = decoded.FriendlyName + s.ScenarioName = decoded.ScenarioName + s.StartTime = decoded.StartTime + s.State = decoded.State + s.StateDescription = decoded.StateDescription + s.TargetInstanceType = decoded.TargetInstanceType + s.TargetObjectId = decoded.TargetObjectId + s.TargetObjectName = decoded.TargetObjectName + s.Tasks = decoded.Tasks + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JobProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customDetails"]; ok { + impl, err := unmarshalJobDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomDetails' for 'JobProperties': %+v", err) + } + s.CustomDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobqueryparameter.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobqueryparameter.go new file mode 100644 index 00000000000..bc10a6b6e1d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobqueryparameter.go @@ -0,0 +1,15 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobQueryParameter struct { + AffectedObjectTypes *string `json:"affectedObjectTypes,omitempty"` + EndTime *string `json:"endTime,omitempty"` + FabricId *string `json:"fabricId,omitempty"` + JobName *string `json:"jobName,omitempty"` + JobOutputType *ExportJobOutputSerializationType `json:"jobOutputType,omitempty"` + JobStatus *string `json:"jobStatus,omitempty"` + StartTime *string `json:"startTime,omitempty"` + TimezoneOffset *float64 `json:"timezoneOffset,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobtaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobtaskdetails.go new file mode 100644 index 00000000000..40a3d24c0d0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_jobtaskdetails.go @@ -0,0 +1,41 @@ +package replicationjobs + +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 _ TaskTypeDetails = JobTaskDetails{} + +type JobTaskDetails struct { + JobTask *JobEntity `json:"jobTask,omitempty"` + + // Fields inherited from TaskTypeDetails +} + +var _ json.Marshaler = JobTaskDetails{} + +func (s JobTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper JobTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JobTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JobTaskDetails: %+v", err) + } + decoded["instanceType"] = "JobTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JobTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_manualactiontaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_manualactiontaskdetails.go new file mode 100644 index 00000000000..9477eb93f5c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_manualactiontaskdetails.go @@ -0,0 +1,43 @@ +package replicationjobs + +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 _ TaskTypeDetails = ManualActionTaskDetails{} + +type ManualActionTaskDetails struct { + Instructions *string `json:"instructions,omitempty"` + Name *string `json:"name,omitempty"` + Observation *string `json:"observation,omitempty"` + + // Fields inherited from TaskTypeDetails +} + +var _ json.Marshaler = ManualActionTaskDetails{} + +func (s ManualActionTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper ManualActionTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ManualActionTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ManualActionTaskDetails: %+v", err) + } + decoded["instanceType"] = "ManualActionTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ManualActionTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_providererror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_providererror.go new file mode 100644 index 00000000000..e7f3a6131ee --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_providererror.go @@ -0,0 +1,12 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderError struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_recoveryplangrouptaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_recoveryplangrouptaskdetails.go new file mode 100644 index 00000000000..5a55423d4da --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_recoveryplangrouptaskdetails.go @@ -0,0 +1,44 @@ +package replicationjobs + +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 _ GroupTaskDetails = RecoveryPlanGroupTaskDetails{} + +type RecoveryPlanGroupTaskDetails struct { + GroupId *string `json:"groupId,omitempty"` + Name *string `json:"name,omitempty"` + RpGroupType *string `json:"rpGroupType,omitempty"` + + // Fields inherited from GroupTaskDetails + ChildTasks *[]ASRTask `json:"childTasks,omitempty"` +} + +var _ json.Marshaler = RecoveryPlanGroupTaskDetails{} + +func (s RecoveryPlanGroupTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanGroupTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanGroupTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanGroupTaskDetails: %+v", err) + } + decoded["instanceType"] = "RecoveryPlanGroupTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanGroupTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_recoveryplanshutdowngrouptaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_recoveryplanshutdowngrouptaskdetails.go new file mode 100644 index 00000000000..5ce8bf8aade --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_recoveryplanshutdowngrouptaskdetails.go @@ -0,0 +1,43 @@ +package replicationjobs + +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 _ GroupTaskDetails = RecoveryPlanShutdownGroupTaskDetails{} + +type RecoveryPlanShutdownGroupTaskDetails struct { + + // Fields inherited from RecoveryPlanGroupTaskDetails + GroupId *string `json:"groupId,omitempty"` + Name *string `json:"name,omitempty"` + RpGroupType *string `json:"rpGroupType,omitempty"` +} + +var _ json.Marshaler = RecoveryPlanShutdownGroupTaskDetails{} + +func (s RecoveryPlanShutdownGroupTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanShutdownGroupTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanShutdownGroupTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanShutdownGroupTaskDetails: %+v", err) + } + decoded["instanceType"] = "RecoveryPlanShutdownGroupTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanShutdownGroupTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_resumejobparams.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_resumejobparams.go new file mode 100644 index 00000000000..c247d0c303b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_resumejobparams.go @@ -0,0 +1,8 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeJobParams struct { + Properties *ResumeJobParamsProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_resumejobparamsproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_resumejobparamsproperties.go new file mode 100644 index 00000000000..a4dc002b22b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_resumejobparamsproperties.go @@ -0,0 +1,8 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeJobParamsProperties struct { + Comments *string `json:"comments,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_scriptactiontaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_scriptactiontaskdetails.go new file mode 100644 index 00000000000..cf231b16ade --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_scriptactiontaskdetails.go @@ -0,0 +1,44 @@ +package replicationjobs + +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 _ TaskTypeDetails = ScriptActionTaskDetails{} + +type ScriptActionTaskDetails struct { + IsPrimarySideScript *bool `json:"isPrimarySideScript,omitempty"` + Name *string `json:"name,omitempty"` + Output *string `json:"output,omitempty"` + Path *string `json:"path,omitempty"` + + // Fields inherited from TaskTypeDetails +} + +var _ json.Marshaler = ScriptActionTaskDetails{} + +func (s ScriptActionTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper ScriptActionTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ScriptActionTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ScriptActionTaskDetails: %+v", err) + } + decoded["instanceType"] = "ScriptActionTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ScriptActionTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_serviceerror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_serviceerror.go new file mode 100644 index 00000000000..1ce1b446dc8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_serviceerror.go @@ -0,0 +1,12 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceError struct { + ActivityId *string `json:"activityId,omitempty"` + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_switchprotectionjobdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_switchprotectionjobdetails.go new file mode 100644 index 00000000000..31c8d2201f6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_switchprotectionjobdetails.go @@ -0,0 +1,42 @@ +package replicationjobs + +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 _ JobDetails = SwitchProtectionJobDetails{} + +type SwitchProtectionJobDetails struct { + NewReplicationProtectedItemId *string `json:"newReplicationProtectedItemId,omitempty"` + + // Fields inherited from JobDetails + AffectedObjectDetails *map[string]string `json:"affectedObjectDetails,omitempty"` +} + +var _ json.Marshaler = SwitchProtectionJobDetails{} + +func (s SwitchProtectionJobDetails) MarshalJSON() ([]byte, error) { + type wrapper SwitchProtectionJobDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SwitchProtectionJobDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SwitchProtectionJobDetails: %+v", err) + } + decoded["instanceType"] = "SwitchProtectionJobDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SwitchProtectionJobDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_tasktypedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_tasktypedetails.go new file mode 100644 index 00000000000..ae90fad9b00 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_tasktypedetails.go @@ -0,0 +1,88 @@ +package replicationjobs + +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 TaskTypeDetails interface { +} + +func unmarshalTaskTypeDetailsImplementation(input []byte) (TaskTypeDetails, 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 TaskTypeDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AutomationRunbookTaskDetails") { + var out AutomationRunbookTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AutomationRunbookTaskDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ConsistencyCheckTaskDetails") { + var out ConsistencyCheckTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ConsistencyCheckTaskDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "JobTaskDetails") { + var out JobTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JobTaskDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ManualActionTaskDetails") { + var out ManualActionTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ManualActionTaskDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ScriptActionTaskDetails") { + var out ScriptActionTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ScriptActionTaskDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VmNicUpdatesTaskDetails") { + var out VMNicUpdatesTaskDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMNicUpdatesTaskDetails: %+v", err) + } + return out, nil + } + + type RawTaskTypeDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawTaskTypeDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_testfailoverjobdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_testfailoverjobdetails.go new file mode 100644 index 00000000000..63502161e0a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_testfailoverjobdetails.go @@ -0,0 +1,47 @@ +package replicationjobs + +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 _ JobDetails = TestFailoverJobDetails{} + +type TestFailoverJobDetails struct { + Comments *string `json:"comments,omitempty"` + NetworkFriendlyName *string `json:"networkFriendlyName,omitempty"` + NetworkName *string `json:"networkName,omitempty"` + NetworkType *string `json:"networkType,omitempty"` + ProtectedItemDetails *[]FailoverReplicationProtectedItemDetails `json:"protectedItemDetails,omitempty"` + TestFailoverStatus *string `json:"testFailoverStatus,omitempty"` + + // Fields inherited from JobDetails + AffectedObjectDetails *map[string]string `json:"affectedObjectDetails,omitempty"` +} + +var _ json.Marshaler = TestFailoverJobDetails{} + +func (s TestFailoverJobDetails) MarshalJSON() ([]byte, error) { + type wrapper TestFailoverJobDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling TestFailoverJobDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling TestFailoverJobDetails: %+v", err) + } + decoded["instanceType"] = "TestFailoverJobDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling TestFailoverJobDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_virtualmachinetaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_virtualmachinetaskdetails.go new file mode 100644 index 00000000000..42726d08363 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_virtualmachinetaskdetails.go @@ -0,0 +1,43 @@ +package replicationjobs + +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 _ TaskTypeDetails = VirtualMachineTaskDetails{} + +type VirtualMachineTaskDetails struct { + SkippedReason *string `json:"skippedReason,omitempty"` + SkippedReasonString *string `json:"skippedReasonString,omitempty"` + + // Fields inherited from JobTaskDetails + JobTask *JobEntity `json:"jobTask,omitempty"` +} + +var _ json.Marshaler = VirtualMachineTaskDetails{} + +func (s VirtualMachineTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper VirtualMachineTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VirtualMachineTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VirtualMachineTaskDetails: %+v", err) + } + decoded["instanceType"] = "VirtualMachineTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VirtualMachineTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_vmnicupdatestaskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_vmnicupdatestaskdetails.go new file mode 100644 index 00000000000..ea5fa8cb61a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/model_vmnicupdatestaskdetails.go @@ -0,0 +1,43 @@ +package replicationjobs + +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 _ TaskTypeDetails = VMNicUpdatesTaskDetails{} + +type VMNicUpdatesTaskDetails struct { + Name *string `json:"name,omitempty"` + NicId *string `json:"nicId,omitempty"` + VMId *string `json:"vmId,omitempty"` + + // Fields inherited from TaskTypeDetails +} + +var _ json.Marshaler = VMNicUpdatesTaskDetails{} + +func (s VMNicUpdatesTaskDetails) MarshalJSON() ([]byte, error) { + type wrapper VMNicUpdatesTaskDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMNicUpdatesTaskDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMNicUpdatesTaskDetails: %+v", err) + } + decoded["instanceType"] = "VmNicUpdatesTaskDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMNicUpdatesTaskDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/predicates.go new file mode 100644 index 00000000000..aaaf2a4a501 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/predicates.go @@ -0,0 +1,32 @@ +package replicationjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p JobOperationPredicate) Matches(input Job) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationjobs/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/version.go new file mode 100644 index 00000000000..48de40bff28 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationjobs/version.go @@ -0,0 +1,12 @@ +package replicationjobs + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationjobs/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/README.md new file mode 100644 index 00000000000..221427ed624 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks` Documentation + +The `replicationlogicalnetworks` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks" +``` + + +### Client Initialization + +```go +client := replicationlogicalnetworks.NewReplicationLogicalNetworksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationLogicalNetworksClient.Get` + +```go +ctx := context.TODO() +id := replicationlogicalnetworks.NewReplicationLogicalNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationLogicalNetworkValue") + +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: `ReplicationLogicalNetworksClient.ListByReplicationFabrics` + +```go +ctx := context.TODO() +id := replicationlogicalnetworks.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +// alternatively `client.ListByReplicationFabrics(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationFabricsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/client.go new file mode 100644 index 00000000000..11c2e3f1dcc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/client.go @@ -0,0 +1,18 @@ +package replicationlogicalnetworks + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLogicalNetworksClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationLogicalNetworksClientWithBaseURI(endpoint string) ReplicationLogicalNetworksClient { + return ReplicationLogicalNetworksClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationfabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationfabric.go new file mode 100644 index 00000000000..e28a16cc19c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationlogicalnetworks + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationfabric_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationfabric_test.go new file mode 100644 index 00000000000..88108146528 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationfabric_test.go @@ -0,0 +1,327 @@ +package replicationlogicalnetworks + +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 = ReplicationFabricId{} + +func TestNewReplicationFabricID(t *testing.T) { + id := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } +} + +func TestFormatReplicationFabricID(t *testing.T) { + actual := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestParseReplicationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestSegmentsForReplicationFabricId(t *testing.T) { + segments := ReplicationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationFabricId 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/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationlogicalnetwork.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationlogicalnetwork.go new file mode 100644 index 00000000000..1bbb1abceae --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationlogicalnetwork.go @@ -0,0 +1,153 @@ +package replicationlogicalnetworks + +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 = ReplicationLogicalNetworkId{} + +// ReplicationLogicalNetworkId is a struct representing the Resource ID for a Replication Logical Network +type ReplicationLogicalNetworkId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationLogicalNetworkName string +} + +// NewReplicationLogicalNetworkID returns a new ReplicationLogicalNetworkId struct +func NewReplicationLogicalNetworkID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationLogicalNetworkName string) ReplicationLogicalNetworkId { + return ReplicationLogicalNetworkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationLogicalNetworkName: replicationLogicalNetworkName, + } +} + +// ParseReplicationLogicalNetworkID parses 'input' into a ReplicationLogicalNetworkId +func ParseReplicationLogicalNetworkID(input string) (*ReplicationLogicalNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationLogicalNetworkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationLogicalNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationLogicalNetworkName, ok = parsed.Parsed["replicationLogicalNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationLogicalNetworkName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationLogicalNetworkIDInsensitively parses 'input' case-insensitively into a ReplicationLogicalNetworkId +// note: this method should only be used for API response data and not user input +func ParseReplicationLogicalNetworkIDInsensitively(input string) (*ReplicationLogicalNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationLogicalNetworkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationLogicalNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationLogicalNetworkName, ok = parsed.Parsed["replicationLogicalNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationLogicalNetworkName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationLogicalNetworkID checks that 'input' can be parsed as a Replication Logical Network ID +func ValidateReplicationLogicalNetworkID(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 := ParseReplicationLogicalNetworkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Logical Network ID +func (id ReplicationLogicalNetworkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationLogicalNetworks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationLogicalNetworkName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Logical Network ID +func (id ReplicationLogicalNetworkId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationLogicalNetworks", "replicationLogicalNetworks", "replicationLogicalNetworks"), + resourceids.UserSpecifiedSegment("replicationLogicalNetworkName", "replicationLogicalNetworkValue"), + } +} + +// String returns a human-readable description of this Replication Logical Network ID +func (id ReplicationLogicalNetworkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Logical Network Name: %q", id.ReplicationLogicalNetworkName), + } + return fmt.Sprintf("Replication Logical Network (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationlogicalnetwork_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationlogicalnetwork_test.go new file mode 100644 index 00000000000..c266ec2e14d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/id_replicationlogicalnetwork_test.go @@ -0,0 +1,372 @@ +package replicationlogicalnetworks + +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 = ReplicationLogicalNetworkId{} + +func TestNewReplicationLogicalNetworkID(t *testing.T) { + id := NewReplicationLogicalNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationLogicalNetworkValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationLogicalNetworkName != "replicationLogicalNetworkValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationLogicalNetworkName'", id.ReplicationLogicalNetworkName, "replicationLogicalNetworkValue") + } +} + +func TestFormatReplicationLogicalNetworkID(t *testing.T) { + actual := NewReplicationLogicalNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationLogicalNetworkValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationLogicalNetworks/replicationLogicalNetworkValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationLogicalNetworkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationLogicalNetworkId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationLogicalNetworks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationLogicalNetworks/replicationLogicalNetworkValue", + Expected: &ReplicationLogicalNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationLogicalNetworkName: "replicationLogicalNetworkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationLogicalNetworks/replicationLogicalNetworkValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationLogicalNetworkID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationLogicalNetworkName != v.Expected.ReplicationLogicalNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationLogicalNetworkName", v.Expected.ReplicationLogicalNetworkName, actual.ReplicationLogicalNetworkName) + } + + } +} + +func TestParseReplicationLogicalNetworkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationLogicalNetworkId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationLogicalNetworks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnLoGiCaLnEtWoRkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationLogicalNetworks/replicationLogicalNetworkValue", + Expected: &ReplicationLogicalNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationLogicalNetworkName: "replicationLogicalNetworkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationLogicalNetworks/replicationLogicalNetworkValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnLoGiCaLnEtWoRkS/rEpLiCaTiOnLoGiCaLnEtWoRkVaLuE", + Expected: &ReplicationLogicalNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationLogicalNetworkName: "rEpLiCaTiOnLoGiCaLnEtWoRkVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnLoGiCaLnEtWoRkS/rEpLiCaTiOnLoGiCaLnEtWoRkVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationLogicalNetworkIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationLogicalNetworkName != v.Expected.ReplicationLogicalNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationLogicalNetworkName", v.Expected.ReplicationLogicalNetworkName, actual.ReplicationLogicalNetworkName) + } + + } +} + +func TestSegmentsForReplicationLogicalNetworkId(t *testing.T) { + segments := ReplicationLogicalNetworkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationLogicalNetworkId 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/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/method_get_autorest.go new file mode 100644 index 00000000000..49beaf8d595 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationlogicalnetworks + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *LogicalNetwork +} + +// Get ... +func (c ReplicationLogicalNetworksClient) Get(ctx context.Context, id ReplicationLogicalNetworkId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationLogicalNetworksClient) preparerForGet(ctx context.Context, id ReplicationLogicalNetworkId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationLogicalNetworksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/method_listbyreplicationfabrics_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/method_listbyreplicationfabrics_autorest.go new file mode 100644 index 00000000000..c3036462d03 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/method_listbyreplicationfabrics_autorest.go @@ -0,0 +1,186 @@ +package replicationlogicalnetworks + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationFabricsOperationResponse struct { + HttpResponse *http.Response + Model *[]LogicalNetwork + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationFabricsOperationResponse, error) +} + +type ListByReplicationFabricsCompleteResult struct { + Items []LogicalNetwork +} + +func (r ListByReplicationFabricsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationFabricsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationFabricsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationFabrics ... +func (c ReplicationLogicalNetworksClient) ListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (resp ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabrics(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationFabrics(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationFabrics prepares the ListByReplicationFabrics request. +func (c ReplicationLogicalNetworksClient) preparerForListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationLogicalNetworks", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationFabricsWithNextLink prepares the ListByReplicationFabrics request with the given nextLink token. +func (c ReplicationLogicalNetworksClient) preparerForListByReplicationFabricsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationFabrics handles the response to the ListByReplicationFabrics request. The method always +// closes the http.Response Body. +func (c ReplicationLogicalNetworksClient) responderForListByReplicationFabrics(resp *http.Response) (result ListByReplicationFabricsOperationResponse, err error) { + type page struct { + Values []LogicalNetwork `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabricsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "ListByReplicationFabrics", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationFabrics(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationlogicalnetworks.ReplicationLogicalNetworksClient", "ListByReplicationFabrics", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationFabricsComplete retrieves all of the results into a single object +func (c ReplicationLogicalNetworksClient) ListByReplicationFabricsComplete(ctx context.Context, id ReplicationFabricId) (ListByReplicationFabricsCompleteResult, error) { + return c.ListByReplicationFabricsCompleteMatchingPredicate(ctx, id, LogicalNetworkOperationPredicate{}) +} + +// ListByReplicationFabricsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationLogicalNetworksClient) ListByReplicationFabricsCompleteMatchingPredicate(ctx context.Context, id ReplicationFabricId, predicate LogicalNetworkOperationPredicate) (resp ListByReplicationFabricsCompleteResult, err error) { + items := make([]LogicalNetwork, 0) + + page, err := c.ListByReplicationFabrics(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationFabricsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/model_logicalnetwork.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/model_logicalnetwork.go new file mode 100644 index 00000000000..957182ab3db --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/model_logicalnetwork.go @@ -0,0 +1,12 @@ +package replicationlogicalnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogicalNetwork struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *LogicalNetworkProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/model_logicalnetworkproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/model_logicalnetworkproperties.go new file mode 100644 index 00000000000..2200c344760 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/model_logicalnetworkproperties.go @@ -0,0 +1,11 @@ +package replicationlogicalnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogicalNetworkProperties struct { + FriendlyName *string `json:"friendlyName,omitempty"` + LogicalNetworkDefinitionsStatus *string `json:"logicalNetworkDefinitionsStatus,omitempty"` + LogicalNetworkUsage *string `json:"logicalNetworkUsage,omitempty"` + NetworkVirtualizationStatus *string `json:"networkVirtualizationStatus,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/predicates.go new file mode 100644 index 00000000000..35d419d424a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/predicates.go @@ -0,0 +1,32 @@ +package replicationlogicalnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogicalNetworkOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p LogicalNetworkOperationPredicate) Matches(input LogicalNetwork) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/version.go new file mode 100644 index 00000000000..28676055b54 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationlogicalnetworks/version.go @@ -0,0 +1,12 @@ +package replicationlogicalnetworks + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationlogicalnetworks/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/README.md new file mode 100644 index 00000000000..0e8623ea368 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/README.md @@ -0,0 +1,218 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems` Documentation + +The `replicationmigrationitems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems" +``` + + +### Client Initialization + +```go +client := replicationmigrationitems.NewReplicationMigrationItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationMigrationItemsClient.Create` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.EnableMigrationInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.Delete` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +if err := client.DeleteThenPoll(ctx, id, replicationmigrationitems.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.Get` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +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: `ReplicationMigrationItemsClient.List` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, replicationmigrationitems.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, replicationmigrationitems.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.ListByReplicationProtectionContainers` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +// alternatively `client.ListByReplicationProtectionContainers(ctx, id, replicationmigrationitems.DefaultListByReplicationProtectionContainersOperationOptions())` can be used to do batched pagination +items, err := client.ListByReplicationProtectionContainersComplete(ctx, id, replicationmigrationitems.DefaultListByReplicationProtectionContainersOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.Migrate` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.MigrateInput{ + // ... +} + + +if err := client.MigrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.PauseReplication` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.PauseReplicationInput{ + // ... +} + + +if err := client.PauseReplicationThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.ResumeReplication` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.ResumeReplicationInput{ + // ... +} + + +if err := client.ResumeReplicationThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.Resync` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.ResyncInput{ + // ... +} + + +if err := client.ResyncThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.TestMigrate` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.TestMigrateInput{ + // ... +} + + +if err := client.TestMigrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.TestMigrateCleanup` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.TestMigrateCleanupInput{ + // ... +} + + +if err := client.TestMigrateCleanupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationMigrationItemsClient.Update` + +```go +ctx := context.TODO() +id := replicationmigrationitems.NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + +payload := replicationmigrationitems.UpdateMigrationItemInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/client.go new file mode 100644 index 00000000000..d2ec77c3f8b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/client.go @@ -0,0 +1,18 @@ +package replicationmigrationitems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationMigrationItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationMigrationItemsClientWithBaseURI(endpoint string) ReplicationMigrationItemsClient { + return ReplicationMigrationItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/constants.go new file mode 100644 index 00000000000..513503aeabc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/constants.go @@ -0,0 +1,413 @@ +package replicationmigrationitems + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskAccountType string + +const ( + DiskAccountTypePremiumLRS DiskAccountType = "Premium_LRS" + DiskAccountTypeStandardLRS DiskAccountType = "Standard_LRS" + DiskAccountTypeStandardSSDLRS DiskAccountType = "StandardSSD_LRS" +) + +func PossibleValuesForDiskAccountType() []string { + return []string{ + string(DiskAccountTypePremiumLRS), + string(DiskAccountTypeStandardLRS), + string(DiskAccountTypeStandardSSDLRS), + } +} + +func parseDiskAccountType(input string) (*DiskAccountType, error) { + vals := map[string]DiskAccountType{ + "premium_lrs": DiskAccountTypePremiumLRS, + "standard_lrs": DiskAccountTypeStandardLRS, + "standardssd_lrs": DiskAccountTypeStandardSSDLRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiskAccountType(input) + return &out, nil +} + +type EthernetAddressType string + +const ( + EthernetAddressTypeDynamic EthernetAddressType = "Dynamic" + EthernetAddressTypeStatic EthernetAddressType = "Static" +) + +func PossibleValuesForEthernetAddressType() []string { + return []string{ + string(EthernetAddressTypeDynamic), + string(EthernetAddressTypeStatic), + } +} + +func parseEthernetAddressType(input string) (*EthernetAddressType, error) { + vals := map[string]EthernetAddressType{ + "dynamic": EthernetAddressTypeDynamic, + "static": EthernetAddressTypeStatic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EthernetAddressType(input) + return &out, nil +} + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} + +type LicenseType string + +const ( + LicenseTypeNoLicenseType LicenseType = "NoLicenseType" + LicenseTypeNotSpecified LicenseType = "NotSpecified" + LicenseTypeWindowsServer LicenseType = "WindowsServer" +) + +func PossibleValuesForLicenseType() []string { + return []string{ + string(LicenseTypeNoLicenseType), + string(LicenseTypeNotSpecified), + string(LicenseTypeWindowsServer), + } +} + +func parseLicenseType(input string) (*LicenseType, error) { + vals := map[string]LicenseType{ + "nolicensetype": LicenseTypeNoLicenseType, + "notspecified": LicenseTypeNotSpecified, + "windowsserver": LicenseTypeWindowsServer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseType(input) + return &out, nil +} + +type MigrationItemOperation string + +const ( + MigrationItemOperationDisableMigration MigrationItemOperation = "DisableMigration" + MigrationItemOperationMigrate MigrationItemOperation = "Migrate" + MigrationItemOperationPauseReplication MigrationItemOperation = "PauseReplication" + MigrationItemOperationResumeReplication MigrationItemOperation = "ResumeReplication" + MigrationItemOperationStartResync MigrationItemOperation = "StartResync" + MigrationItemOperationTestMigrate MigrationItemOperation = "TestMigrate" + MigrationItemOperationTestMigrateCleanup MigrationItemOperation = "TestMigrateCleanup" +) + +func PossibleValuesForMigrationItemOperation() []string { + return []string{ + string(MigrationItemOperationDisableMigration), + string(MigrationItemOperationMigrate), + string(MigrationItemOperationPauseReplication), + string(MigrationItemOperationResumeReplication), + string(MigrationItemOperationStartResync), + string(MigrationItemOperationTestMigrate), + string(MigrationItemOperationTestMigrateCleanup), + } +} + +func parseMigrationItemOperation(input string) (*MigrationItemOperation, error) { + vals := map[string]MigrationItemOperation{ + "disablemigration": MigrationItemOperationDisableMigration, + "migrate": MigrationItemOperationMigrate, + "pausereplication": MigrationItemOperationPauseReplication, + "resumereplication": MigrationItemOperationResumeReplication, + "startresync": MigrationItemOperationStartResync, + "testmigrate": MigrationItemOperationTestMigrate, + "testmigratecleanup": MigrationItemOperationTestMigrateCleanup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MigrationItemOperation(input) + return &out, nil +} + +type MigrationState string + +const ( + MigrationStateDisableMigrationFailed MigrationState = "DisableMigrationFailed" + MigrationStateDisableMigrationInProgress MigrationState = "DisableMigrationInProgress" + MigrationStateEnableMigrationFailed MigrationState = "EnableMigrationFailed" + MigrationStateEnableMigrationInProgress MigrationState = "EnableMigrationInProgress" + MigrationStateInitialSeedingFailed MigrationState = "InitialSeedingFailed" + MigrationStateInitialSeedingInProgress MigrationState = "InitialSeedingInProgress" + MigrationStateMigrationCompletedWithInformation MigrationState = "MigrationCompletedWithInformation" + MigrationStateMigrationFailed MigrationState = "MigrationFailed" + MigrationStateMigrationInProgress MigrationState = "MigrationInProgress" + MigrationStateMigrationPartiallySucceeded MigrationState = "MigrationPartiallySucceeded" + MigrationStateMigrationSucceeded MigrationState = "MigrationSucceeded" + MigrationStateNone MigrationState = "None" + MigrationStateProtectionSuspended MigrationState = "ProtectionSuspended" + MigrationStateReplicating MigrationState = "Replicating" + MigrationStateResumeInProgress MigrationState = "ResumeInProgress" + MigrationStateResumeInitiated MigrationState = "ResumeInitiated" + MigrationStateSuspendingProtection MigrationState = "SuspendingProtection" +) + +func PossibleValuesForMigrationState() []string { + return []string{ + string(MigrationStateDisableMigrationFailed), + string(MigrationStateDisableMigrationInProgress), + string(MigrationStateEnableMigrationFailed), + string(MigrationStateEnableMigrationInProgress), + string(MigrationStateInitialSeedingFailed), + string(MigrationStateInitialSeedingInProgress), + string(MigrationStateMigrationCompletedWithInformation), + string(MigrationStateMigrationFailed), + string(MigrationStateMigrationInProgress), + string(MigrationStateMigrationPartiallySucceeded), + string(MigrationStateMigrationSucceeded), + string(MigrationStateNone), + string(MigrationStateProtectionSuspended), + string(MigrationStateReplicating), + string(MigrationStateResumeInProgress), + string(MigrationStateResumeInitiated), + string(MigrationStateSuspendingProtection), + } +} + +func parseMigrationState(input string) (*MigrationState, error) { + vals := map[string]MigrationState{ + "disablemigrationfailed": MigrationStateDisableMigrationFailed, + "disablemigrationinprogress": MigrationStateDisableMigrationInProgress, + "enablemigrationfailed": MigrationStateEnableMigrationFailed, + "enablemigrationinprogress": MigrationStateEnableMigrationInProgress, + "initialseedingfailed": MigrationStateInitialSeedingFailed, + "initialseedinginprogress": MigrationStateInitialSeedingInProgress, + "migrationcompletedwithinformation": MigrationStateMigrationCompletedWithInformation, + "migrationfailed": MigrationStateMigrationFailed, + "migrationinprogress": MigrationStateMigrationInProgress, + "migrationpartiallysucceeded": MigrationStateMigrationPartiallySucceeded, + "migrationsucceeded": MigrationStateMigrationSucceeded, + "none": MigrationStateNone, + "protectionsuspended": MigrationStateProtectionSuspended, + "replicating": MigrationStateReplicating, + "resumeinprogress": MigrationStateResumeInProgress, + "resumeinitiated": MigrationStateResumeInitiated, + "suspendingprotection": MigrationStateSuspendingProtection, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MigrationState(input) + return &out, nil +} + +type ProtectionHealth string + +const ( + ProtectionHealthCritical ProtectionHealth = "Critical" + ProtectionHealthNone ProtectionHealth = "None" + ProtectionHealthNormal ProtectionHealth = "Normal" + ProtectionHealthWarning ProtectionHealth = "Warning" +) + +func PossibleValuesForProtectionHealth() []string { + return []string{ + string(ProtectionHealthCritical), + string(ProtectionHealthNone), + string(ProtectionHealthNormal), + string(ProtectionHealthWarning), + } +} + +func parseProtectionHealth(input string) (*ProtectionHealth, error) { + vals := map[string]ProtectionHealth{ + "critical": ProtectionHealthCritical, + "none": ProtectionHealthNone, + "normal": ProtectionHealthNormal, + "warning": ProtectionHealthWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtectionHealth(input) + return &out, nil +} + +type ResyncState string + +const ( + ResyncStateNone ResyncState = "None" + ResyncStatePreparedForResynchronization ResyncState = "PreparedForResynchronization" + ResyncStateStartedResynchronization ResyncState = "StartedResynchronization" +) + +func PossibleValuesForResyncState() []string { + return []string{ + string(ResyncStateNone), + string(ResyncStatePreparedForResynchronization), + string(ResyncStateStartedResynchronization), + } +} + +func parseResyncState(input string) (*ResyncState, error) { + vals := map[string]ResyncState{ + "none": ResyncStateNone, + "preparedforresynchronization": ResyncStatePreparedForResynchronization, + "startedresynchronization": ResyncStateStartedResynchronization, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResyncState(input) + return &out, nil +} + +type SecurityType string + +const ( + SecurityTypeConfidentialVM SecurityType = "ConfidentialVM" + SecurityTypeNone SecurityType = "None" + SecurityTypeTrustedLaunch SecurityType = "TrustedLaunch" +) + +func PossibleValuesForSecurityType() []string { + return []string{ + string(SecurityTypeConfidentialVM), + string(SecurityTypeNone), + string(SecurityTypeTrustedLaunch), + } +} + +func parseSecurityType(input string) (*SecurityType, error) { + vals := map[string]SecurityType{ + "confidentialvm": SecurityTypeConfidentialVM, + "none": SecurityTypeNone, + "trustedlaunch": SecurityTypeTrustedLaunch, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityType(input) + return &out, nil +} + +type SqlServerLicenseType string + +const ( + SqlServerLicenseTypeAHUB SqlServerLicenseType = "AHUB" + SqlServerLicenseTypeNoLicenseType SqlServerLicenseType = "NoLicenseType" + SqlServerLicenseTypeNotSpecified SqlServerLicenseType = "NotSpecified" + SqlServerLicenseTypePAYG SqlServerLicenseType = "PAYG" +) + +func PossibleValuesForSqlServerLicenseType() []string { + return []string{ + string(SqlServerLicenseTypeAHUB), + string(SqlServerLicenseTypeNoLicenseType), + string(SqlServerLicenseTypeNotSpecified), + string(SqlServerLicenseTypePAYG), + } +} + +func parseSqlServerLicenseType(input string) (*SqlServerLicenseType, error) { + vals := map[string]SqlServerLicenseType{ + "ahub": SqlServerLicenseTypeAHUB, + "nolicensetype": SqlServerLicenseTypeNoLicenseType, + "notspecified": SqlServerLicenseTypeNotSpecified, + "payg": SqlServerLicenseTypePAYG, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SqlServerLicenseType(input) + return &out, nil +} + +type TestMigrationState string + +const ( + TestMigrationStateNone TestMigrationState = "None" + TestMigrationStateTestMigrationCleanupInProgress TestMigrationState = "TestMigrationCleanupInProgress" + TestMigrationStateTestMigrationCompletedWithInformation TestMigrationState = "TestMigrationCompletedWithInformation" + TestMigrationStateTestMigrationFailed TestMigrationState = "TestMigrationFailed" + TestMigrationStateTestMigrationInProgress TestMigrationState = "TestMigrationInProgress" + TestMigrationStateTestMigrationPartiallySucceeded TestMigrationState = "TestMigrationPartiallySucceeded" + TestMigrationStateTestMigrationSucceeded TestMigrationState = "TestMigrationSucceeded" +) + +func PossibleValuesForTestMigrationState() []string { + return []string{ + string(TestMigrationStateNone), + string(TestMigrationStateTestMigrationCleanupInProgress), + string(TestMigrationStateTestMigrationCompletedWithInformation), + string(TestMigrationStateTestMigrationFailed), + string(TestMigrationStateTestMigrationInProgress), + string(TestMigrationStateTestMigrationPartiallySucceeded), + string(TestMigrationStateTestMigrationSucceeded), + } +} + +func parseTestMigrationState(input string) (*TestMigrationState, error) { + vals := map[string]TestMigrationState{ + "none": TestMigrationStateNone, + "testmigrationcleanupinprogress": TestMigrationStateTestMigrationCleanupInProgress, + "testmigrationcompletedwithinformation": TestMigrationStateTestMigrationCompletedWithInformation, + "testmigrationfailed": TestMigrationStateTestMigrationFailed, + "testmigrationinprogress": TestMigrationStateTestMigrationInProgress, + "testmigrationpartiallysucceeded": TestMigrationStateTestMigrationPartiallySucceeded, + "testmigrationsucceeded": TestMigrationStateTestMigrationSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TestMigrationState(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationmigrationitem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationmigrationitem.go new file mode 100644 index 00000000000..b0b14cab119 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationmigrationitem.go @@ -0,0 +1,166 @@ +package replicationmigrationitems + +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 = ReplicationMigrationItemId{} + +// ReplicationMigrationItemId is a struct representing the Resource ID for a Replication Migration Item +type ReplicationMigrationItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationMigrationItemName string +} + +// NewReplicationMigrationItemID returns a new ReplicationMigrationItemId struct +func NewReplicationMigrationItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationMigrationItemName string) ReplicationMigrationItemId { + return ReplicationMigrationItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationMigrationItemName: replicationMigrationItemName, + } +} + +// ParseReplicationMigrationItemID parses 'input' into a ReplicationMigrationItemId +func ParseReplicationMigrationItemID(input string) (*ReplicationMigrationItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationMigrationItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationMigrationItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationMigrationItemName, ok = parsed.Parsed["replicationMigrationItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationMigrationItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationMigrationItemIDInsensitively parses 'input' case-insensitively into a ReplicationMigrationItemId +// note: this method should only be used for API response data and not user input +func ParseReplicationMigrationItemIDInsensitively(input string) (*ReplicationMigrationItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationMigrationItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationMigrationItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationMigrationItemName, ok = parsed.Parsed["replicationMigrationItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationMigrationItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationMigrationItemID checks that 'input' can be parsed as a Replication Migration Item ID +func ValidateReplicationMigrationItemID(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 := ParseReplicationMigrationItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Migration Item ID +func (id ReplicationMigrationItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationMigrationItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationMigrationItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Migration Item ID +func (id ReplicationMigrationItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationMigrationItems", "replicationMigrationItems", "replicationMigrationItems"), + resourceids.UserSpecifiedSegment("replicationMigrationItemName", "replicationMigrationItemValue"), + } +} + +// String returns a human-readable description of this Replication Migration Item ID +func (id ReplicationMigrationItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Migration Item Name: %q", id.ReplicationMigrationItemName), + } + return fmt.Sprintf("Replication Migration Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationmigrationitem_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationmigrationitem_test.go new file mode 100644 index 00000000000..aad5d192225 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationmigrationitem_test.go @@ -0,0 +1,417 @@ +package replicationmigrationitems + +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 = ReplicationMigrationItemId{} + +func TestNewReplicationMigrationItemID(t *testing.T) { + id := NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationMigrationItemName != "replicationMigrationItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationMigrationItemName'", id.ReplicationMigrationItemName, "replicationMigrationItemValue") + } +} + +func TestFormatReplicationMigrationItemID(t *testing.T) { + actual := NewReplicationMigrationItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationMigrationItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationMigrationItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationMigrationItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue", + Expected: &ReplicationMigrationItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationMigrationItemName: "replicationMigrationItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationMigrationItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationMigrationItemName != v.Expected.ReplicationMigrationItemName { + t.Fatalf("Expected %q but got %q for ReplicationMigrationItemName", v.Expected.ReplicationMigrationItemName, actual.ReplicationMigrationItemName) + } + + } +} + +func TestParseReplicationMigrationItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationMigrationItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue", + Expected: &ReplicationMigrationItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationMigrationItemName: "replicationMigrationItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationMigrationItems/replicationMigrationItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe", + Expected: &ReplicationMigrationItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationMigrationItemName: "rEpLiCaTiOnMiGrAtIoNiTeMvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnMiGrAtIoNiTeMs/rEpLiCaTiOnMiGrAtIoNiTeMvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationMigrationItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationMigrationItemName != v.Expected.ReplicationMigrationItemName { + t.Fatalf("Expected %q but got %q for ReplicationMigrationItemName", v.Expected.ReplicationMigrationItemName, actual.ReplicationMigrationItemName) + } + + } +} + +func TestSegmentsForReplicationMigrationItemId(t *testing.T) { + segments := ReplicationMigrationItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationMigrationItemId 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/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationprotectioncontainer.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationprotectioncontainer.go new file mode 100644 index 00000000000..1185d7204fe --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationprotectioncontainer.go @@ -0,0 +1,153 @@ +package replicationmigrationitems + +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 = ReplicationProtectionContainerId{} + +// ReplicationProtectionContainerId is a struct representing the Resource ID for a Replication Protection Container +type ReplicationProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string +} + +// NewReplicationProtectionContainerID returns a new ReplicationProtectionContainerId struct +func NewReplicationProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string) ReplicationProtectionContainerId { + return ReplicationProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + } +} + +// ParseReplicationProtectionContainerID parses 'input' into a ReplicationProtectionContainerId +func ParseReplicationProtectionContainerID(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectionContainerIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionContainerIDInsensitively(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectionContainerID checks that 'input' can be parsed as a Replication Protection Container ID +func ValidateReplicationProtectionContainerID(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 := ParseReplicationProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Container ID +func (id ReplicationProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container ID +func (id ReplicationProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + } +} + +// String returns a human-readable description of this Replication Protection Container ID +func (id ReplicationProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + } + return fmt.Sprintf("Replication Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationprotectioncontainer_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationprotectioncontainer_test.go new file mode 100644 index 00000000000..f1008c0b2d8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_replicationprotectioncontainer_test.go @@ -0,0 +1,372 @@ +package replicationmigrationitems + +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 = ReplicationProtectionContainerId{} + +func TestNewReplicationProtectionContainerID(t *testing.T) { + id := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } +} + +func TestFormatReplicationProtectionContainerID(t *testing.T) { + actual := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectionContainerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestParseReplicationProtectionContainerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestSegmentsForReplicationProtectionContainerId(t *testing.T) { + segments := ReplicationProtectionContainerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectionContainerId 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/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_vault.go new file mode 100644 index 00000000000..511943a42e5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_vault.go @@ -0,0 +1,127 @@ +package replicationmigrationitems + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_vault_test.go new file mode 100644 index 00000000000..034ce351a0a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationmigrationitems + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_create_autorest.go new file mode 100644 index 00000000000..35052f1c3e2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationMigrationItemsClient) Create(ctx context.Context, id ReplicationMigrationItemId, input EnableMigrationInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationMigrationItemsClient) CreateThenPoll(ctx context.Context, id ReplicationMigrationItemId, input EnableMigrationInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationMigrationItemsClient) preparerForCreate(ctx context.Context, id ReplicationMigrationItemId, input EnableMigrationInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_delete_autorest.go new file mode 100644 index 00000000000..909cbac85e2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_delete_autorest.go @@ -0,0 +1,107 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +type DeleteOperationOptions struct { + DeleteOption *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o DeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.DeleteOption != nil { + out["deleteOption"] = *o.DeleteOption + } + + return out +} + +// Delete ... +func (c ReplicationMigrationItemsClient) Delete(ctx context.Context, id ReplicationMigrationItemId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationMigrationItemsClient) DeleteThenPoll(ctx context.Context, id ReplicationMigrationItemId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationMigrationItemsClient) preparerForDelete(ctx context.Context, id ReplicationMigrationItemId, options DeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_get_autorest.go new file mode 100644 index 00000000000..027275a85be --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationmigrationitems + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *MigrationItem +} + +// Get ... +func (c ReplicationMigrationItemsClient) Get(ctx context.Context, id ReplicationMigrationItemId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationMigrationItemsClient) preparerForGet(ctx context.Context, id ReplicationMigrationItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationMigrationItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_list_autorest.go new file mode 100644 index 00000000000..df03e381225 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_list_autorest.go @@ -0,0 +1,225 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]MigrationItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []MigrationItem +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string + SkipToken *string + TakeToken *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + if o.SkipToken != nil { + out["skipToken"] = *o.SkipToken + } + + if o.TakeToken != nil { + out["takeToken"] = *o.TakeToken + } + + return out +} + +// List ... +func (c ReplicationMigrationItemsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationMigrationItemsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationMigrationItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationMigrationItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationMigrationItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []MigrationItem `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationMigrationItemsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MigrationItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationMigrationItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate MigrationItemOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]MigrationItem, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_listbyreplicationprotectioncontainers_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_listbyreplicationprotectioncontainers_autorest.go new file mode 100644 index 00000000000..76c1530f442 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_listbyreplicationprotectioncontainers_autorest.go @@ -0,0 +1,225 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationProtectionContainersOperationResponse struct { + HttpResponse *http.Response + Model *[]MigrationItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectionContainersOperationResponse, error) +} + +type ListByReplicationProtectionContainersCompleteResult struct { + Items []MigrationItem +} + +func (r ListByReplicationProtectionContainersOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationProtectionContainersOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByReplicationProtectionContainersOperationOptions struct { + Filter *string + SkipToken *string + TakeToken *string +} + +func DefaultListByReplicationProtectionContainersOperationOptions() ListByReplicationProtectionContainersOperationOptions { + return ListByReplicationProtectionContainersOperationOptions{} +} + +func (o ListByReplicationProtectionContainersOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByReplicationProtectionContainersOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + if o.SkipToken != nil { + out["skipToken"] = *o.SkipToken + } + + if o.TakeToken != nil { + out["takeToken"] = *o.TakeToken + } + + return out +} + +// ListByReplicationProtectionContainers ... +func (c ReplicationMigrationItemsClient) ListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainers(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationProtectionContainers(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationProtectionContainers prepares the ListByReplicationProtectionContainers request. +func (c ReplicationMigrationItemsClient) preparerForListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationMigrationItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationProtectionContainersWithNextLink prepares the ListByReplicationProtectionContainers request with the given nextLink token. +func (c ReplicationMigrationItemsClient) preparerForListByReplicationProtectionContainersWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationProtectionContainers handles the response to the ListByReplicationProtectionContainers request. The method always +// closes the http.Response Body. +func (c ReplicationMigrationItemsClient) responderForListByReplicationProtectionContainers(resp *http.Response) (result ListByReplicationProtectionContainersOperationResponse, err error) { + type page struct { + Values []MigrationItem `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainersWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationProtectionContainers(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationProtectionContainersComplete retrieves all of the results into a single object +func (c ReplicationMigrationItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (ListByReplicationProtectionContainersCompleteResult, error) { + return c.ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx, id, options, MigrationItemOperationPredicate{}) +} + +// ListByReplicationProtectionContainersCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationMigrationItemsClient) ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions, predicate MigrationItemOperationPredicate) (resp ListByReplicationProtectionContainersCompleteResult, err error) { + items := make([]MigrationItem, 0) + + page, err := c.ListByReplicationProtectionContainers(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationProtectionContainersCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_migrate_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_migrate_autorest.go new file mode 100644 index 00000000000..98b228f3da3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_migrate_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Migrate ... +func (c ReplicationMigrationItemsClient) Migrate(ctx context.Context, id ReplicationMigrationItemId, input MigrateInput) (result MigrateOperationResponse, err error) { + req, err := c.preparerForMigrate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Migrate", nil, "Failure preparing request") + return + } + + result, err = c.senderForMigrate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Migrate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// MigrateThenPoll performs Migrate then polls until it's completed +func (c ReplicationMigrationItemsClient) MigrateThenPoll(ctx context.Context, id ReplicationMigrationItemId, input MigrateInput) error { + result, err := c.Migrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Migrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Migrate: %+v", err) + } + + return nil +} + +// preparerForMigrate prepares the Migrate request. +func (c ReplicationMigrationItemsClient) preparerForMigrate(ctx context.Context, id ReplicationMigrationItemId, input MigrateInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/migrate", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForMigrate sends the Migrate request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForMigrate(ctx context.Context, req *http.Request) (future MigrateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_pausereplication_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_pausereplication_autorest.go new file mode 100644 index 00000000000..5e4978f28e5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_pausereplication_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PauseReplicationOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// PauseReplication ... +func (c ReplicationMigrationItemsClient) PauseReplication(ctx context.Context, id ReplicationMigrationItemId, input PauseReplicationInput) (result PauseReplicationOperationResponse, err error) { + req, err := c.preparerForPauseReplication(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "PauseReplication", nil, "Failure preparing request") + return + } + + result, err = c.senderForPauseReplication(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "PauseReplication", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PauseReplicationThenPoll performs PauseReplication then polls until it's completed +func (c ReplicationMigrationItemsClient) PauseReplicationThenPoll(ctx context.Context, id ReplicationMigrationItemId, input PauseReplicationInput) error { + result, err := c.PauseReplication(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PauseReplication: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after PauseReplication: %+v", err) + } + + return nil +} + +// preparerForPauseReplication prepares the PauseReplication request. +func (c ReplicationMigrationItemsClient) preparerForPauseReplication(ctx context.Context, id ReplicationMigrationItemId, input PauseReplicationInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/pauseReplication", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPauseReplication sends the PauseReplication request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForPauseReplication(ctx context.Context, req *http.Request) (future PauseReplicationOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_resumereplication_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_resumereplication_autorest.go new file mode 100644 index 00000000000..3c5ea7d3bc7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_resumereplication_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeReplicationOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ResumeReplication ... +func (c ReplicationMigrationItemsClient) ResumeReplication(ctx context.Context, id ReplicationMigrationItemId, input ResumeReplicationInput) (result ResumeReplicationOperationResponse, err error) { + req, err := c.preparerForResumeReplication(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ResumeReplication", nil, "Failure preparing request") + return + } + + result, err = c.senderForResumeReplication(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "ResumeReplication", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ResumeReplicationThenPoll performs ResumeReplication then polls until it's completed +func (c ReplicationMigrationItemsClient) ResumeReplicationThenPoll(ctx context.Context, id ReplicationMigrationItemId, input ResumeReplicationInput) error { + result, err := c.ResumeReplication(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ResumeReplication: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ResumeReplication: %+v", err) + } + + return nil +} + +// preparerForResumeReplication prepares the ResumeReplication request. +func (c ReplicationMigrationItemsClient) preparerForResumeReplication(ctx context.Context, id ReplicationMigrationItemId, input ResumeReplicationInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/resumeReplication", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForResumeReplication sends the ResumeReplication request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForResumeReplication(ctx context.Context, req *http.Request) (future ResumeReplicationOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_resync_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_resync_autorest.go new file mode 100644 index 00000000000..4a62dbb792c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_resync_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResyncOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Resync ... +func (c ReplicationMigrationItemsClient) Resync(ctx context.Context, id ReplicationMigrationItemId, input ResyncInput) (result ResyncOperationResponse, err error) { + req, err := c.preparerForResync(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Resync", nil, "Failure preparing request") + return + } + + result, err = c.senderForResync(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Resync", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ResyncThenPoll performs Resync then polls until it's completed +func (c ReplicationMigrationItemsClient) ResyncThenPoll(ctx context.Context, id ReplicationMigrationItemId, input ResyncInput) error { + result, err := c.Resync(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Resync: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Resync: %+v", err) + } + + return nil +} + +// preparerForResync prepares the Resync request. +func (c ReplicationMigrationItemsClient) preparerForResync(ctx context.Context, id ReplicationMigrationItemId, input ResyncInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/resync", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForResync sends the Resync request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForResync(ctx context.Context, req *http.Request) (future ResyncOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_testmigrate_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_testmigrate_autorest.go new file mode 100644 index 00000000000..d775b946707 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_testmigrate_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestMigrateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// TestMigrate ... +func (c ReplicationMigrationItemsClient) TestMigrate(ctx context.Context, id ReplicationMigrationItemId, input TestMigrateInput) (result TestMigrateOperationResponse, err error) { + req, err := c.preparerForTestMigrate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "TestMigrate", nil, "Failure preparing request") + return + } + + result, err = c.senderForTestMigrate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "TestMigrate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TestMigrateThenPoll performs TestMigrate then polls until it's completed +func (c ReplicationMigrationItemsClient) TestMigrateThenPoll(ctx context.Context, id ReplicationMigrationItemId, input TestMigrateInput) error { + result, err := c.TestMigrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestMigrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after TestMigrate: %+v", err) + } + + return nil +} + +// preparerForTestMigrate prepares the TestMigrate request. +func (c ReplicationMigrationItemsClient) preparerForTestMigrate(ctx context.Context, id ReplicationMigrationItemId, input TestMigrateInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/testMigrate", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTestMigrate sends the TestMigrate request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForTestMigrate(ctx context.Context, req *http.Request) (future TestMigrateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_testmigratecleanup_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_testmigratecleanup_autorest.go new file mode 100644 index 00000000000..6b7689ee7ae --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_testmigratecleanup_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestMigrateCleanupOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// TestMigrateCleanup ... +func (c ReplicationMigrationItemsClient) TestMigrateCleanup(ctx context.Context, id ReplicationMigrationItemId, input TestMigrateCleanupInput) (result TestMigrateCleanupOperationResponse, err error) { + req, err := c.preparerForTestMigrateCleanup(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "TestMigrateCleanup", nil, "Failure preparing request") + return + } + + result, err = c.senderForTestMigrateCleanup(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "TestMigrateCleanup", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TestMigrateCleanupThenPoll performs TestMigrateCleanup then polls until it's completed +func (c ReplicationMigrationItemsClient) TestMigrateCleanupThenPoll(ctx context.Context, id ReplicationMigrationItemId, input TestMigrateCleanupInput) error { + result, err := c.TestMigrateCleanup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestMigrateCleanup: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after TestMigrateCleanup: %+v", err) + } + + return nil +} + +// preparerForTestMigrateCleanup prepares the TestMigrateCleanup request. +func (c ReplicationMigrationItemsClient) preparerForTestMigrateCleanup(ctx context.Context, id ReplicationMigrationItemId, input TestMigrateCleanupInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/testMigrateCleanup", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTestMigrateCleanup sends the TestMigrateCleanup request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForTestMigrateCleanup(ctx context.Context, req *http.Request) (future TestMigrateCleanupOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_update_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_update_autorest.go new file mode 100644 index 00000000000..3489a1788df --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/method_update_autorest.go @@ -0,0 +1,79 @@ +package replicationmigrationitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ReplicationMigrationItemsClient) Update(ctx context.Context, id ReplicationMigrationItemId, input UpdateMigrationItemInput) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationmigrationitems.ReplicationMigrationItemsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationMigrationItemsClient) UpdateThenPoll(ctx context.Context, id ReplicationMigrationItemId, input UpdateMigrationItemInput) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ReplicationMigrationItemsClient) preparerForUpdate(ctx context.Context, id ReplicationMigrationItemId, input UpdateMigrationItemInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationMigrationItemsClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_criticaljobhistorydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_criticaljobhistorydetails.go new file mode 100644 index 00000000000..cbaf060f779 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_criticaljobhistorydetails.go @@ -0,0 +1,29 @@ +package replicationmigrationitems + +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 CriticalJobHistoryDetails struct { + JobId *string `json:"jobId,omitempty"` + JobName *string `json:"jobName,omitempty"` + JobStatus *string `json:"jobStatus,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *CriticalJobHistoryDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CriticalJobHistoryDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_currentjobdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_currentjobdetails.go new file mode 100644 index 00000000000..6461ea7fe4f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_currentjobdetails.go @@ -0,0 +1,28 @@ +package replicationmigrationitems + +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 CurrentJobDetails struct { + JobId *string `json:"jobId,omitempty"` + JobName *string `json:"jobName,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *CurrentJobDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CurrentJobDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationinput.go new file mode 100644 index 00000000000..eeb46d6566e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationinput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnableMigrationInput struct { + Properties EnableMigrationInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationinputproperties.go new file mode 100644 index 00000000000..49ca92b996e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationinputproperties.go @@ -0,0 +1,40 @@ +package replicationmigrationitems + +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 EnableMigrationInputProperties struct { + PolicyId string `json:"policyId"` + ProviderSpecificDetails EnableMigrationProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &EnableMigrationInputProperties{} + +func (s *EnableMigrationInputProperties) UnmarshalJSON(bytes []byte) error { + type alias EnableMigrationInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into EnableMigrationInputProperties: %+v", err) + } + + s.PolicyId = decoded.PolicyId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EnableMigrationInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalEnableMigrationProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'EnableMigrationInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationproviderspecificinput.go new file mode 100644 index 00000000000..2d22fea5966 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_enablemigrationproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationmigrationitems + +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 EnableMigrationProviderSpecificInput interface { +} + +func unmarshalEnableMigrationProviderSpecificInputImplementation(input []byte) (EnableMigrationProviderSpecificInput, 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 EnableMigrationProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtEnableMigrationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtEnableMigrationInput: %+v", err) + } + return out, nil + } + + type RawEnableMigrationProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawEnableMigrationProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_healtherror.go new file mode 100644 index 00000000000..bd011f2be40 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationmigrationitems + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_innerhealtherror.go new file mode 100644 index 00000000000..57850e37e2e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationmigrationitems + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateinput.go new file mode 100644 index 00000000000..64530958cea --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateinput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateInput struct { + Properties MigrateInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateinputproperties.go new file mode 100644 index 00000000000..3b1bf018068 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateinputproperties.go @@ -0,0 +1,32 @@ +package replicationmigrationitems + +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 MigrateInputProperties struct { + ProviderSpecificDetails MigrateProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &MigrateInputProperties{} + +func (s *MigrateInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling MigrateInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalMigrateProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'MigrateInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateproviderspecificinput.go new file mode 100644 index 00000000000..2d9b24665f6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrateproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationmigrationitems + +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 MigrateProviderSpecificInput interface { +} + +func unmarshalMigrateProviderSpecificInputImplementation(input []byte) (MigrateProviderSpecificInput, 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 MigrateProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtMigrateInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtMigrateInput: %+v", err) + } + return out, nil + } + + type RawMigrateProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawMigrateProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationitem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationitem.go new file mode 100644 index 00000000000..42cd0fcb04e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationitem.go @@ -0,0 +1,12 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationItem struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MigrationItemProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationitemproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationitemproperties.go new file mode 100644 index 00000000000..76e077d7bde --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationitemproperties.go @@ -0,0 +1,103 @@ +package replicationmigrationitems + +import ( + "encoding/json" + "fmt" + "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 MigrationItemProperties struct { + AllowedOperations *[]MigrationItemOperation `json:"allowedOperations,omitempty"` + CriticalJobHistory *[]CriticalJobHistoryDetails `json:"criticalJobHistory,omitempty"` + CurrentJob *CurrentJobDetails `json:"currentJob,omitempty"` + EventCorrelationId *string `json:"eventCorrelationId,omitempty"` + Health *ProtectionHealth `json:"health,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + LastMigrationStatus *string `json:"lastMigrationStatus,omitempty"` + LastMigrationTime *string `json:"lastMigrationTime,omitempty"` + LastTestMigrationStatus *string `json:"lastTestMigrationStatus,omitempty"` + LastTestMigrationTime *string `json:"lastTestMigrationTime,omitempty"` + MachineName *string `json:"machineName,omitempty"` + MigrationState *MigrationState `json:"migrationState,omitempty"` + MigrationStateDescription *string `json:"migrationStateDescription,omitempty"` + PolicyFriendlyName *string `json:"policyFriendlyName,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProviderSpecificDetails MigrationProviderSpecificSettings `json:"providerSpecificDetails"` + RecoveryServicesProviderId *string `json:"recoveryServicesProviderId,omitempty"` + ReplicationStatus *string `json:"replicationStatus,omitempty"` + TestMigrateState *TestMigrationState `json:"testMigrateState,omitempty"` + TestMigrateStateDescription *string `json:"testMigrateStateDescription,omitempty"` +} + +func (o *MigrationItemProperties) GetLastMigrationTimeAsTime() (*time.Time, error) { + if o.LastMigrationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastMigrationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MigrationItemProperties) SetLastMigrationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastMigrationTime = &formatted +} + +func (o *MigrationItemProperties) GetLastTestMigrationTimeAsTime() (*time.Time, error) { + if o.LastTestMigrationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastTestMigrationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MigrationItemProperties) SetLastTestMigrationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastTestMigrationTime = &formatted +} + +var _ json.Unmarshaler = &MigrationItemProperties{} + +func (s *MigrationItemProperties) UnmarshalJSON(bytes []byte) error { + type alias MigrationItemProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into MigrationItemProperties: %+v", err) + } + + s.AllowedOperations = decoded.AllowedOperations + s.CriticalJobHistory = decoded.CriticalJobHistory + s.CurrentJob = decoded.CurrentJob + s.EventCorrelationId = decoded.EventCorrelationId + s.Health = decoded.Health + s.HealthErrors = decoded.HealthErrors + s.LastMigrationStatus = decoded.LastMigrationStatus + s.LastMigrationTime = decoded.LastMigrationTime + s.LastTestMigrationStatus = decoded.LastTestMigrationStatus + s.LastTestMigrationTime = decoded.LastTestMigrationTime + s.MachineName = decoded.MachineName + s.MigrationState = decoded.MigrationState + s.MigrationStateDescription = decoded.MigrationStateDescription + s.PolicyFriendlyName = decoded.PolicyFriendlyName + s.PolicyId = decoded.PolicyId + s.RecoveryServicesProviderId = decoded.RecoveryServicesProviderId + s.ReplicationStatus = decoded.ReplicationStatus + s.TestMigrateState = decoded.TestMigrateState + s.TestMigrateStateDescription = decoded.TestMigrateStateDescription + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling MigrationItemProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalMigrationProviderSpecificSettingsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'MigrationItemProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationproviderspecificsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationproviderspecificsettings.go new file mode 100644 index 00000000000..8de2c082a6c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_migrationproviderspecificsettings.go @@ -0,0 +1,48 @@ +package replicationmigrationitems + +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 MigrationProviderSpecificSettings interface { +} + +func unmarshalMigrationProviderSpecificSettingsImplementation(input []byte) (MigrationProviderSpecificSettings, 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 MigrationProviderSpecificSettings into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtMigrationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtMigrationDetails: %+v", err) + } + return out, nil + } + + type RawMigrationProviderSpecificSettingsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawMigrationProviderSpecificSettingsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_pausereplicationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_pausereplicationinput.go new file mode 100644 index 00000000000..9e6108005ed --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_pausereplicationinput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PauseReplicationInput struct { + Properties PauseReplicationInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_pausereplicationinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_pausereplicationinputproperties.go new file mode 100644 index 00000000000..67b7a7a192c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_pausereplicationinputproperties.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PauseReplicationInputProperties struct { + InstanceType string `json:"instanceType"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationinput.go new file mode 100644 index 00000000000..fb4429f5eac --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationinput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeReplicationInput struct { + Properties ResumeReplicationInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationinputproperties.go new file mode 100644 index 00000000000..2f4cf233728 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationinputproperties.go @@ -0,0 +1,32 @@ +package replicationmigrationitems + +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 ResumeReplicationInputProperties struct { + ProviderSpecificDetails ResumeReplicationProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &ResumeReplicationInputProperties{} + +func (s *ResumeReplicationInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ResumeReplicationInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalResumeReplicationProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ResumeReplicationInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationproviderspecificinput.go new file mode 100644 index 00000000000..1511ccf83cc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resumereplicationproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationmigrationitems + +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 ResumeReplicationProviderSpecificInput interface { +} + +func unmarshalResumeReplicationProviderSpecificInputImplementation(input []byte) (ResumeReplicationProviderSpecificInput, 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 ResumeReplicationProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtResumeReplicationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtResumeReplicationInput: %+v", err) + } + return out, nil + } + + type RawResumeReplicationProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawResumeReplicationProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncinput.go new file mode 100644 index 00000000000..e680c11686e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncinput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResyncInput struct { + Properties ResyncInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncinputproperties.go new file mode 100644 index 00000000000..a440510e3b9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncinputproperties.go @@ -0,0 +1,32 @@ +package replicationmigrationitems + +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 ResyncInputProperties struct { + ProviderSpecificDetails ResyncProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &ResyncInputProperties{} + +func (s *ResyncInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ResyncInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalResyncProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ResyncInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncproviderspecificinput.go new file mode 100644 index 00000000000..8134ba1973e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_resyncproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationmigrationitems + +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 ResyncProviderSpecificInput interface { +} + +func unmarshalResyncProviderSpecificInputImplementation(input []byte) (ResyncProviderSpecificInput, 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 ResyncProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtResyncInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtResyncInput: %+v", err) + } + return out, nil + } + + type RawResyncProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawResyncProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigratecleanupinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigratecleanupinput.go new file mode 100644 index 00000000000..15890ac313a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigratecleanupinput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestMigrateCleanupInput struct { + Properties TestMigrateCleanupInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigratecleanupinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigratecleanupinputproperties.go new file mode 100644 index 00000000000..a7ac0568f76 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigratecleanupinputproperties.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestMigrateCleanupInputProperties struct { + Comments *string `json:"comments,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateinput.go new file mode 100644 index 00000000000..cc8da4dbada --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateinput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestMigrateInput struct { + Properties TestMigrateInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateinputproperties.go new file mode 100644 index 00000000000..5453572f37d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateinputproperties.go @@ -0,0 +1,32 @@ +package replicationmigrationitems + +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 TestMigrateInputProperties struct { + ProviderSpecificDetails TestMigrateProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &TestMigrateInputProperties{} + +func (s *TestMigrateInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TestMigrateInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalTestMigrateProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'TestMigrateInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateproviderspecificinput.go new file mode 100644 index 00000000000..8d228123dc4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_testmigrateproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationmigrationitems + +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 TestMigrateProviderSpecificInput interface { +} + +func unmarshalTestMigrateProviderSpecificInputImplementation(input []byte) (TestMigrateProviderSpecificInput, 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 TestMigrateProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtTestMigrateInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtTestMigrateInput: %+v", err) + } + return out, nil + } + + type RawTestMigrateProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawTestMigrateProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationiteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationiteminput.go new file mode 100644 index 00000000000..3a41aab1339 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationiteminput.go @@ -0,0 +1,8 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateMigrationItemInput struct { + Properties *UpdateMigrationItemInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationiteminputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationiteminputproperties.go new file mode 100644 index 00000000000..59b86ba8b1e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationiteminputproperties.go @@ -0,0 +1,32 @@ +package replicationmigrationitems + +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 UpdateMigrationItemInputProperties struct { + ProviderSpecificDetails UpdateMigrationItemProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &UpdateMigrationItemInputProperties{} + +func (s *UpdateMigrationItemInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling UpdateMigrationItemInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalUpdateMigrationItemProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'UpdateMigrationItemInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationitemproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationitemproviderspecificinput.go new file mode 100644 index 00000000000..97954547811 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_updatemigrationitemproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationmigrationitems + +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 UpdateMigrationItemProviderSpecificInput interface { +} + +func unmarshalUpdateMigrationItemProviderSpecificInputImplementation(input []byte) (UpdateMigrationItemProviderSpecificInput, 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 UpdateMigrationItemProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtUpdateMigrationItemInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtUpdateMigrationItemInput: %+v", err) + } + return out, nil + } + + type RawUpdateMigrationItemProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawUpdateMigrationItemProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtdiskinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtdiskinput.go new file mode 100644 index 00000000000..fc16a80a298 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtdiskinput.go @@ -0,0 +1,13 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareCbtDiskInput struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId string `json:"diskId"` + DiskType *DiskAccountType `json:"diskType,omitempty"` + IsOSDisk string `json:"isOSDisk"` + LogStorageAccountId string `json:"logStorageAccountId"` + LogStorageAccountSasSecretName string `json:"logStorageAccountSasSecretName"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtenablemigrationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtenablemigrationinput.go new file mode 100644 index 00000000000..55ef94dffb5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtenablemigrationinput.go @@ -0,0 +1,65 @@ +package replicationmigrationitems + +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 _ EnableMigrationProviderSpecificInput = VMwareCbtEnableMigrationInput{} + +type VMwareCbtEnableMigrationInput struct { + ConfidentialVMKeyVaultId *string `json:"confidentialVmKeyVaultId,omitempty"` + DataMoverRunAsAccountId string `json:"dataMoverRunAsAccountId"` + DisksToInclude []VMwareCbtDiskInput `json:"disksToInclude"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + PerformAutoResync *string `json:"performAutoResync,omitempty"` + PerformSqlBulkRegistration *string `json:"performSqlBulkRegistration,omitempty"` + SeedDiskTags *map[string]string `json:"seedDiskTags,omitempty"` + SnapshotRunAsAccountId string `json:"snapshotRunAsAccountId"` + SqlServerLicenseType *SqlServerLicenseType `json:"sqlServerLicenseType,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetBootDiagnosticsStorageAccountId *string `json:"targetBootDiagnosticsStorageAccountId,omitempty"` + TargetDiskTags *map[string]string `json:"targetDiskTags,omitempty"` + TargetNetworkId string `json:"targetNetworkId"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetResourceGroupId string `json:"targetResourceGroupId"` + TargetSubnetName *string `json:"targetSubnetName,omitempty"` + TargetVMName *string `json:"targetVmName,omitempty"` + TargetVMSecurityProfile *VMwareCbtSecurityProfileProperties `json:"targetVmSecurityProfile,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + TestNetworkId *string `json:"testNetworkId,omitempty"` + TestSubnetName *string `json:"testSubnetName,omitempty"` + VMwareMachineId string `json:"vmwareMachineId"` + + // Fields inherited from EnableMigrationProviderSpecificInput +} + +var _ json.Marshaler = VMwareCbtEnableMigrationInput{} + +func (s VMwareCbtEnableMigrationInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtEnableMigrationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtEnableMigrationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtEnableMigrationInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtEnableMigrationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtmigrateinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtmigrateinput.go new file mode 100644 index 00000000000..270108c42c2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtmigrateinput.go @@ -0,0 +1,42 @@ +package replicationmigrationitems + +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 _ MigrateProviderSpecificInput = VMwareCbtMigrateInput{} + +type VMwareCbtMigrateInput struct { + OsUpgradeVersion *string `json:"osUpgradeVersion,omitempty"` + PerformShutdown string `json:"performShutdown"` + + // Fields inherited from MigrateProviderSpecificInput +} + +var _ json.Marshaler = VMwareCbtMigrateInput{} + +func (s VMwareCbtMigrateInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtMigrateInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtMigrateInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtMigrateInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtMigrateInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtmigrationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtmigrationdetails.go new file mode 100644 index 00000000000..efc3eb35083 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtmigrationdetails.go @@ -0,0 +1,82 @@ +package replicationmigrationitems + +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 _ MigrationProviderSpecificSettings = VMwareCbtMigrationDetails{} + +type VMwareCbtMigrationDetails struct { + ConfidentialVMKeyVaultId *string `json:"confidentialVmKeyVaultId,omitempty"` + DataMoverRunAsAccountId *string `json:"dataMoverRunAsAccountId,omitempty"` + FirmwareType *string `json:"firmwareType,omitempty"` + InitialSeedingProgressPercentage *int64 `json:"initialSeedingProgressPercentage,omitempty"` + InitialSeedingRetryCount *int64 `json:"initialSeedingRetryCount,omitempty"` + LastRecoveryPointId *string `json:"lastRecoveryPointId,omitempty"` + LastRecoveryPointReceived *string `json:"lastRecoveryPointReceived,omitempty"` + LicenseType *string `json:"licenseType,omitempty"` + MigrationProgressPercentage *int64 `json:"migrationProgressPercentage,omitempty"` + MigrationRecoveryPointId *string `json:"migrationRecoveryPointId,omitempty"` + OsName *string `json:"osName,omitempty"` + OsType *string `json:"osType,omitempty"` + PerformAutoResync *string `json:"performAutoResync,omitempty"` + ProtectedDisks *[]VMwareCbtProtectedDiskDetails `json:"protectedDisks,omitempty"` + ResumeProgressPercentage *int64 `json:"resumeProgressPercentage,omitempty"` + ResumeRetryCount *int64 `json:"resumeRetryCount,omitempty"` + ResyncProgressPercentage *int64 `json:"resyncProgressPercentage,omitempty"` + ResyncRequired *string `json:"resyncRequired,omitempty"` + ResyncRetryCount *int64 `json:"resyncRetryCount,omitempty"` + ResyncState *ResyncState `json:"resyncState,omitempty"` + SeedDiskTags *map[string]string `json:"seedDiskTags,omitempty"` + SnapshotRunAsAccountId *string `json:"snapshotRunAsAccountId,omitempty"` + SqlServerLicenseType *string `json:"sqlServerLicenseType,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + SupportedOSVersions *[]string `json:"supportedOSVersions,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetBootDiagnosticsStorageAccountId *string `json:"targetBootDiagnosticsStorageAccountId,omitempty"` + TargetDiskTags *map[string]string `json:"targetDiskTags,omitempty"` + TargetGeneration *string `json:"targetGeneration,omitempty"` + TargetLocation *string `json:"targetLocation,omitempty"` + TargetNetworkId *string `json:"targetNetworkId,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVMName *string `json:"targetVmName,omitempty"` + TargetVMSecurityProfile *VMwareCbtSecurityProfileProperties `json:"targetVmSecurityProfile,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + TestNetworkId *string `json:"testNetworkId,omitempty"` + VMNics *[]VMwareCbtNicDetails `json:"vmNics,omitempty"` + VMwareMachineId *string `json:"vmwareMachineId,omitempty"` + + // Fields inherited from MigrationProviderSpecificSettings +} + +var _ json.Marshaler = VMwareCbtMigrationDetails{} + +func (s VMwareCbtMigrationDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtMigrationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtMigrationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtMigrationDetails: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtMigrationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtnicdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtnicdetails.go new file mode 100644 index 00000000000..068195a186f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtnicdetails.go @@ -0,0 +1,21 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareCbtNicDetails struct { + IsPrimaryNic *string `json:"isPrimaryNic,omitempty"` + IsSelectedForMigration *string `json:"isSelectedForMigration,omitempty"` + NicId *string `json:"nicId,omitempty"` + SourceIPAddress *string `json:"sourceIPAddress,omitempty"` + SourceIPAddressType *EthernetAddressType `json:"sourceIPAddressType,omitempty"` + SourceNetworkId *string `json:"sourceNetworkId,omitempty"` + TargetIPAddress *string `json:"targetIPAddress,omitempty"` + TargetIPAddressType *EthernetAddressType `json:"targetIPAddressType,omitempty"` + TargetNicName *string `json:"targetNicName,omitempty"` + TargetSubnetName *string `json:"targetSubnetName,omitempty"` + TestIPAddress *string `json:"testIPAddress,omitempty"` + TestIPAddressType *EthernetAddressType `json:"testIPAddressType,omitempty"` + TestNetworkId *string `json:"testNetworkId,omitempty"` + TestSubnetName *string `json:"testSubnetName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtnicinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtnicinput.go new file mode 100644 index 00000000000..43ec27bd70b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtnicinput.go @@ -0,0 +1,15 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareCbtNicInput struct { + IsPrimaryNic string `json:"isPrimaryNic"` + IsSelectedForMigration *string `json:"isSelectedForMigration,omitempty"` + NicId string `json:"nicId"` + TargetNicName *string `json:"targetNicName,omitempty"` + TargetStaticIPAddress *string `json:"targetStaticIPAddress,omitempty"` + TargetSubnetName *string `json:"targetSubnetName,omitempty"` + TestStaticIPAddress *string `json:"testStaticIPAddress,omitempty"` + TestSubnetName *string `json:"testSubnetName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtprotecteddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtprotecteddiskdetails.go new file mode 100644 index 00000000000..a84ff74659d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtprotecteddiskdetails.go @@ -0,0 +1,21 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareCbtProtectedDiskDetails struct { + CapacityInBytes *int64 `json:"capacityInBytes,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskPath *string `json:"diskPath,omitempty"` + DiskType *DiskAccountType `json:"diskType,omitempty"` + IsOSDisk *string `json:"isOSDisk,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` + LogStorageAccountSasSecretName *string `json:"logStorageAccountSasSecretName,omitempty"` + SeedBlobUri *string `json:"seedBlobUri,omitempty"` + SeedManagedDiskId *string `json:"seedManagedDiskId,omitempty"` + TargetBlobUri *string `json:"targetBlobUri,omitempty"` + TargetDiskName *string `json:"targetDiskName,omitempty"` + TargetManagedDiskId *string `json:"targetManagedDiskId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtresumereplicationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtresumereplicationinput.go new file mode 100644 index 00000000000..bd5bb9ebae3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtresumereplicationinput.go @@ -0,0 +1,41 @@ +package replicationmigrationitems + +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 _ ResumeReplicationProviderSpecificInput = VMwareCbtResumeReplicationInput{} + +type VMwareCbtResumeReplicationInput struct { + DeleteMigrationResources *string `json:"deleteMigrationResources,omitempty"` + + // Fields inherited from ResumeReplicationProviderSpecificInput +} + +var _ json.Marshaler = VMwareCbtResumeReplicationInput{} + +func (s VMwareCbtResumeReplicationInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtResumeReplicationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtResumeReplicationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtResumeReplicationInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtResumeReplicationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtresyncinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtresyncinput.go new file mode 100644 index 00000000000..98d37a993f1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtresyncinput.go @@ -0,0 +1,41 @@ +package replicationmigrationitems + +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 _ ResyncProviderSpecificInput = VMwareCbtResyncInput{} + +type VMwareCbtResyncInput struct { + SkipCbtReset string `json:"skipCbtReset"` + + // Fields inherited from ResyncProviderSpecificInput +} + +var _ json.Marshaler = VMwareCbtResyncInput{} + +func (s VMwareCbtResyncInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtResyncInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtResyncInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtResyncInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtResyncInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtsecurityprofileproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtsecurityprofileproperties.go new file mode 100644 index 00000000000..8bca1ef02df --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtsecurityprofileproperties.go @@ -0,0 +1,12 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareCbtSecurityProfileProperties struct { + IsTargetVMConfidentialEncryptionEnabled *string `json:"isTargetVmConfidentialEncryptionEnabled,omitempty"` + IsTargetVMIntegrityMonitoringEnabled *string `json:"isTargetVmIntegrityMonitoringEnabled,omitempty"` + IsTargetVMSecureBootEnabled *string `json:"isTargetVmSecureBootEnabled,omitempty"` + IsTargetVMTpmEnabled *string `json:"isTargetVmTpmEnabled,omitempty"` + TargetVMSecurityType *SecurityType `json:"targetVmSecurityType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbttestmigrateinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbttestmigrateinput.go new file mode 100644 index 00000000000..78879848fb6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbttestmigrateinput.go @@ -0,0 +1,44 @@ +package replicationmigrationitems + +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 _ TestMigrateProviderSpecificInput = VMwareCbtTestMigrateInput{} + +type VMwareCbtTestMigrateInput struct { + NetworkId string `json:"networkId"` + OsUpgradeVersion *string `json:"osUpgradeVersion,omitempty"` + RecoveryPointId string `json:"recoveryPointId"` + VMNics *[]VMwareCbtNicInput `json:"vmNics,omitempty"` + + // Fields inherited from TestMigrateProviderSpecificInput +} + +var _ json.Marshaler = VMwareCbtTestMigrateInput{} + +func (s VMwareCbtTestMigrateInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtTestMigrateInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtTestMigrateInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtTestMigrateInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtTestMigrateInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtupdatediskinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtupdatediskinput.go new file mode 100644 index 00000000000..54acf609e2b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtupdatediskinput.go @@ -0,0 +1,10 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMwareCbtUpdateDiskInput struct { + DiskId string `json:"diskId"` + IsOSDisk *string `json:"isOSDisk,omitempty"` + TargetDiskName *string `json:"targetDiskName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtupdatemigrationiteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtupdatemigrationiteminput.go new file mode 100644 index 00000000000..3617cd1a1f2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/model_vmwarecbtupdatemigrationiteminput.go @@ -0,0 +1,57 @@ +package replicationmigrationitems + +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 _ UpdateMigrationItemProviderSpecificInput = VMwareCbtUpdateMigrationItemInput{} + +type VMwareCbtUpdateMigrationItemInput struct { + LicenseType *LicenseType `json:"licenseType,omitempty"` + PerformAutoResync *string `json:"performAutoResync,omitempty"` + SqlServerLicenseType *SqlServerLicenseType `json:"sqlServerLicenseType,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetBootDiagnosticsStorageAccountId *string `json:"targetBootDiagnosticsStorageAccountId,omitempty"` + TargetDiskTags *map[string]string `json:"targetDiskTags,omitempty"` + TargetNetworkId *string `json:"targetNetworkId,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVMName *string `json:"targetVmName,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + TestNetworkId *string `json:"testNetworkId,omitempty"` + VMDisks *[]VMwareCbtUpdateDiskInput `json:"vmDisks,omitempty"` + VMNics *[]VMwareCbtNicInput `json:"vmNics,omitempty"` + + // Fields inherited from UpdateMigrationItemProviderSpecificInput +} + +var _ json.Marshaler = VMwareCbtUpdateMigrationItemInput{} + +func (s VMwareCbtUpdateMigrationItemInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtUpdateMigrationItemInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtUpdateMigrationItemInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtUpdateMigrationItemInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtUpdateMigrationItemInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/predicates.go new file mode 100644 index 00000000000..41a62705f7e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/predicates.go @@ -0,0 +1,32 @@ +package replicationmigrationitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationItemOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p MigrationItemOperationPredicate) Matches(input MigrationItem) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/version.go new file mode 100644 index 00000000000..6609e427f7b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationmigrationitems/version.go @@ -0,0 +1,12 @@ +package replicationmigrationitems + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationmigrationitems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/README.md new file mode 100644 index 00000000000..e473b29918c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings` Documentation + +The `replicationnetworkmappings` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings" +``` + + +### Client Initialization + +```go +client := replicationnetworkmappings.NewReplicationNetworkMappingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationNetworkMappingsClient.Create` + +```go +ctx := context.TODO() +id := replicationnetworkmappings.NewReplicationNetworkMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue", "replicationNetworkMappingValue") + +payload := replicationnetworkmappings.CreateNetworkMappingInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationNetworkMappingsClient.Delete` + +```go +ctx := context.TODO() +id := replicationnetworkmappings.NewReplicationNetworkMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue", "replicationNetworkMappingValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationNetworkMappingsClient.Get` + +```go +ctx := context.TODO() +id := replicationnetworkmappings.NewReplicationNetworkMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue", "replicationNetworkMappingValue") + +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: `ReplicationNetworkMappingsClient.List` + +```go +ctx := context.TODO() +id := replicationnetworkmappings.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationNetworkMappingsClient.ListByReplicationNetworks` + +```go +ctx := context.TODO() +id := replicationnetworkmappings.NewReplicationNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue") + +// alternatively `client.ListByReplicationNetworks(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationNetworksComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationNetworkMappingsClient.Update` + +```go +ctx := context.TODO() +id := replicationnetworkmappings.NewReplicationNetworkMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue", "replicationNetworkMappingValue") + +payload := replicationnetworkmappings.UpdateNetworkMappingInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/client.go new file mode 100644 index 00000000000..2db90e54e48 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/client.go @@ -0,0 +1,18 @@ +package replicationnetworkmappings + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationNetworkMappingsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationNetworkMappingsClientWithBaseURI(endpoint string) ReplicationNetworkMappingsClient { + return ReplicationNetworkMappingsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetwork.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetwork.go new file mode 100644 index 00000000000..a4e2ebb501b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetwork.go @@ -0,0 +1,153 @@ +package replicationnetworkmappings + +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 = ReplicationNetworkId{} + +// ReplicationNetworkId is a struct representing the Resource ID for a Replication Network +type ReplicationNetworkId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationNetworkName string +} + +// NewReplicationNetworkID returns a new ReplicationNetworkId struct +func NewReplicationNetworkID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationNetworkName string) ReplicationNetworkId { + return ReplicationNetworkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationNetworkName: replicationNetworkName, + } +} + +// ParseReplicationNetworkID parses 'input' into a ReplicationNetworkId +func ParseReplicationNetworkID(input string) (*ReplicationNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationNetworkIDInsensitively parses 'input' case-insensitively into a ReplicationNetworkId +// note: this method should only be used for API response data and not user input +func ParseReplicationNetworkIDInsensitively(input string) (*ReplicationNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationNetworkID checks that 'input' can be parsed as a Replication Network ID +func ValidateReplicationNetworkID(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 := ParseReplicationNetworkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Network ID +func (id ReplicationNetworkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationNetworks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationNetworkName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Network ID +func (id ReplicationNetworkId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationNetworks", "replicationNetworks", "replicationNetworks"), + resourceids.UserSpecifiedSegment("replicationNetworkName", "replicationNetworkValue"), + } +} + +// String returns a human-readable description of this Replication Network ID +func (id ReplicationNetworkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Network Name: %q", id.ReplicationNetworkName), + } + return fmt.Sprintf("Replication Network (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetwork_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetwork_test.go new file mode 100644 index 00000000000..0e8aef4d0be --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetwork_test.go @@ -0,0 +1,372 @@ +package replicationnetworkmappings + +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 = ReplicationNetworkId{} + +func TestNewReplicationNetworkID(t *testing.T) { + id := NewReplicationNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationNetworkName != "replicationNetworkValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationNetworkName'", id.ReplicationNetworkName, "replicationNetworkValue") + } +} + +func TestFormatReplicationNetworkID(t *testing.T) { + actual := NewReplicationNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationNetworkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationNetworkId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue", + Expected: &ReplicationNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationNetworkName: "replicationNetworkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationNetworkID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationNetworkName != v.Expected.ReplicationNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkName", v.Expected.ReplicationNetworkName, actual.ReplicationNetworkName) + } + + } +} + +func TestParseReplicationNetworkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationNetworkId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue", + Expected: &ReplicationNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationNetworkName: "replicationNetworkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe", + Expected: &ReplicationNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationNetworkName: "rEpLiCaTiOnNeTwOrKvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationNetworkIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationNetworkName != v.Expected.ReplicationNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkName", v.Expected.ReplicationNetworkName, actual.ReplicationNetworkName) + } + + } +} + +func TestSegmentsForReplicationNetworkId(t *testing.T) { + segments := ReplicationNetworkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationNetworkId 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/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetworkmapping.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetworkmapping.go new file mode 100644 index 00000000000..31b6fe11a52 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetworkmapping.go @@ -0,0 +1,166 @@ +package replicationnetworkmappings + +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 = ReplicationNetworkMappingId{} + +// ReplicationNetworkMappingId is a struct representing the Resource ID for a Replication Network Mapping +type ReplicationNetworkMappingId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationNetworkName string + ReplicationNetworkMappingName string +} + +// NewReplicationNetworkMappingID returns a new ReplicationNetworkMappingId struct +func NewReplicationNetworkMappingID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationNetworkName string, replicationNetworkMappingName string) ReplicationNetworkMappingId { + return ReplicationNetworkMappingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationNetworkName: replicationNetworkName, + ReplicationNetworkMappingName: replicationNetworkMappingName, + } +} + +// ParseReplicationNetworkMappingID parses 'input' into a ReplicationNetworkMappingId +func ParseReplicationNetworkMappingID(input string) (*ReplicationNetworkMappingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkMappingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkMappingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkMappingName, ok = parsed.Parsed["replicationNetworkMappingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkMappingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationNetworkMappingIDInsensitively parses 'input' case-insensitively into a ReplicationNetworkMappingId +// note: this method should only be used for API response data and not user input +func ParseReplicationNetworkMappingIDInsensitively(input string) (*ReplicationNetworkMappingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkMappingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkMappingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkMappingName, ok = parsed.Parsed["replicationNetworkMappingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkMappingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationNetworkMappingID checks that 'input' can be parsed as a Replication Network Mapping ID +func ValidateReplicationNetworkMappingID(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 := ParseReplicationNetworkMappingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Network Mapping ID +func (id ReplicationNetworkMappingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationNetworks/%s/replicationNetworkMappings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationNetworkName, id.ReplicationNetworkMappingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Network Mapping ID +func (id ReplicationNetworkMappingId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationNetworks", "replicationNetworks", "replicationNetworks"), + resourceids.UserSpecifiedSegment("replicationNetworkName", "replicationNetworkValue"), + resourceids.StaticSegment("staticReplicationNetworkMappings", "replicationNetworkMappings", "replicationNetworkMappings"), + resourceids.UserSpecifiedSegment("replicationNetworkMappingName", "replicationNetworkMappingValue"), + } +} + +// String returns a human-readable description of this Replication Network Mapping ID +func (id ReplicationNetworkMappingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Network Name: %q", id.ReplicationNetworkName), + fmt.Sprintf("Replication Network Mapping Name: %q", id.ReplicationNetworkMappingName), + } + return fmt.Sprintf("Replication Network Mapping (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetworkmapping_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetworkmapping_test.go new file mode 100644 index 00000000000..aa68ff1a302 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_replicationnetworkmapping_test.go @@ -0,0 +1,417 @@ +package replicationnetworkmappings + +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 = ReplicationNetworkMappingId{} + +func TestNewReplicationNetworkMappingID(t *testing.T) { + id := NewReplicationNetworkMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue", "replicationNetworkMappingValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationNetworkName != "replicationNetworkValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationNetworkName'", id.ReplicationNetworkName, "replicationNetworkValue") + } + + if id.ReplicationNetworkMappingName != "replicationNetworkMappingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationNetworkMappingName'", id.ReplicationNetworkMappingName, "replicationNetworkMappingValue") + } +} + +func TestFormatReplicationNetworkMappingID(t *testing.T) { + actual := NewReplicationNetworkMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue", "replicationNetworkMappingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/replicationNetworkMappings/replicationNetworkMappingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationNetworkMappingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationNetworkMappingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/replicationNetworkMappings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/replicationNetworkMappings/replicationNetworkMappingValue", + Expected: &ReplicationNetworkMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationNetworkName: "replicationNetworkValue", + ReplicationNetworkMappingName: "replicationNetworkMappingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/replicationNetworkMappings/replicationNetworkMappingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationNetworkMappingID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationNetworkName != v.Expected.ReplicationNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkName", v.Expected.ReplicationNetworkName, actual.ReplicationNetworkName) + } + + if actual.ReplicationNetworkMappingName != v.Expected.ReplicationNetworkMappingName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkMappingName", v.Expected.ReplicationNetworkMappingName, actual.ReplicationNetworkMappingName) + } + + } +} + +func TestParseReplicationNetworkMappingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationNetworkMappingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/replicationNetworkMappings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe/rEpLiCaTiOnNeTwOrKmApPiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/replicationNetworkMappings/replicationNetworkMappingValue", + Expected: &ReplicationNetworkMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationNetworkName: "replicationNetworkValue", + ReplicationNetworkMappingName: "replicationNetworkMappingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/replicationNetworkMappings/replicationNetworkMappingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe/rEpLiCaTiOnNeTwOrKmApPiNgS/rEpLiCaTiOnNeTwOrKmApPiNgVaLuE", + Expected: &ReplicationNetworkMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationNetworkName: "rEpLiCaTiOnNeTwOrKvAlUe", + ReplicationNetworkMappingName: "rEpLiCaTiOnNeTwOrKmApPiNgVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe/rEpLiCaTiOnNeTwOrKmApPiNgS/rEpLiCaTiOnNeTwOrKmApPiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationNetworkMappingIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationNetworkName != v.Expected.ReplicationNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkName", v.Expected.ReplicationNetworkName, actual.ReplicationNetworkName) + } + + if actual.ReplicationNetworkMappingName != v.Expected.ReplicationNetworkMappingName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkMappingName", v.Expected.ReplicationNetworkMappingName, actual.ReplicationNetworkMappingName) + } + + } +} + +func TestSegmentsForReplicationNetworkMappingId(t *testing.T) { + segments := ReplicationNetworkMappingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationNetworkMappingId 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/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_vault.go new file mode 100644 index 00000000000..61be35518ce --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_vault.go @@ -0,0 +1,127 @@ +package replicationnetworkmappings + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_vault_test.go new file mode 100644 index 00000000000..2c1a2daf6aa --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationnetworkmappings + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_create_autorest.go new file mode 100644 index 00000000000..25ce961f0c8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationnetworkmappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationNetworkMappingsClient) Create(ctx context.Context, id ReplicationNetworkMappingId, input CreateNetworkMappingInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationNetworkMappingsClient) CreateThenPoll(ctx context.Context, id ReplicationNetworkMappingId, input CreateNetworkMappingInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationNetworkMappingsClient) preparerForCreate(ctx context.Context, id ReplicationNetworkMappingId, input CreateNetworkMappingInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationNetworkMappingsClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_delete_autorest.go new file mode 100644 index 00000000000..80e78f8ff09 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationnetworkmappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationNetworkMappingsClient) Delete(ctx context.Context, id ReplicationNetworkMappingId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationNetworkMappingsClient) DeleteThenPoll(ctx context.Context, id ReplicationNetworkMappingId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationNetworkMappingsClient) preparerForDelete(ctx context.Context, id ReplicationNetworkMappingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationNetworkMappingsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_get_autorest.go new file mode 100644 index 00000000000..231f6b0aa31 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationnetworkmappings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *NetworkMapping +} + +// Get ... +func (c ReplicationNetworkMappingsClient) Get(ctx context.Context, id ReplicationNetworkMappingId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationNetworkMappingsClient) preparerForGet(ctx context.Context, id ReplicationNetworkMappingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationNetworkMappingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_list_autorest.go new file mode 100644 index 00000000000..bd55c74734f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationnetworkmappings + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]NetworkMapping + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []NetworkMapping +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationNetworkMappingsClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationNetworkMappingsClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationNetworkMappings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationNetworkMappingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationNetworkMappingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []NetworkMapping `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationNetworkMappingsClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, NetworkMappingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationNetworkMappingsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate NetworkMappingOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]NetworkMapping, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_listbyreplicationnetworks_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_listbyreplicationnetworks_autorest.go new file mode 100644 index 00000000000..6a7b0fe1078 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_listbyreplicationnetworks_autorest.go @@ -0,0 +1,186 @@ +package replicationnetworkmappings + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationNetworksOperationResponse struct { + HttpResponse *http.Response + Model *[]NetworkMapping + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationNetworksOperationResponse, error) +} + +type ListByReplicationNetworksCompleteResult struct { + Items []NetworkMapping +} + +func (r ListByReplicationNetworksOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationNetworksOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationNetworksOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationNetworks ... +func (c ReplicationNetworkMappingsClient) ListByReplicationNetworks(ctx context.Context, id ReplicationNetworkId) (resp ListByReplicationNetworksOperationResponse, err error) { + req, err := c.preparerForListByReplicationNetworks(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationNetworks(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationNetworks prepares the ListByReplicationNetworks request. +func (c ReplicationNetworkMappingsClient) preparerForListByReplicationNetworks(ctx context.Context, id ReplicationNetworkId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationNetworkMappings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationNetworksWithNextLink prepares the ListByReplicationNetworks request with the given nextLink token. +func (c ReplicationNetworkMappingsClient) preparerForListByReplicationNetworksWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationNetworks handles the response to the ListByReplicationNetworks request. The method always +// closes the http.Response Body. +func (c ReplicationNetworkMappingsClient) responderForListByReplicationNetworks(resp *http.Response) (result ListByReplicationNetworksOperationResponse, err error) { + type page struct { + Values []NetworkMapping `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationNetworksOperationResponse, err error) { + req, err := c.preparerForListByReplicationNetworksWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationNetworks(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationNetworksComplete retrieves all of the results into a single object +func (c ReplicationNetworkMappingsClient) ListByReplicationNetworksComplete(ctx context.Context, id ReplicationNetworkId) (ListByReplicationNetworksCompleteResult, error) { + return c.ListByReplicationNetworksCompleteMatchingPredicate(ctx, id, NetworkMappingOperationPredicate{}) +} + +// ListByReplicationNetworksCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationNetworkMappingsClient) ListByReplicationNetworksCompleteMatchingPredicate(ctx context.Context, id ReplicationNetworkId, predicate NetworkMappingOperationPredicate) (resp ListByReplicationNetworksCompleteResult, err error) { + items := make([]NetworkMapping, 0) + + page, err := c.ListByReplicationNetworks(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationNetworksCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_update_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_update_autorest.go new file mode 100644 index 00000000000..32306fd3a50 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/method_update_autorest.go @@ -0,0 +1,79 @@ +package replicationnetworkmappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ReplicationNetworkMappingsClient) Update(ctx context.Context, id ReplicationNetworkMappingId, input UpdateNetworkMappingInput) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworkmappings.ReplicationNetworkMappingsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationNetworkMappingsClient) UpdateThenPoll(ctx context.Context, id ReplicationNetworkMappingId, input UpdateNetworkMappingInput) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ReplicationNetworkMappingsClient) preparerForUpdate(ctx context.Context, id ReplicationNetworkMappingId, input UpdateNetworkMappingInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationNetworkMappingsClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazurecreatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazurecreatenetworkmappinginput.go new file mode 100644 index 00000000000..338a69b7c24 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazurecreatenetworkmappinginput.go @@ -0,0 +1,41 @@ +package replicationnetworkmappings + +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 _ FabricSpecificCreateNetworkMappingInput = AzureToAzureCreateNetworkMappingInput{} + +type AzureToAzureCreateNetworkMappingInput struct { + PrimaryNetworkId string `json:"primaryNetworkId"` + + // Fields inherited from FabricSpecificCreateNetworkMappingInput +} + +var _ json.Marshaler = AzureToAzureCreateNetworkMappingInput{} + +func (s AzureToAzureCreateNetworkMappingInput) MarshalJSON() ([]byte, error) { + type wrapper AzureToAzureCreateNetworkMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureToAzureCreateNetworkMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureToAzureCreateNetworkMappingInput: %+v", err) + } + decoded["instanceType"] = "AzureToAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureToAzureCreateNetworkMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazurenetworkmappingsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazurenetworkmappingsettings.go new file mode 100644 index 00000000000..82ee7d7cd78 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazurenetworkmappingsettings.go @@ -0,0 +1,42 @@ +package replicationnetworkmappings + +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 _ NetworkMappingFabricSpecificSettings = AzureToAzureNetworkMappingSettings{} + +type AzureToAzureNetworkMappingSettings struct { + PrimaryFabricLocation *string `json:"primaryFabricLocation,omitempty"` + RecoveryFabricLocation *string `json:"recoveryFabricLocation,omitempty"` + + // Fields inherited from NetworkMappingFabricSpecificSettings +} + +var _ json.Marshaler = AzureToAzureNetworkMappingSettings{} + +func (s AzureToAzureNetworkMappingSettings) MarshalJSON() ([]byte, error) { + type wrapper AzureToAzureNetworkMappingSettings + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureToAzureNetworkMappingSettings: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureToAzureNetworkMappingSettings: %+v", err) + } + decoded["instanceType"] = "AzureToAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureToAzureNetworkMappingSettings: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazureupdatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazureupdatenetworkmappinginput.go new file mode 100644 index 00000000000..3df2303a098 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_azuretoazureupdatenetworkmappinginput.go @@ -0,0 +1,41 @@ +package replicationnetworkmappings + +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 _ FabricSpecificUpdateNetworkMappingInput = AzureToAzureUpdateNetworkMappingInput{} + +type AzureToAzureUpdateNetworkMappingInput struct { + PrimaryNetworkId *string `json:"primaryNetworkId,omitempty"` + + // Fields inherited from FabricSpecificUpdateNetworkMappingInput +} + +var _ json.Marshaler = AzureToAzureUpdateNetworkMappingInput{} + +func (s AzureToAzureUpdateNetworkMappingInput) MarshalJSON() ([]byte, error) { + type wrapper AzureToAzureUpdateNetworkMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureToAzureUpdateNetworkMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureToAzureUpdateNetworkMappingInput: %+v", err) + } + decoded["instanceType"] = "AzureToAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureToAzureUpdateNetworkMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_createnetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_createnetworkmappinginput.go new file mode 100644 index 00000000000..1465b2453c9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_createnetworkmappinginput.go @@ -0,0 +1,8 @@ +package replicationnetworkmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateNetworkMappingInput struct { + Properties CreateNetworkMappingInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_createnetworkmappinginputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_createnetworkmappinginputproperties.go new file mode 100644 index 00000000000..43ae6995a54 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_createnetworkmappinginputproperties.go @@ -0,0 +1,42 @@ +package replicationnetworkmappings + +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 CreateNetworkMappingInputProperties struct { + FabricSpecificDetails FabricSpecificCreateNetworkMappingInput `json:"fabricSpecificDetails"` + RecoveryFabricName *string `json:"recoveryFabricName,omitempty"` + RecoveryNetworkId string `json:"recoveryNetworkId"` +} + +var _ json.Unmarshaler = &CreateNetworkMappingInputProperties{} + +func (s *CreateNetworkMappingInputProperties) UnmarshalJSON(bytes []byte) error { + type alias CreateNetworkMappingInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into CreateNetworkMappingInputProperties: %+v", err) + } + + s.RecoveryFabricName = decoded.RecoveryFabricName + s.RecoveryNetworkId = decoded.RecoveryNetworkId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CreateNetworkMappingInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["fabricSpecificDetails"]; ok { + impl, err := unmarshalFabricSpecificCreateNetworkMappingInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'FabricSpecificDetails' for 'CreateNetworkMappingInputProperties': %+v", err) + } + s.FabricSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_fabricspecificcreatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_fabricspecificcreatenetworkmappinginput.go new file mode 100644 index 00000000000..ce5bae473cd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_fabricspecificcreatenetworkmappinginput.go @@ -0,0 +1,64 @@ +package replicationnetworkmappings + +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 FabricSpecificCreateNetworkMappingInput interface { +} + +func unmarshalFabricSpecificCreateNetworkMappingInputImplementation(input []byte) (FabricSpecificCreateNetworkMappingInput, 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 FabricSpecificCreateNetworkMappingInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureToAzure") { + var out AzureToAzureCreateNetworkMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureToAzureCreateNetworkMappingInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VmmToAzure") { + var out VMmToAzureCreateNetworkMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMmToAzureCreateNetworkMappingInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VmmToVmm") { + var out VMmToVMmCreateNetworkMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMmToVMmCreateNetworkMappingInput: %+v", err) + } + return out, nil + } + + type RawFabricSpecificCreateNetworkMappingInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawFabricSpecificCreateNetworkMappingInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_fabricspecificupdatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_fabricspecificupdatenetworkmappinginput.go new file mode 100644 index 00000000000..9eba5f539cd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_fabricspecificupdatenetworkmappinginput.go @@ -0,0 +1,64 @@ +package replicationnetworkmappings + +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 FabricSpecificUpdateNetworkMappingInput interface { +} + +func unmarshalFabricSpecificUpdateNetworkMappingInputImplementation(input []byte) (FabricSpecificUpdateNetworkMappingInput, 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 FabricSpecificUpdateNetworkMappingInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureToAzure") { + var out AzureToAzureUpdateNetworkMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureToAzureUpdateNetworkMappingInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VmmToAzure") { + var out VMmToAzureUpdateNetworkMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMmToAzureUpdateNetworkMappingInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VmmToVmm") { + var out VMmToVMmUpdateNetworkMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMmToVMmUpdateNetworkMappingInput: %+v", err) + } + return out, nil + } + + type RawFabricSpecificUpdateNetworkMappingInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawFabricSpecificUpdateNetworkMappingInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmapping.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmapping.go new file mode 100644 index 00000000000..920122dece0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmapping.go @@ -0,0 +1,12 @@ +package replicationnetworkmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkMapping struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkMappingProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmappingfabricspecificsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmappingfabricspecificsettings.go new file mode 100644 index 00000000000..5132021aca4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmappingfabricspecificsettings.go @@ -0,0 +1,64 @@ +package replicationnetworkmappings + +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 NetworkMappingFabricSpecificSettings interface { +} + +func unmarshalNetworkMappingFabricSpecificSettingsImplementation(input []byte) (NetworkMappingFabricSpecificSettings, 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 NetworkMappingFabricSpecificSettings into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureToAzure") { + var out AzureToAzureNetworkMappingSettings + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureToAzureNetworkMappingSettings: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VmmToAzure") { + var out VMmToAzureNetworkMappingSettings + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMmToAzureNetworkMappingSettings: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VmmToVmm") { + var out VMmToVMmNetworkMappingSettings + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMmToVMmNetworkMappingSettings: %+v", err) + } + return out, nil + } + + type RawNetworkMappingFabricSpecificSettingsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawNetworkMappingFabricSpecificSettingsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmappingproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmappingproperties.go new file mode 100644 index 00000000000..5f4d29ba66e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_networkmappingproperties.go @@ -0,0 +1,54 @@ +package replicationnetworkmappings + +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 NetworkMappingProperties struct { + FabricSpecificSettings NetworkMappingFabricSpecificSettings `json:"fabricSpecificSettings"` + PrimaryFabricFriendlyName *string `json:"primaryFabricFriendlyName,omitempty"` + PrimaryNetworkFriendlyName *string `json:"primaryNetworkFriendlyName,omitempty"` + PrimaryNetworkId *string `json:"primaryNetworkId,omitempty"` + RecoveryFabricArmId *string `json:"recoveryFabricArmId,omitempty"` + RecoveryFabricFriendlyName *string `json:"recoveryFabricFriendlyName,omitempty"` + RecoveryNetworkFriendlyName *string `json:"recoveryNetworkFriendlyName,omitempty"` + RecoveryNetworkId *string `json:"recoveryNetworkId,omitempty"` + State *string `json:"state,omitempty"` +} + +var _ json.Unmarshaler = &NetworkMappingProperties{} + +func (s *NetworkMappingProperties) UnmarshalJSON(bytes []byte) error { + type alias NetworkMappingProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into NetworkMappingProperties: %+v", err) + } + + s.PrimaryFabricFriendlyName = decoded.PrimaryFabricFriendlyName + s.PrimaryNetworkFriendlyName = decoded.PrimaryNetworkFriendlyName + s.PrimaryNetworkId = decoded.PrimaryNetworkId + s.RecoveryFabricArmId = decoded.RecoveryFabricArmId + s.RecoveryFabricFriendlyName = decoded.RecoveryFabricFriendlyName + s.RecoveryNetworkFriendlyName = decoded.RecoveryNetworkFriendlyName + s.RecoveryNetworkId = decoded.RecoveryNetworkId + s.State = decoded.State + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling NetworkMappingProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["fabricSpecificSettings"]; ok { + impl, err := unmarshalNetworkMappingFabricSpecificSettingsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'FabricSpecificSettings' for 'NetworkMappingProperties': %+v", err) + } + s.FabricSpecificSettings = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_updatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_updatenetworkmappinginput.go new file mode 100644 index 00000000000..12c39d59aee --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_updatenetworkmappinginput.go @@ -0,0 +1,8 @@ +package replicationnetworkmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateNetworkMappingInput struct { + Properties *UpdateNetworkMappingInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_updatenetworkmappinginputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_updatenetworkmappinginputproperties.go new file mode 100644 index 00000000000..9f64360d09b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_updatenetworkmappinginputproperties.go @@ -0,0 +1,42 @@ +package replicationnetworkmappings + +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 UpdateNetworkMappingInputProperties struct { + FabricSpecificDetails FabricSpecificUpdateNetworkMappingInput `json:"fabricSpecificDetails"` + RecoveryFabricName *string `json:"recoveryFabricName,omitempty"` + RecoveryNetworkId *string `json:"recoveryNetworkId,omitempty"` +} + +var _ json.Unmarshaler = &UpdateNetworkMappingInputProperties{} + +func (s *UpdateNetworkMappingInputProperties) UnmarshalJSON(bytes []byte) error { + type alias UpdateNetworkMappingInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into UpdateNetworkMappingInputProperties: %+v", err) + } + + s.RecoveryFabricName = decoded.RecoveryFabricName + s.RecoveryNetworkId = decoded.RecoveryNetworkId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling UpdateNetworkMappingInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["fabricSpecificDetails"]; ok { + impl, err := unmarshalFabricSpecificUpdateNetworkMappingInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'FabricSpecificDetails' for 'UpdateNetworkMappingInputProperties': %+v", err) + } + s.FabricSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazurecreatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazurecreatenetworkmappinginput.go new file mode 100644 index 00000000000..e8a8a1a928a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazurecreatenetworkmappinginput.go @@ -0,0 +1,40 @@ +package replicationnetworkmappings + +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 _ FabricSpecificCreateNetworkMappingInput = VMmToAzureCreateNetworkMappingInput{} + +type VMmToAzureCreateNetworkMappingInput struct { + + // Fields inherited from FabricSpecificCreateNetworkMappingInput +} + +var _ json.Marshaler = VMmToAzureCreateNetworkMappingInput{} + +func (s VMmToAzureCreateNetworkMappingInput) MarshalJSON() ([]byte, error) { + type wrapper VMmToAzureCreateNetworkMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmToAzureCreateNetworkMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmToAzureCreateNetworkMappingInput: %+v", err) + } + decoded["instanceType"] = "VmmToAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmToAzureCreateNetworkMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazurenetworkmappingsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazurenetworkmappingsettings.go new file mode 100644 index 00000000000..aa741d5d144 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazurenetworkmappingsettings.go @@ -0,0 +1,40 @@ +package replicationnetworkmappings + +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 _ NetworkMappingFabricSpecificSettings = VMmToAzureNetworkMappingSettings{} + +type VMmToAzureNetworkMappingSettings struct { + + // Fields inherited from NetworkMappingFabricSpecificSettings +} + +var _ json.Marshaler = VMmToAzureNetworkMappingSettings{} + +func (s VMmToAzureNetworkMappingSettings) MarshalJSON() ([]byte, error) { + type wrapper VMmToAzureNetworkMappingSettings + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmToAzureNetworkMappingSettings: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmToAzureNetworkMappingSettings: %+v", err) + } + decoded["instanceType"] = "VmmToAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmToAzureNetworkMappingSettings: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazureupdatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazureupdatenetworkmappinginput.go new file mode 100644 index 00000000000..b496ae4ae1f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtoazureupdatenetworkmappinginput.go @@ -0,0 +1,40 @@ +package replicationnetworkmappings + +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 _ FabricSpecificUpdateNetworkMappingInput = VMmToAzureUpdateNetworkMappingInput{} + +type VMmToAzureUpdateNetworkMappingInput struct { + + // Fields inherited from FabricSpecificUpdateNetworkMappingInput +} + +var _ json.Marshaler = VMmToAzureUpdateNetworkMappingInput{} + +func (s VMmToAzureUpdateNetworkMappingInput) MarshalJSON() ([]byte, error) { + type wrapper VMmToAzureUpdateNetworkMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmToAzureUpdateNetworkMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmToAzureUpdateNetworkMappingInput: %+v", err) + } + decoded["instanceType"] = "VmmToAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmToAzureUpdateNetworkMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmcreatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmcreatenetworkmappinginput.go new file mode 100644 index 00000000000..62ecb90d0ff --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmcreatenetworkmappinginput.go @@ -0,0 +1,40 @@ +package replicationnetworkmappings + +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 _ FabricSpecificCreateNetworkMappingInput = VMmToVMmCreateNetworkMappingInput{} + +type VMmToVMmCreateNetworkMappingInput struct { + + // Fields inherited from FabricSpecificCreateNetworkMappingInput +} + +var _ json.Marshaler = VMmToVMmCreateNetworkMappingInput{} + +func (s VMmToVMmCreateNetworkMappingInput) MarshalJSON() ([]byte, error) { + type wrapper VMmToVMmCreateNetworkMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmToVMmCreateNetworkMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmToVMmCreateNetworkMappingInput: %+v", err) + } + decoded["instanceType"] = "VmmToVmm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmToVMmCreateNetworkMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmnetworkmappingsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmnetworkmappingsettings.go new file mode 100644 index 00000000000..b82ddcde87f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmnetworkmappingsettings.go @@ -0,0 +1,40 @@ +package replicationnetworkmappings + +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 _ NetworkMappingFabricSpecificSettings = VMmToVMmNetworkMappingSettings{} + +type VMmToVMmNetworkMappingSettings struct { + + // Fields inherited from NetworkMappingFabricSpecificSettings +} + +var _ json.Marshaler = VMmToVMmNetworkMappingSettings{} + +func (s VMmToVMmNetworkMappingSettings) MarshalJSON() ([]byte, error) { + type wrapper VMmToVMmNetworkMappingSettings + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmToVMmNetworkMappingSettings: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmToVMmNetworkMappingSettings: %+v", err) + } + decoded["instanceType"] = "VmmToVmm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmToVMmNetworkMappingSettings: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmupdatenetworkmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmupdatenetworkmappinginput.go new file mode 100644 index 00000000000..c26929ad37a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/model_vmmtovmmupdatenetworkmappinginput.go @@ -0,0 +1,40 @@ +package replicationnetworkmappings + +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 _ FabricSpecificUpdateNetworkMappingInput = VMmToVMmUpdateNetworkMappingInput{} + +type VMmToVMmUpdateNetworkMappingInput struct { + + // Fields inherited from FabricSpecificUpdateNetworkMappingInput +} + +var _ json.Marshaler = VMmToVMmUpdateNetworkMappingInput{} + +func (s VMmToVMmUpdateNetworkMappingInput) MarshalJSON() ([]byte, error) { + type wrapper VMmToVMmUpdateNetworkMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmToVMmUpdateNetworkMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmToVMmUpdateNetworkMappingInput: %+v", err) + } + decoded["instanceType"] = "VmmToVmm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmToVMmUpdateNetworkMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/predicates.go new file mode 100644 index 00000000000..d3d33679bde --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/predicates.go @@ -0,0 +1,32 @@ +package replicationnetworkmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkMappingOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NetworkMappingOperationPredicate) Matches(input NetworkMapping) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/version.go new file mode 100644 index 00000000000..fda0a5f5c7a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworkmappings/version.go @@ -0,0 +1,12 @@ +package replicationnetworkmappings + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationnetworkmappings/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/README.md new file mode 100644 index 00000000000..dbaa0e67590 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks` Documentation + +The `replicationnetworks` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationnetworks" +``` + + +### Client Initialization + +```go +client := replicationnetworks.NewReplicationNetworksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationNetworksClient.Get` + +```go +ctx := context.TODO() +id := replicationnetworks.NewReplicationNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue") + +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: `ReplicationNetworksClient.List` + +```go +ctx := context.TODO() +id := replicationnetworks.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationNetworksClient.ListByReplicationFabrics` + +```go +ctx := context.TODO() +id := replicationnetworks.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +// alternatively `client.ListByReplicationFabrics(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationFabricsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/client.go new file mode 100644 index 00000000000..13a853fab01 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/client.go @@ -0,0 +1,18 @@ +package replicationnetworks + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationNetworksClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationNetworksClientWithBaseURI(endpoint string) ReplicationNetworksClient { + return ReplicationNetworksClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationfabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationfabric.go new file mode 100644 index 00000000000..d70f889ac02 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationnetworks + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationfabric_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationfabric_test.go new file mode 100644 index 00000000000..da63804a31a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationfabric_test.go @@ -0,0 +1,327 @@ +package replicationnetworks + +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 = ReplicationFabricId{} + +func TestNewReplicationFabricID(t *testing.T) { + id := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } +} + +func TestFormatReplicationFabricID(t *testing.T) { + actual := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestParseReplicationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestSegmentsForReplicationFabricId(t *testing.T) { + segments := ReplicationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationFabricId 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/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationnetwork.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationnetwork.go new file mode 100644 index 00000000000..58c0904d971 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationnetwork.go @@ -0,0 +1,153 @@ +package replicationnetworks + +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 = ReplicationNetworkId{} + +// ReplicationNetworkId is a struct representing the Resource ID for a Replication Network +type ReplicationNetworkId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationNetworkName string +} + +// NewReplicationNetworkID returns a new ReplicationNetworkId struct +func NewReplicationNetworkID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationNetworkName string) ReplicationNetworkId { + return ReplicationNetworkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationNetworkName: replicationNetworkName, + } +} + +// ParseReplicationNetworkID parses 'input' into a ReplicationNetworkId +func ParseReplicationNetworkID(input string) (*ReplicationNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationNetworkIDInsensitively parses 'input' case-insensitively into a ReplicationNetworkId +// note: this method should only be used for API response data and not user input +func ParseReplicationNetworkIDInsensitively(input string) (*ReplicationNetworkId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationNetworkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationNetworkId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationNetworkName, ok = parsed.Parsed["replicationNetworkName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationNetworkName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationNetworkID checks that 'input' can be parsed as a Replication Network ID +func ValidateReplicationNetworkID(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 := ParseReplicationNetworkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Network ID +func (id ReplicationNetworkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationNetworks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationNetworkName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Network ID +func (id ReplicationNetworkId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationNetworks", "replicationNetworks", "replicationNetworks"), + resourceids.UserSpecifiedSegment("replicationNetworkName", "replicationNetworkValue"), + } +} + +// String returns a human-readable description of this Replication Network ID +func (id ReplicationNetworkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Network Name: %q", id.ReplicationNetworkName), + } + return fmt.Sprintf("Replication Network (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationnetwork_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationnetwork_test.go new file mode 100644 index 00000000000..8a0f99ecfa3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_replicationnetwork_test.go @@ -0,0 +1,372 @@ +package replicationnetworks + +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 = ReplicationNetworkId{} + +func TestNewReplicationNetworkID(t *testing.T) { + id := NewReplicationNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationNetworkName != "replicationNetworkValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationNetworkName'", id.ReplicationNetworkName, "replicationNetworkValue") + } +} + +func TestFormatReplicationNetworkID(t *testing.T) { + actual := NewReplicationNetworkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationNetworkValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationNetworkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationNetworkId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue", + Expected: &ReplicationNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationNetworkName: "replicationNetworkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationNetworkID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationNetworkName != v.Expected.ReplicationNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkName", v.Expected.ReplicationNetworkName, actual.ReplicationNetworkName) + } + + } +} + +func TestParseReplicationNetworkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationNetworkId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue", + Expected: &ReplicationNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationNetworkName: "replicationNetworkValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationNetworks/replicationNetworkValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe", + Expected: &ReplicationNetworkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationNetworkName: "rEpLiCaTiOnNeTwOrKvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnNeTwOrKs/rEpLiCaTiOnNeTwOrKvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationNetworkIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationNetworkName != v.Expected.ReplicationNetworkName { + t.Fatalf("Expected %q but got %q for ReplicationNetworkName", v.Expected.ReplicationNetworkName, actual.ReplicationNetworkName) + } + + } +} + +func TestSegmentsForReplicationNetworkId(t *testing.T) { + segments := ReplicationNetworkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationNetworkId 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/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_vault.go new file mode 100644 index 00000000000..084c80d4431 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_vault.go @@ -0,0 +1,127 @@ +package replicationnetworks + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_vault_test.go new file mode 100644 index 00000000000..46e826945bb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationnetworks + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_get_autorest.go new file mode 100644 index 00000000000..38146e2d3d5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationnetworks + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Network +} + +// Get ... +func (c ReplicationNetworksClient) Get(ctx context.Context, id ReplicationNetworkId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationNetworksClient) preparerForGet(ctx context.Context, id ReplicationNetworkId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationNetworksClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_list_autorest.go new file mode 100644 index 00000000000..075aca6607d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationnetworks + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Network + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Network +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationNetworksClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationNetworksClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationNetworks", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationNetworksClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationNetworksClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Network `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationNetworksClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, NetworkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationNetworksClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate NetworkOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Network, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_listbyreplicationfabrics_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_listbyreplicationfabrics_autorest.go new file mode 100644 index 00000000000..e9d8ef73e15 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/method_listbyreplicationfabrics_autorest.go @@ -0,0 +1,186 @@ +package replicationnetworks + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationFabricsOperationResponse struct { + HttpResponse *http.Response + Model *[]Network + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationFabricsOperationResponse, error) +} + +type ListByReplicationFabricsCompleteResult struct { + Items []Network +} + +func (r ListByReplicationFabricsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationFabricsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationFabricsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationFabrics ... +func (c ReplicationNetworksClient) ListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (resp ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabrics(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationFabrics(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationFabrics prepares the ListByReplicationFabrics request. +func (c ReplicationNetworksClient) preparerForListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationNetworks", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationFabricsWithNextLink prepares the ListByReplicationFabrics request with the given nextLink token. +func (c ReplicationNetworksClient) preparerForListByReplicationFabricsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationFabrics handles the response to the ListByReplicationFabrics request. The method always +// closes the http.Response Body. +func (c ReplicationNetworksClient) responderForListByReplicationFabrics(resp *http.Response) (result ListByReplicationFabricsOperationResponse, err error) { + type page struct { + Values []Network `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabricsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationFabrics(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationnetworks.ReplicationNetworksClient", "ListByReplicationFabrics", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationFabricsComplete retrieves all of the results into a single object +func (c ReplicationNetworksClient) ListByReplicationFabricsComplete(ctx context.Context, id ReplicationFabricId) (ListByReplicationFabricsCompleteResult, error) { + return c.ListByReplicationFabricsCompleteMatchingPredicate(ctx, id, NetworkOperationPredicate{}) +} + +// ListByReplicationFabricsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationNetworksClient) ListByReplicationFabricsCompleteMatchingPredicate(ctx context.Context, id ReplicationFabricId, predicate NetworkOperationPredicate) (resp ListByReplicationFabricsCompleteResult, err error) { + items := make([]Network, 0) + + page, err := c.ListByReplicationFabrics(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationFabricsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_network.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_network.go new file mode 100644 index 00000000000..a55b39eacf2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_network.go @@ -0,0 +1,12 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Network struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_networkproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_networkproperties.go new file mode 100644 index 00000000000..7a2c7204a97 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_networkproperties.go @@ -0,0 +1,11 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkProperties struct { + FabricType *string `json:"fabricType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + NetworkType *string `json:"networkType,omitempty"` + Subnets *[]Subnet `json:"subnets,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_subnet.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_subnet.go new file mode 100644 index 00000000000..fed1f4919d8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/model_subnet.go @@ -0,0 +1,10 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Subnet struct { + AddressList *[]string `json:"addressList,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/predicates.go new file mode 100644 index 00000000000..7cf85d61c5a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/predicates.go @@ -0,0 +1,32 @@ +package replicationnetworks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NetworkOperationPredicate) Matches(input Network) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationnetworks/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/version.go new file mode 100644 index 00000000000..e5bd6aa81a2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationnetworks/version.go @@ -0,0 +1,12 @@ +package replicationnetworks + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationnetworks/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/README.md new file mode 100644 index 00000000000..bd40a7c0b0e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies` Documentation + +The `replicationpolicies` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationpolicies" +``` + + +### Client Initialization + +```go +client := replicationpolicies.NewReplicationPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationPoliciesClient.Create` + +```go +ctx := context.TODO() +id := replicationpolicies.NewReplicationPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationPolicyValue") + +payload := replicationpolicies.CreatePolicyInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := replicationpolicies.NewReplicationPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationPolicyValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationPoliciesClient.Get` + +```go +ctx := context.TODO() +id := replicationpolicies.NewReplicationPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationPolicyValue") + +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: `ReplicationPoliciesClient.List` + +```go +ctx := context.TODO() +id := replicationpolicies.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationPoliciesClient.Update` + +```go +ctx := context.TODO() +id := replicationpolicies.NewReplicationPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationPolicyValue") + +payload := replicationpolicies.UpdatePolicyInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/client.go new file mode 100644 index 00000000000..51a99a96155 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/client.go @@ -0,0 +1,18 @@ +package replicationpolicies + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationPoliciesClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationPoliciesClientWithBaseURI(endpoint string) ReplicationPoliciesClient { + return ReplicationPoliciesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/constants.go new file mode 100644 index 00000000000..50f7c5337b6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/constants.go @@ -0,0 +1,34 @@ +package replicationpolicies + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SetMultiVMSyncStatus string + +const ( + SetMultiVMSyncStatusDisable SetMultiVMSyncStatus = "Disable" + SetMultiVMSyncStatusEnable SetMultiVMSyncStatus = "Enable" +) + +func PossibleValuesForSetMultiVMSyncStatus() []string { + return []string{ + string(SetMultiVMSyncStatusDisable), + string(SetMultiVMSyncStatusEnable), + } +} + +func parseSetMultiVMSyncStatus(input string) (*SetMultiVMSyncStatus, error) { + vals := map[string]SetMultiVMSyncStatus{ + "disable": SetMultiVMSyncStatusDisable, + "enable": SetMultiVMSyncStatusEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SetMultiVMSyncStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_replicationpolicy.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_replicationpolicy.go new file mode 100644 index 00000000000..7b6bff157a1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_replicationpolicy.go @@ -0,0 +1,140 @@ +package replicationpolicies + +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 = ReplicationPolicyId{} + +// ReplicationPolicyId is a struct representing the Resource ID for a Replication Policy +type ReplicationPolicyId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationPolicyName string +} + +// NewReplicationPolicyID returns a new ReplicationPolicyId struct +func NewReplicationPolicyID(subscriptionId string, resourceGroupName string, vaultName string, replicationPolicyName string) ReplicationPolicyId { + return ReplicationPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationPolicyName: replicationPolicyName, + } +} + +// ParseReplicationPolicyID parses 'input' into a ReplicationPolicyId +func ParseReplicationPolicyID(input string) (*ReplicationPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationPolicyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationPolicyName, ok = parsed.Parsed["replicationPolicyName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationPolicyName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationPolicyIDInsensitively parses 'input' case-insensitively into a ReplicationPolicyId +// note: this method should only be used for API response data and not user input +func ParseReplicationPolicyIDInsensitively(input string) (*ReplicationPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationPolicyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationPolicyName, ok = parsed.Parsed["replicationPolicyName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationPolicyName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationPolicyID checks that 'input' can be parsed as a Replication Policy ID +func ValidateReplicationPolicyID(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 := ParseReplicationPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Policy ID +func (id ReplicationPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Policy ID +func (id ReplicationPolicyId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationPolicies", "replicationPolicies", "replicationPolicies"), + resourceids.UserSpecifiedSegment("replicationPolicyName", "replicationPolicyValue"), + } +} + +// String returns a human-readable description of this Replication Policy ID +func (id ReplicationPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Policy Name: %q", id.ReplicationPolicyName), + } + return fmt.Sprintf("Replication Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_replicationpolicy_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_replicationpolicy_test.go new file mode 100644 index 00000000000..2a7fc90a784 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_replicationpolicy_test.go @@ -0,0 +1,327 @@ +package replicationpolicies + +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 = ReplicationPolicyId{} + +func TestNewReplicationPolicyID(t *testing.T) { + id := NewReplicationPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationPolicyValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationPolicyName != "replicationPolicyValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationPolicyName'", id.ReplicationPolicyName, "replicationPolicyValue") + } +} + +func TestFormatReplicationPolicyID(t *testing.T) { + actual := NewReplicationPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationPolicyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationPolicies/replicationPolicyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationPolicyId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationPolicies/replicationPolicyValue", + Expected: &ReplicationPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationPolicyName: "replicationPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationPolicies/replicationPolicyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationPolicyID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationPolicyName != v.Expected.ReplicationPolicyName { + t.Fatalf("Expected %q but got %q for ReplicationPolicyName", v.Expected.ReplicationPolicyName, actual.ReplicationPolicyName) + } + + } +} + +func TestParseReplicationPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationPolicyId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnPoLiCiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationPolicies/replicationPolicyValue", + Expected: &ReplicationPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationPolicyName: "replicationPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationPolicies/replicationPolicyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnPoLiCiEs/rEpLiCaTiOnPoLiCyVaLuE", + Expected: &ReplicationPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationPolicyName: "rEpLiCaTiOnPoLiCyVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnPoLiCiEs/rEpLiCaTiOnPoLiCyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationPolicyIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationPolicyName != v.Expected.ReplicationPolicyName { + t.Fatalf("Expected %q but got %q for ReplicationPolicyName", v.Expected.ReplicationPolicyName, actual.ReplicationPolicyName) + } + + } +} + +func TestSegmentsForReplicationPolicyId(t *testing.T) { + segments := ReplicationPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationPolicyId 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/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_vault.go new file mode 100644 index 00000000000..6e0d4121e5d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_vault.go @@ -0,0 +1,127 @@ +package replicationpolicies + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_vault_test.go new file mode 100644 index 00000000000..9e7f29e3ade --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationpolicies + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_create_autorest.go new file mode 100644 index 00000000000..df52b837530 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationPoliciesClient) Create(ctx context.Context, id ReplicationPolicyId, input CreatePolicyInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationPoliciesClient) CreateThenPoll(ctx context.Context, id ReplicationPolicyId, input CreatePolicyInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationPoliciesClient) preparerForCreate(ctx context.Context, id ReplicationPolicyId, input CreatePolicyInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationPoliciesClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_delete_autorest.go new file mode 100644 index 00000000000..390eeb314c4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationPoliciesClient) Delete(ctx context.Context, id ReplicationPolicyId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationPoliciesClient) DeleteThenPoll(ctx context.Context, id ReplicationPolicyId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationPoliciesClient) preparerForDelete(ctx context.Context, id ReplicationPolicyId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationPoliciesClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_get_autorest.go new file mode 100644 index 00000000000..1cd4fbb34ac --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationpolicies + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *Policy +} + +// Get ... +func (c ReplicationPoliciesClient) Get(ctx context.Context, id ReplicationPolicyId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationPoliciesClient) preparerForGet(ctx context.Context, id ReplicationPolicyId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationPoliciesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_list_autorest.go new file mode 100644 index 00000000000..37f1e65558d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationpolicies + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]Policy + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []Policy +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationPoliciesClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationPoliciesClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationPolicies", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationPoliciesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationPoliciesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []Policy `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationPoliciesClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PolicyOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationPoliciesClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate PolicyOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]Policy, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_update_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_update_autorest.go new file mode 100644 index 00000000000..8276c7d8311 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/method_update_autorest.go @@ -0,0 +1,79 @@ +package replicationpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ReplicationPoliciesClient) Update(ctx context.Context, id ReplicationPolicyId, input UpdatePolicyInput) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationpolicies.ReplicationPoliciesClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationPoliciesClient) UpdateThenPoll(ctx context.Context, id ReplicationPolicyId, input UpdatePolicyInput) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ReplicationPoliciesClient) preparerForUpdate(ctx context.Context, id ReplicationPolicyId, input UpdatePolicyInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationPoliciesClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2acrossclustermigrationpolicycreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2acrossclustermigrationpolicycreationinput.go new file mode 100644 index 00000000000..b45a259a55f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2acrossclustermigrationpolicycreationinput.go @@ -0,0 +1,40 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = A2ACrossClusterMigrationPolicyCreationInput{} + +type A2ACrossClusterMigrationPolicyCreationInput struct { + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = A2ACrossClusterMigrationPolicyCreationInput{} + +func (s A2ACrossClusterMigrationPolicyCreationInput) MarshalJSON() ([]byte, error) { + type wrapper A2ACrossClusterMigrationPolicyCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ACrossClusterMigrationPolicyCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ACrossClusterMigrationPolicyCreationInput: %+v", err) + } + decoded["instanceType"] = "A2ACrossClusterMigration" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ACrossClusterMigrationPolicyCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2apolicycreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2apolicycreationinput.go new file mode 100644 index 00000000000..cbaba9db768 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2apolicycreationinput.go @@ -0,0 +1,44 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = A2APolicyCreationInput{} + +type A2APolicyCreationInput struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus SetMultiVMSyncStatus `json:"multiVmSyncStatus"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = A2APolicyCreationInput{} + +func (s A2APolicyCreationInput) MarshalJSON() ([]byte, error) { + type wrapper A2APolicyCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2APolicyCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2APolicyCreationInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2APolicyCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2apolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2apolicydetails.go new file mode 100644 index 00000000000..3aa1c5f9fb7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_a2apolicydetails.go @@ -0,0 +1,45 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = A2APolicyDetails{} + +type A2APolicyDetails struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus *string `json:"multiVmSyncStatus,omitempty"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + RecoveryPointThresholdInMinutes *int64 `json:"recoveryPointThresholdInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = A2APolicyDetails{} + +func (s A2APolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper A2APolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2APolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2APolicyDetails: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2APolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_createpolicyinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_createpolicyinput.go new file mode 100644 index 00000000000..a1cb3c60fe8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_createpolicyinput.go @@ -0,0 +1,8 @@ +package replicationpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreatePolicyInput struct { + Properties *CreatePolicyInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_createpolicyinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_createpolicyinputproperties.go new file mode 100644 index 00000000000..6e5638e6871 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_createpolicyinputproperties.go @@ -0,0 +1,32 @@ +package replicationpolicies + +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 CreatePolicyInputProperties struct { + ProviderSpecificInput PolicyProviderSpecificInput `json:"providerSpecificInput"` +} + +var _ json.Unmarshaler = &CreatePolicyInputProperties{} + +func (s *CreatePolicyInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CreatePolicyInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificInput"]; ok { + impl, err := unmarshalPolicyProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificInput' for 'CreatePolicyInputProperties': %+v", err) + } + s.ProviderSpecificInput = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicaazurepolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicaazurepolicydetails.go new file mode 100644 index 00000000000..775075b8d2a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicaazurepolicydetails.go @@ -0,0 +1,46 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = HyperVReplicaAzurePolicyDetails{} + +type HyperVReplicaAzurePolicyDetails struct { + ActiveStorageAccountId *string `json:"activeStorageAccountId,omitempty"` + ApplicationConsistentSnapshotFrequencyInHours *int64 `json:"applicationConsistentSnapshotFrequencyInHours,omitempty"` + Encryption *string `json:"encryption,omitempty"` + OnlineReplicationStartTime *string `json:"onlineReplicationStartTime,omitempty"` + RecoveryPointHistoryDurationInHours *int64 `json:"recoveryPointHistoryDurationInHours,omitempty"` + ReplicationInterval *int64 `json:"replicationInterval,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplicaAzurePolicyDetails{} + +func (s HyperVReplicaAzurePolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzurePolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzurePolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzurePolicyDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzurePolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicaazurepolicyinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicaazurepolicyinput.go new file mode 100644 index 00000000000..46599f8373b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicaazurepolicyinput.go @@ -0,0 +1,45 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = HyperVReplicaAzurePolicyInput{} + +type HyperVReplicaAzurePolicyInput struct { + ApplicationConsistentSnapshotFrequencyInHours *int64 `json:"applicationConsistentSnapshotFrequencyInHours,omitempty"` + OnlineReplicationStartTime *string `json:"onlineReplicationStartTime,omitempty"` + RecoveryPointHistoryDuration *int64 `json:"recoveryPointHistoryDuration,omitempty"` + ReplicationInterval *int64 `json:"replicationInterval,omitempty"` + StorageAccounts *[]string `json:"storageAccounts,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = HyperVReplicaAzurePolicyInput{} + +func (s HyperVReplicaAzurePolicyInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzurePolicyInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzurePolicyInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzurePolicyInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzurePolicyInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabasepolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabasepolicydetails.go new file mode 100644 index 00000000000..12bfc95a141 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabasepolicydetails.go @@ -0,0 +1,50 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = HyperVReplicaBasePolicyDetails{} + +type HyperVReplicaBasePolicyDetails struct { + AllowedAuthenticationType *int64 `json:"allowedAuthenticationType,omitempty"` + ApplicationConsistentSnapshotFrequencyInHours *int64 `json:"applicationConsistentSnapshotFrequencyInHours,omitempty"` + Compression *string `json:"compression,omitempty"` + InitialReplicationMethod *string `json:"initialReplicationMethod,omitempty"` + OfflineReplicationExportPath *string `json:"offlineReplicationExportPath,omitempty"` + OfflineReplicationImportPath *string `json:"offlineReplicationImportPath,omitempty"` + OnlineReplicationStartTime *string `json:"onlineReplicationStartTime,omitempty"` + RecoveryPoints *int64 `json:"recoveryPoints,omitempty"` + ReplicaDeletionOption *string `json:"replicaDeletionOption,omitempty"` + ReplicationPort *int64 `json:"replicationPort,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplicaBasePolicyDetails{} + +func (s HyperVReplicaBasePolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaBasePolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaBasePolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaBasePolicyDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaBasePolicyDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaBasePolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabluepolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabluepolicydetails.go new file mode 100644 index 00000000000..ea551ee41d6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabluepolicydetails.go @@ -0,0 +1,51 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = HyperVReplicaBluePolicyDetails{} + +type HyperVReplicaBluePolicyDetails struct { + AllowedAuthenticationType *int64 `json:"allowedAuthenticationType,omitempty"` + ApplicationConsistentSnapshotFrequencyInHours *int64 `json:"applicationConsistentSnapshotFrequencyInHours,omitempty"` + Compression *string `json:"compression,omitempty"` + InitialReplicationMethod *string `json:"initialReplicationMethod,omitempty"` + OfflineReplicationExportPath *string `json:"offlineReplicationExportPath,omitempty"` + OfflineReplicationImportPath *string `json:"offlineReplicationImportPath,omitempty"` + OnlineReplicationStartTime *string `json:"onlineReplicationStartTime,omitempty"` + RecoveryPoints *int64 `json:"recoveryPoints,omitempty"` + ReplicaDeletionOption *string `json:"replicaDeletionOption,omitempty"` + ReplicationFrequencyInSeconds *int64 `json:"replicationFrequencyInSeconds,omitempty"` + ReplicationPort *int64 `json:"replicationPort,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplicaBluePolicyDetails{} + +func (s HyperVReplicaBluePolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaBluePolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaBluePolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaBluePolicyDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012R2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaBluePolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabluepolicyinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabluepolicyinput.go new file mode 100644 index 00000000000..be141866872 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicabluepolicyinput.go @@ -0,0 +1,51 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = HyperVReplicaBluePolicyInput{} + +type HyperVReplicaBluePolicyInput struct { + ReplicationFrequencyInSeconds *int64 `json:"replicationFrequencyInSeconds,omitempty"` + + // Fields inherited from HyperVReplicaPolicyInput + AllowedAuthenticationType *int64 `json:"allowedAuthenticationType,omitempty"` + ApplicationConsistentSnapshotFrequencyInHours *int64 `json:"applicationConsistentSnapshotFrequencyInHours,omitempty"` + Compression *string `json:"compression,omitempty"` + InitialReplicationMethod *string `json:"initialReplicationMethod,omitempty"` + OfflineReplicationExportPath *string `json:"offlineReplicationExportPath,omitempty"` + OfflineReplicationImportPath *string `json:"offlineReplicationImportPath,omitempty"` + OnlineReplicationStartTime *string `json:"onlineReplicationStartTime,omitempty"` + RecoveryPoints *int64 `json:"recoveryPoints,omitempty"` + ReplicaDeletion *string `json:"replicaDeletion,omitempty"` + ReplicationPort *int64 `json:"replicationPort,omitempty"` +} + +var _ json.Marshaler = HyperVReplicaBluePolicyInput{} + +func (s HyperVReplicaBluePolicyInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaBluePolicyInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaBluePolicyInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaBluePolicyInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012R2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaBluePolicyInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicapolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicapolicydetails.go new file mode 100644 index 00000000000..af3773107b1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicapolicydetails.go @@ -0,0 +1,50 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = HyperVReplicaPolicyDetails{} + +type HyperVReplicaPolicyDetails struct { + AllowedAuthenticationType *int64 `json:"allowedAuthenticationType,omitempty"` + ApplicationConsistentSnapshotFrequencyInHours *int64 `json:"applicationConsistentSnapshotFrequencyInHours,omitempty"` + Compression *string `json:"compression,omitempty"` + InitialReplicationMethod *string `json:"initialReplicationMethod,omitempty"` + OfflineReplicationExportPath *string `json:"offlineReplicationExportPath,omitempty"` + OfflineReplicationImportPath *string `json:"offlineReplicationImportPath,omitempty"` + OnlineReplicationStartTime *string `json:"onlineReplicationStartTime,omitempty"` + RecoveryPoints *int64 `json:"recoveryPoints,omitempty"` + ReplicaDeletionOption *string `json:"replicaDeletionOption,omitempty"` + ReplicationPort *int64 `json:"replicationPort,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = HyperVReplicaPolicyDetails{} + +func (s HyperVReplicaPolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaPolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaPolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaPolicyDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaPolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicapolicyinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicapolicyinput.go new file mode 100644 index 00000000000..b8882e26d4e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_hypervreplicapolicyinput.go @@ -0,0 +1,50 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = HyperVReplicaPolicyInput{} + +type HyperVReplicaPolicyInput struct { + AllowedAuthenticationType *int64 `json:"allowedAuthenticationType,omitempty"` + ApplicationConsistentSnapshotFrequencyInHours *int64 `json:"applicationConsistentSnapshotFrequencyInHours,omitempty"` + Compression *string `json:"compression,omitempty"` + InitialReplicationMethod *string `json:"initialReplicationMethod,omitempty"` + OfflineReplicationExportPath *string `json:"offlineReplicationExportPath,omitempty"` + OfflineReplicationImportPath *string `json:"offlineReplicationImportPath,omitempty"` + OnlineReplicationStartTime *string `json:"onlineReplicationStartTime,omitempty"` + RecoveryPoints *int64 `json:"recoveryPoints,omitempty"` + ReplicaDeletion *string `json:"replicaDeletion,omitempty"` + ReplicationPort *int64 `json:"replicationPort,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = HyperVReplicaPolicyInput{} + +func (s HyperVReplicaPolicyInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaPolicyInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaPolicyInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaPolicyInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaPolicyInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmageazurev2policydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmageazurev2policydetails.go new file mode 100644 index 00000000000..561d2d868c5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmageazurev2policydetails.go @@ -0,0 +1,45 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = InMageAzureV2PolicyDetails{} + +type InMageAzureV2PolicyDetails struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus *string `json:"multiVmSyncStatus,omitempty"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + RecoveryPointThresholdInMinutes *int64 `json:"recoveryPointThresholdInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = InMageAzureV2PolicyDetails{} + +func (s InMageAzureV2PolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2PolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2PolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2PolicyDetails: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2PolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmageazurev2policyinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmageazurev2policyinput.go new file mode 100644 index 00000000000..7e42a20f0e1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmageazurev2policyinput.go @@ -0,0 +1,45 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = InMageAzureV2PolicyInput{} + +type InMageAzureV2PolicyInput struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus SetMultiVMSyncStatus `json:"multiVmSyncStatus"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + RecoveryPointThresholdInMinutes *int64 `json:"recoveryPointThresholdInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = InMageAzureV2PolicyInput{} + +func (s InMageAzureV2PolicyInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2PolicyInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2PolicyInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2PolicyInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2PolicyInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagebasepolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagebasepolicydetails.go new file mode 100644 index 00000000000..a9aa31dee55 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagebasepolicydetails.go @@ -0,0 +1,44 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = InMageBasePolicyDetails{} + +type InMageBasePolicyDetails struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus *string `json:"multiVmSyncStatus,omitempty"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + RecoveryPointThresholdInMinutes *int64 `json:"recoveryPointThresholdInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = InMageBasePolicyDetails{} + +func (s InMageBasePolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageBasePolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageBasePolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageBasePolicyDetails: %+v", err) + } + decoded["instanceType"] = "InMageBasePolicyDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageBasePolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagepolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagepolicydetails.go new file mode 100644 index 00000000000..e5eb997e2da --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagepolicydetails.go @@ -0,0 +1,44 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = InMagePolicyDetails{} + +type InMagePolicyDetails struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus *string `json:"multiVmSyncStatus,omitempty"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + RecoveryPointThresholdInMinutes *int64 `json:"recoveryPointThresholdInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = InMagePolicyDetails{} + +func (s InMagePolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper InMagePolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMagePolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMagePolicyDetails: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMagePolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagepolicyinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagepolicyinput.go new file mode 100644 index 00000000000..6d9e7b1e90a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagepolicyinput.go @@ -0,0 +1,44 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = InMagePolicyInput{} + +type InMagePolicyInput struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus SetMultiVMSyncStatus `json:"multiVmSyncStatus"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + RecoveryPointThresholdInMinutes *int64 `json:"recoveryPointThresholdInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = InMagePolicyInput{} + +func (s InMagePolicyInput) MarshalJSON() ([]byte, error) { + type wrapper InMagePolicyInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMagePolicyInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMagePolicyInput: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMagePolicyInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmfailbackpolicycreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmfailbackpolicycreationinput.go new file mode 100644 index 00000000000..2939b3a5096 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmfailbackpolicycreationinput.go @@ -0,0 +1,42 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = InMageRcmFailbackPolicyCreationInput{} + +type InMageRcmFailbackPolicyCreationInput struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmFailbackPolicyCreationInput{} + +func (s InMageRcmFailbackPolicyCreationInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFailbackPolicyCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFailbackPolicyCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFailbackPolicyCreationInput: %+v", err) + } + decoded["instanceType"] = "InMageRcmFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFailbackPolicyCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmfailbackpolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmfailbackpolicydetails.go new file mode 100644 index 00000000000..610cd07baff --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmfailbackpolicydetails.go @@ -0,0 +1,42 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = InMageRcmFailbackPolicyDetails{} + +type InMageRcmFailbackPolicyDetails struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = InMageRcmFailbackPolicyDetails{} + +func (s InMageRcmFailbackPolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFailbackPolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFailbackPolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFailbackPolicyDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcmFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFailbackPolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmpolicycreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmpolicycreationinput.go new file mode 100644 index 00000000000..1960d5ce36e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmpolicycreationinput.go @@ -0,0 +1,44 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = InMageRcmPolicyCreationInput{} + +type InMageRcmPolicyCreationInput struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + EnableMultiVMSync *string `json:"enableMultiVmSync,omitempty"` + RecoveryPointHistoryInMinutes *int64 `json:"recoveryPointHistoryInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmPolicyCreationInput{} + +func (s InMageRcmPolicyCreationInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmPolicyCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmPolicyCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmPolicyCreationInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmPolicyCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmpolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmpolicydetails.go new file mode 100644 index 00000000000..6d682e3127c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_inmagercmpolicydetails.go @@ -0,0 +1,44 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = InMageRcmPolicyDetails{} + +type InMageRcmPolicyDetails struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + EnableMultiVMSync *string `json:"enableMultiVmSync,omitempty"` + RecoveryPointHistoryInMinutes *int64 `json:"recoveryPointHistoryInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = InMageRcmPolicyDetails{} + +func (s InMageRcmPolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmPolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmPolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmPolicyDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmPolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policy.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policy.go new file mode 100644 index 00000000000..f57b4a8530b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policy.go @@ -0,0 +1,12 @@ +package replicationpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Policy struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproperties.go new file mode 100644 index 00000000000..3f6d1fd8bfa --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproperties.go @@ -0,0 +1,40 @@ +package replicationpolicies + +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 PolicyProperties struct { + FriendlyName *string `json:"friendlyName,omitempty"` + ProviderSpecificDetails PolicyProviderSpecificDetails `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &PolicyProperties{} + +func (s *PolicyProperties) UnmarshalJSON(bytes []byte) error { + type alias PolicyProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into PolicyProperties: %+v", err) + } + + s.FriendlyName = decoded.FriendlyName + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PolicyProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalPolicyProviderSpecificDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'PolicyProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproviderspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproviderspecificdetails.go new file mode 100644 index 00000000000..ea173063686 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproviderspecificdetails.go @@ -0,0 +1,128 @@ +package replicationpolicies + +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 PolicyProviderSpecificDetails interface { +} + +func unmarshalPolicyProviderSpecificDetailsImplementation(input []byte) (PolicyProviderSpecificDetails, 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 PolicyProviderSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2APolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2APolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzurePolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzurePolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaBasePolicyDetails") { + var out HyperVReplicaBasePolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaBasePolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplica2012R2") { + var out HyperVReplicaBluePolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaBluePolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplica2012") { + var out HyperVReplicaPolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaPolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2PolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2PolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageBasePolicyDetails") { + var out InMageBasePolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageBasePolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMagePolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMagePolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcmFailback") { + var out InMageRcmFailbackPolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFailbackPolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmPolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmPolicyDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtPolicyDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtPolicyDetails: %+v", err) + } + return out, nil + } + + type RawPolicyProviderSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawPolicyProviderSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproviderspecificinput.go new file mode 100644 index 00000000000..f87fe704130 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_policyproviderspecificinput.go @@ -0,0 +1,112 @@ +package replicationpolicies + +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 PolicyProviderSpecificInput interface { +} + +func unmarshalPolicyProviderSpecificInputImplementation(input []byte) (PolicyProviderSpecificInput, 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 PolicyProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2ACrossClusterMigration") { + var out A2ACrossClusterMigrationPolicyCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ACrossClusterMigrationPolicyCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2APolicyCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2APolicyCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzurePolicyInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzurePolicyInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplica2012") { + var out HyperVReplicaPolicyInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaPolicyInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2PolicyInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2PolicyInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMagePolicyInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMagePolicyInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcmFailback") { + var out InMageRcmFailbackPolicyCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFailbackPolicyCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmPolicyCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmPolicyCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtPolicyCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtPolicyCreationInput: %+v", err) + } + return out, nil + } + + type RawPolicyProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawPolicyProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_updatepolicyinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_updatepolicyinput.go new file mode 100644 index 00000000000..ca0f0a2c86e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_updatepolicyinput.go @@ -0,0 +1,8 @@ +package replicationpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdatePolicyInput struct { + Properties *UpdatePolicyInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_updatepolicyinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_updatepolicyinputproperties.go new file mode 100644 index 00000000000..59351084d98 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_updatepolicyinputproperties.go @@ -0,0 +1,32 @@ +package replicationpolicies + +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 UpdatePolicyInputProperties struct { + ReplicationProviderSettings PolicyProviderSpecificInput `json:"replicationProviderSettings"` +} + +var _ json.Unmarshaler = &UpdatePolicyInputProperties{} + +func (s *UpdatePolicyInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling UpdatePolicyInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["replicationProviderSettings"]; ok { + impl, err := unmarshalPolicyProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ReplicationProviderSettings' for 'UpdatePolicyInputProperties': %+v", err) + } + s.ReplicationProviderSettings = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_vmwarecbtpolicycreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_vmwarecbtpolicycreationinput.go new file mode 100644 index 00000000000..a2701bda163 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_vmwarecbtpolicycreationinput.go @@ -0,0 +1,43 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificInput = VMwareCbtPolicyCreationInput{} + +type VMwareCbtPolicyCreationInput struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + RecoveryPointHistoryInMinutes *int64 `json:"recoveryPointHistoryInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificInput +} + +var _ json.Marshaler = VMwareCbtPolicyCreationInput{} + +func (s VMwareCbtPolicyCreationInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtPolicyCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtPolicyCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtPolicyCreationInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtPolicyCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_vmwarecbtpolicydetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_vmwarecbtpolicydetails.go new file mode 100644 index 00000000000..0541a8187bb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/model_vmwarecbtpolicydetails.go @@ -0,0 +1,43 @@ +package replicationpolicies + +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 _ PolicyProviderSpecificDetails = VMwareCbtPolicyDetails{} + +type VMwareCbtPolicyDetails struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + RecoveryPointHistoryInMinutes *int64 `json:"recoveryPointHistoryInMinutes,omitempty"` + + // Fields inherited from PolicyProviderSpecificDetails +} + +var _ json.Marshaler = VMwareCbtPolicyDetails{} + +func (s VMwareCbtPolicyDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtPolicyDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtPolicyDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtPolicyDetails: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtPolicyDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/predicates.go new file mode 100644 index 00000000000..bde5ece565b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/predicates.go @@ -0,0 +1,32 @@ +package replicationpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PolicyOperationPredicate) Matches(input Policy) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationpolicies/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/version.go new file mode 100644 index 00000000000..24392b7647a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationpolicies/version.go @@ -0,0 +1,12 @@ +package replicationpolicies + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/README.md new file mode 100644 index 00000000000..e7d0acb27c1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems` Documentation + +The `replicationprotectableitems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems" +``` + + +### Client Initialization + +```go +client := replicationprotectableitems.NewReplicationProtectableItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationProtectableItemsClient.Get` + +```go +ctx := context.TODO() +id := replicationprotectableitems.NewReplicationProtectableItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectableItemValue") + +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: `ReplicationProtectableItemsClient.ListByReplicationProtectionContainers` + +```go +ctx := context.TODO() +id := replicationprotectableitems.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +// alternatively `client.ListByReplicationProtectionContainers(ctx, id, replicationprotectableitems.DefaultListByReplicationProtectionContainersOperationOptions())` can be used to do batched pagination +items, err := client.ListByReplicationProtectionContainersComplete(ctx, id, replicationprotectableitems.DefaultListByReplicationProtectionContainersOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/client.go new file mode 100644 index 00000000000..cd1356d41c0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/client.go @@ -0,0 +1,18 @@ +package replicationprotectableitems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectableItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationProtectableItemsClientWithBaseURI(endpoint string) ReplicationProtectableItemsClient { + return ReplicationProtectableItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/constants.go new file mode 100644 index 00000000000..7ae2eaa30c8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/constants.go @@ -0,0 +1,65 @@ +package replicationprotectableitems + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} + +type PresenceStatus string + +const ( + PresenceStatusNotPresent PresenceStatus = "NotPresent" + PresenceStatusPresent PresenceStatus = "Present" + PresenceStatusUnknown PresenceStatus = "Unknown" +) + +func PossibleValuesForPresenceStatus() []string { + return []string{ + string(PresenceStatusNotPresent), + string(PresenceStatusPresent), + string(PresenceStatusUnknown), + } +} + +func parsePresenceStatus(input string) (*PresenceStatus, error) { + vals := map[string]PresenceStatus{ + "notpresent": PresenceStatusNotPresent, + "present": PresenceStatusPresent, + "unknown": PresenceStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PresenceStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectableitem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectableitem.go new file mode 100644 index 00000000000..1b650ec79a4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectableitem.go @@ -0,0 +1,166 @@ +package replicationprotectableitems + +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 = ReplicationProtectableItemId{} + +// ReplicationProtectableItemId is a struct representing the Resource ID for a Replication Protectable Item +type ReplicationProtectableItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationProtectableItemName string +} + +// NewReplicationProtectableItemID returns a new ReplicationProtectableItemId struct +func NewReplicationProtectableItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectableItemName string) ReplicationProtectableItemId { + return ReplicationProtectableItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationProtectableItemName: replicationProtectableItemName, + } +} + +// ParseReplicationProtectableItemID parses 'input' into a ReplicationProtectableItemId +func ParseReplicationProtectableItemID(input string) (*ReplicationProtectableItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectableItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectableItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectableItemName, ok = parsed.Parsed["replicationProtectableItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectableItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectableItemIDInsensitively parses 'input' case-insensitively into a ReplicationProtectableItemId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectableItemIDInsensitively(input string) (*ReplicationProtectableItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectableItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectableItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectableItemName, ok = parsed.Parsed["replicationProtectableItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectableItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectableItemID checks that 'input' can be parsed as a Replication Protectable Item ID +func ValidateReplicationProtectableItemID(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 := ParseReplicationProtectableItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protectable Item ID +func (id ReplicationProtectableItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectableItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectableItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protectable Item ID +func (id ReplicationProtectableItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationProtectableItems", "replicationProtectableItems", "replicationProtectableItems"), + resourceids.UserSpecifiedSegment("replicationProtectableItemName", "replicationProtectableItemValue"), + } +} + +// String returns a human-readable description of this Replication Protectable Item ID +func (id ReplicationProtectableItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Protectable Item Name: %q", id.ReplicationProtectableItemName), + } + return fmt.Sprintf("Replication Protectable Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectableitem_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectableitem_test.go new file mode 100644 index 00000000000..7f77a2c68cf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectableitem_test.go @@ -0,0 +1,417 @@ +package replicationprotectableitems + +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 = ReplicationProtectableItemId{} + +func TestNewReplicationProtectableItemID(t *testing.T) { + id := NewReplicationProtectableItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectableItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationProtectableItemName != "replicationProtectableItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectableItemName'", id.ReplicationProtectableItemName, "replicationProtectableItemValue") + } +} + +func TestFormatReplicationProtectableItemID(t *testing.T) { + actual := NewReplicationProtectableItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectableItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectableItems/replicationProtectableItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectableItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectableItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectableItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectableItems/replicationProtectableItemValue", + Expected: &ReplicationProtectableItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectableItemName: "replicationProtectableItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectableItems/replicationProtectableItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectableItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectableItemName != v.Expected.ReplicationProtectableItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectableItemName", v.Expected.ReplicationProtectableItemName, actual.ReplicationProtectableItemName) + } + + } +} + +func TestParseReplicationProtectableItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectableItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectableItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTaBlEiTeMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectableItems/replicationProtectableItemValue", + Expected: &ReplicationProtectableItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectableItemName: "replicationProtectableItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectableItems/replicationProtectableItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTaBlEiTeMs/rEpLiCaTiOnPrOtEcTaBlEiTeMvAlUe", + Expected: &ReplicationProtectableItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationProtectableItemName: "rEpLiCaTiOnPrOtEcTaBlEiTeMvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTaBlEiTeMs/rEpLiCaTiOnPrOtEcTaBlEiTeMvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectableItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectableItemName != v.Expected.ReplicationProtectableItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectableItemName", v.Expected.ReplicationProtectableItemName, actual.ReplicationProtectableItemName) + } + + } +} + +func TestSegmentsForReplicationProtectableItemId(t *testing.T) { + segments := ReplicationProtectableItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectableItemId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectioncontainer.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectioncontainer.go new file mode 100644 index 00000000000..70a56469f92 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectioncontainer.go @@ -0,0 +1,153 @@ +package replicationprotectableitems + +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 = ReplicationProtectionContainerId{} + +// ReplicationProtectionContainerId is a struct representing the Resource ID for a Replication Protection Container +type ReplicationProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string +} + +// NewReplicationProtectionContainerID returns a new ReplicationProtectionContainerId struct +func NewReplicationProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string) ReplicationProtectionContainerId { + return ReplicationProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + } +} + +// ParseReplicationProtectionContainerID parses 'input' into a ReplicationProtectionContainerId +func ParseReplicationProtectionContainerID(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectionContainerIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionContainerIDInsensitively(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectionContainerID checks that 'input' can be parsed as a Replication Protection Container ID +func ValidateReplicationProtectionContainerID(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 := ParseReplicationProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Container ID +func (id ReplicationProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container ID +func (id ReplicationProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + } +} + +// String returns a human-readable description of this Replication Protection Container ID +func (id ReplicationProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + } + return fmt.Sprintf("Replication Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectioncontainer_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectioncontainer_test.go new file mode 100644 index 00000000000..4913dd9aab5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/id_replicationprotectioncontainer_test.go @@ -0,0 +1,372 @@ +package replicationprotectableitems + +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 = ReplicationProtectionContainerId{} + +func TestNewReplicationProtectionContainerID(t *testing.T) { + id := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } +} + +func TestFormatReplicationProtectionContainerID(t *testing.T) { + actual := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectionContainerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestParseReplicationProtectionContainerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestSegmentsForReplicationProtectionContainerId(t *testing.T) { + segments := ReplicationProtectionContainerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectionContainerId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/method_get_autorest.go new file mode 100644 index 00000000000..5f174d7a1cc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationprotectableitems + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ProtectableItem +} + +// Get ... +func (c ReplicationProtectableItemsClient) Get(ctx context.Context, id ReplicationProtectableItemId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationProtectableItemsClient) preparerForGet(ctx context.Context, id ReplicationProtectableItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationProtectableItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go new file mode 100644 index 00000000000..5c77821d594 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/method_listbyreplicationprotectioncontainers_autorest.go @@ -0,0 +1,220 @@ +package replicationprotectableitems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationProtectionContainersOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectableItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectionContainersOperationResponse, error) +} + +type ListByReplicationProtectionContainersCompleteResult struct { + Items []ProtectableItem +} + +func (r ListByReplicationProtectionContainersOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationProtectionContainersOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListByReplicationProtectionContainersOperationOptions struct { + Filter *string + Take *string +} + +func DefaultListByReplicationProtectionContainersOperationOptions() ListByReplicationProtectionContainersOperationOptions { + return ListByReplicationProtectionContainersOperationOptions{} +} + +func (o ListByReplicationProtectionContainersOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListByReplicationProtectionContainersOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + if o.Take != nil { + out["$take"] = *o.Take + } + + return out +} + +// ListByReplicationProtectionContainers ... +func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainers(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationProtectionContainers(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationProtectionContainers prepares the ListByReplicationProtectionContainers request. +func (c ReplicationProtectableItemsClient) preparerForListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectableItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationProtectionContainersWithNextLink prepares the ListByReplicationProtectionContainers request with the given nextLink token. +func (c ReplicationProtectableItemsClient) preparerForListByReplicationProtectionContainersWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationProtectionContainers handles the response to the ListByReplicationProtectionContainers request. The method always +// closes the http.Response Body. +func (c ReplicationProtectableItemsClient) responderForListByReplicationProtectionContainers(resp *http.Response) (result ListByReplicationProtectionContainersOperationResponse, err error) { + type page struct { + Values []ProtectableItem `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainersWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationProtectionContainers(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectableitems.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationProtectionContainersComplete retrieves all of the results into a single object +func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions) (ListByReplicationProtectionContainersCompleteResult, error) { + return c.ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx, id, options, ProtectableItemOperationPredicate{}) +} + +// ListByReplicationProtectionContainersCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectableItemsClient) ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectionContainerId, options ListByReplicationProtectionContainersOperationOptions, predicate ProtectableItemOperationPredicate) (resp ListByReplicationProtectionContainersCompleteResult, err error) { + items := make([]ProtectableItem, 0) + + page, err := c.ListByReplicationProtectionContainers(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationProtectionContainersCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_configurationsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_configurationsettings.go new file mode 100644 index 00000000000..4d071558c6c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_configurationsettings.go @@ -0,0 +1,64 @@ +package replicationprotectableitems + +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 ConfigurationSettings interface { +} + +func unmarshalConfigurationSettingsImplementation(input []byte) (ConfigurationSettings, 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 ConfigurationSettings into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "HyperVVirtualMachine") { + var out HyperVVirtualMachineDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVVirtualMachineDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ReplicationGroupDetails") { + var out ReplicationGroupDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ReplicationGroupDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareVirtualMachine") { + var out VMwareVirtualMachineDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareVirtualMachineDetails: %+v", err) + } + return out, nil + } + + type RawConfigurationSettingsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawConfigurationSettingsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_diskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_diskdetails.go new file mode 100644 index 00000000000..f418a8a199a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_diskdetails.go @@ -0,0 +1,11 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskDetails struct { + MaxSizeMB *int64 `json:"maxSizeMB,omitempty"` + VhdId *string `json:"vhdId,omitempty"` + VhdName *string `json:"vhdName,omitempty"` + VhdType *string `json:"vhdType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_diskvolumedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_diskvolumedetails.go new file mode 100644 index 00000000000..a1807b2e5d9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_diskvolumedetails.go @@ -0,0 +1,9 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskVolumeDetails struct { + Label *string `json:"label,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_healtherror.go new file mode 100644 index 00000000000..dd836fd7405 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationprotectableitems + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go new file mode 100644 index 00000000000..73a1c26e708 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_hypervvirtualmachinedetails.go @@ -0,0 +1,48 @@ +package replicationprotectableitems + +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 _ ConfigurationSettings = HyperVVirtualMachineDetails{} + +type HyperVVirtualMachineDetails struct { + DiskDetails *[]DiskDetails `json:"diskDetails,omitempty"` + Generation *string `json:"generation,omitempty"` + HasFibreChannelAdapter *PresenceStatus `json:"hasFibreChannelAdapter,omitempty"` + HasPhysicalDisk *PresenceStatus `json:"hasPhysicalDisk,omitempty"` + HasSharedVhd *PresenceStatus `json:"hasSharedVhd,omitempty"` + HyperVHostId *string `json:"hyperVHostId,omitempty"` + OsDetails *OSDetails `json:"osDetails,omitempty"` + SourceItemId *string `json:"sourceItemId,omitempty"` + + // Fields inherited from ConfigurationSettings +} + +var _ json.Marshaler = HyperVVirtualMachineDetails{} + +func (s HyperVVirtualMachineDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVVirtualMachineDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVVirtualMachineDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVVirtualMachineDetails: %+v", err) + } + decoded["instanceType"] = "HyperVVirtualMachine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVVirtualMachineDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_inmagediskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_inmagediskdetails.go new file mode 100644 index 00000000000..a4233f28136 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_inmagediskdetails.go @@ -0,0 +1,13 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageDiskDetails struct { + DiskConfiguration *string `json:"diskConfiguration,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskSizeInMB *string `json:"diskSizeInMB,omitempty"` + DiskType *string `json:"diskType,omitempty"` + VolumeList *[]DiskVolumeDetails `json:"volumeList,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_innerhealtherror.go new file mode 100644 index 00000000000..ee306e7b230 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationprotectableitems + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_osdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_osdetails.go new file mode 100644 index 00000000000..7b38e793990 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_osdetails.go @@ -0,0 +1,13 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSDetails struct { + OSMajorVersion *string `json:"oSMajorVersion,omitempty"` + OSMinorVersion *string `json:"oSMinorVersion,omitempty"` + OSVersion *string `json:"oSVersion,omitempty"` + OsEdition *string `json:"osEdition,omitempty"` + OsType *string `json:"osType,omitempty"` + ProductType *string `json:"productType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_protectableitem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_protectableitem.go new file mode 100644 index 00000000000..f2996c6b514 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_protectableitem.go @@ -0,0 +1,12 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectableItem struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProtectableItemProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_protectableitemproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_protectableitemproperties.go new file mode 100644 index 00000000000..5559fc9f13c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_protectableitemproperties.go @@ -0,0 +1,50 @@ +package replicationprotectableitems + +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 ProtectableItemProperties struct { + CustomDetails ConfigurationSettings `json:"customDetails"` + FriendlyName *string `json:"friendlyName,omitempty"` + ProtectionReadinessErrors *[]string `json:"protectionReadinessErrors,omitempty"` + ProtectionStatus *string `json:"protectionStatus,omitempty"` + RecoveryServicesProviderId *string `json:"recoveryServicesProviderId,omitempty"` + ReplicationProtectedItemId *string `json:"replicationProtectedItemId,omitempty"` + SupportedReplicationProviders *[]string `json:"supportedReplicationProviders,omitempty"` +} + +var _ json.Unmarshaler = &ProtectableItemProperties{} + +func (s *ProtectableItemProperties) UnmarshalJSON(bytes []byte) error { + type alias ProtectableItemProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectableItemProperties: %+v", err) + } + + s.FriendlyName = decoded.FriendlyName + s.ProtectionReadinessErrors = decoded.ProtectionReadinessErrors + s.ProtectionStatus = decoded.ProtectionStatus + s.RecoveryServicesProviderId = decoded.RecoveryServicesProviderId + s.ReplicationProtectedItemId = decoded.ReplicationProtectedItemId + s.SupportedReplicationProviders = decoded.SupportedReplicationProviders + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectableItemProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customDetails"]; ok { + impl, err := unmarshalConfigurationSettingsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomDetails' for 'ProtectableItemProperties': %+v", err) + } + s.CustomDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_replicationgroupdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_replicationgroupdetails.go new file mode 100644 index 00000000000..2afdac69d0e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_replicationgroupdetails.go @@ -0,0 +1,40 @@ +package replicationprotectableitems + +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 _ ConfigurationSettings = ReplicationGroupDetails{} + +type ReplicationGroupDetails struct { + + // Fields inherited from ConfigurationSettings +} + +var _ json.Marshaler = ReplicationGroupDetails{} + +func (s ReplicationGroupDetails) MarshalJSON() ([]byte, error) { + type wrapper ReplicationGroupDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ReplicationGroupDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ReplicationGroupDetails: %+v", err) + } + decoded["instanceType"] = "ReplicationGroupDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ReplicationGroupDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go new file mode 100644 index 00000000000..1ae50cf4cc7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_vmmvirtualmachinedetails.go @@ -0,0 +1,48 @@ +package replicationprotectableitems + +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 _ ConfigurationSettings = VMmVirtualMachineDetails{} + +type VMmVirtualMachineDetails struct { + + // Fields inherited from HyperVVirtualMachineDetails + DiskDetails *[]DiskDetails `json:"diskDetails,omitempty"` + Generation *string `json:"generation,omitempty"` + HasFibreChannelAdapter *PresenceStatus `json:"hasFibreChannelAdapter,omitempty"` + HasPhysicalDisk *PresenceStatus `json:"hasPhysicalDisk,omitempty"` + HasSharedVhd *PresenceStatus `json:"hasSharedVhd,omitempty"` + HyperVHostId *string `json:"hyperVHostId,omitempty"` + OsDetails *OSDetails `json:"osDetails,omitempty"` + SourceItemId *string `json:"sourceItemId,omitempty"` +} + +var _ json.Marshaler = VMmVirtualMachineDetails{} + +func (s VMmVirtualMachineDetails) MarshalJSON() ([]byte, error) { + type wrapper VMmVirtualMachineDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMmVirtualMachineDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMmVirtualMachineDetails: %+v", err) + } + decoded["instanceType"] = "VmmVirtualMachine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMmVirtualMachineDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go new file mode 100644 index 00000000000..8eb8ecdf063 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/model_vmwarevirtualmachinedetails.go @@ -0,0 +1,50 @@ +package replicationprotectableitems + +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 _ ConfigurationSettings = VMwareVirtualMachineDetails{} + +type VMwareVirtualMachineDetails struct { + AgentGeneratedId *string `json:"agentGeneratedId,omitempty"` + AgentInstalled *string `json:"agentInstalled,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + DiscoveryType *string `json:"discoveryType,omitempty"` + DiskDetails *[]InMageDiskDetails `json:"diskDetails,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + OsType *string `json:"osType,omitempty"` + PoweredOn *string `json:"poweredOn,omitempty"` + VCenterInfrastructureId *string `json:"vCenterInfrastructureId,omitempty"` + ValidationErrors *[]HealthError `json:"validationErrors,omitempty"` + + // Fields inherited from ConfigurationSettings +} + +var _ json.Marshaler = VMwareVirtualMachineDetails{} + +func (s VMwareVirtualMachineDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareVirtualMachineDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareVirtualMachineDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareVirtualMachineDetails: %+v", err) + } + decoded["instanceType"] = "VMwareVirtualMachine" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareVirtualMachineDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/predicates.go new file mode 100644 index 00000000000..06bc4485e63 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/predicates.go @@ -0,0 +1,32 @@ +package replicationprotectableitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectableItemOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectableItemOperationPredicate) Matches(input ProtectableItem) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/version.go new file mode 100644 index 00000000000..3b67bf8762a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectableitems/version.go @@ -0,0 +1,12 @@ +package replicationprotectableitems + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationprotectableitems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/README.md new file mode 100644 index 00000000000..51f55ae1a20 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/README.md @@ -0,0 +1,373 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems` Documentation + +The `replicationprotecteditems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems" +``` + + +### Client Initialization + +```go +client := replicationprotecteditems.NewReplicationProtectedItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationProtectedItemsClient.AddDisks` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.AddDisksInput{ + // ... +} + + +if err := client.AddDisksThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.ApplyRecoveryPoint` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.ApplyRecoveryPointInput{ + // ... +} + + +if err := client.ApplyRecoveryPointThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.Create` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.EnableProtectionInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.Delete` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.DisableProtectionInput{ + // ... +} + + +if err := client.DeleteThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.FailoverCancel` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +if err := client.FailoverCancelThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.FailoverCommit` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +if err := client.FailoverCommitThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.Get` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +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: `ReplicationProtectedItemsClient.List` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, replicationprotecteditems.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, replicationprotecteditems.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.ListByReplicationProtectionContainers` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +// alternatively `client.ListByReplicationProtectionContainers(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationProtectionContainersComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.PlannedFailover` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.PlannedFailoverInput{ + // ... +} + + +if err := client.PlannedFailoverThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.Purge` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +if err := client.PurgeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.RemoveDisks` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.RemoveDisksInput{ + // ... +} + + +if err := client.RemoveDisksThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.RepairReplication` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +if err := client.RepairReplicationThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.Reprotect` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.ReverseReplicationInput{ + // ... +} + + +if err := client.ReprotectThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.ResolveHealthErrors` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.ResolveHealthInput{ + // ... +} + + +if err := client.ResolveHealthErrorsThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.SwitchProvider` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.SwitchProviderInput{ + // ... +} + + +if err := client.SwitchProviderThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.TestFailover` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.TestFailoverInput{ + // ... +} + + +if err := client.TestFailoverThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.TestFailoverCleanup` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.TestFailoverCleanupInput{ + // ... +} + + +if err := client.TestFailoverCleanupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.UnplannedFailover` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.UnplannedFailoverInput{ + // ... +} + + +if err := client.UnplannedFailoverThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.Update` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.UpdateReplicationProtectedItemInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.UpdateAppliance` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.UpdateApplianceForReplicationProtectedItemInput{ + // ... +} + + +if err := client.UpdateApplianceThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectedItemsClient.UpdateMobilityService` + +```go +ctx := context.TODO() +id := replicationprotecteditems.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +payload := replicationprotecteditems.UpdateMobilityServiceRequest{ + // ... +} + + +if err := client.UpdateMobilityServiceThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/client.go new file mode 100644 index 00000000000..4e2a164fa12 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/client.go @@ -0,0 +1,18 @@ +package replicationprotecteditems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectedItemsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationProtectedItemsClientWithBaseURI(endpoint string) ReplicationProtectedItemsClient { + return ReplicationProtectedItemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/constants.go new file mode 100644 index 00000000000..bd9703af0b6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/constants.go @@ -0,0 +1,566 @@ +package replicationprotecteditems + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentUpgradeBlockedReason string + +const ( + AgentUpgradeBlockedReasonAgentNoHeartbeat AgentUpgradeBlockedReason = "AgentNoHeartbeat" + AgentUpgradeBlockedReasonAlreadyOnLatestVersion AgentUpgradeBlockedReason = "AlreadyOnLatestVersion" + AgentUpgradeBlockedReasonDistroIsNotReported AgentUpgradeBlockedReason = "DistroIsNotReported" + AgentUpgradeBlockedReasonDistroNotSupportedForUpgrade AgentUpgradeBlockedReason = "DistroNotSupportedForUpgrade" + AgentUpgradeBlockedReasonIncompatibleApplianceVersion AgentUpgradeBlockedReason = "IncompatibleApplianceVersion" + AgentUpgradeBlockedReasonInvalidAgentVersion AgentUpgradeBlockedReason = "InvalidAgentVersion" + AgentUpgradeBlockedReasonInvalidDriverVersion AgentUpgradeBlockedReason = "InvalidDriverVersion" + AgentUpgradeBlockedReasonMissingUpgradePath AgentUpgradeBlockedReason = "MissingUpgradePath" + AgentUpgradeBlockedReasonNotProtected AgentUpgradeBlockedReason = "NotProtected" + AgentUpgradeBlockedReasonProcessServerNoHeartbeat AgentUpgradeBlockedReason = "ProcessServerNoHeartbeat" + AgentUpgradeBlockedReasonRcmProxyNoHeartbeat AgentUpgradeBlockedReason = "RcmProxyNoHeartbeat" + AgentUpgradeBlockedReasonRebootRequired AgentUpgradeBlockedReason = "RebootRequired" + AgentUpgradeBlockedReasonUnknown AgentUpgradeBlockedReason = "Unknown" + AgentUpgradeBlockedReasonUnsupportedProtectionScenario AgentUpgradeBlockedReason = "UnsupportedProtectionScenario" +) + +func PossibleValuesForAgentUpgradeBlockedReason() []string { + return []string{ + string(AgentUpgradeBlockedReasonAgentNoHeartbeat), + string(AgentUpgradeBlockedReasonAlreadyOnLatestVersion), + string(AgentUpgradeBlockedReasonDistroIsNotReported), + string(AgentUpgradeBlockedReasonDistroNotSupportedForUpgrade), + string(AgentUpgradeBlockedReasonIncompatibleApplianceVersion), + string(AgentUpgradeBlockedReasonInvalidAgentVersion), + string(AgentUpgradeBlockedReasonInvalidDriverVersion), + string(AgentUpgradeBlockedReasonMissingUpgradePath), + string(AgentUpgradeBlockedReasonNotProtected), + string(AgentUpgradeBlockedReasonProcessServerNoHeartbeat), + string(AgentUpgradeBlockedReasonRcmProxyNoHeartbeat), + string(AgentUpgradeBlockedReasonRebootRequired), + string(AgentUpgradeBlockedReasonUnknown), + string(AgentUpgradeBlockedReasonUnsupportedProtectionScenario), + } +} + +func parseAgentUpgradeBlockedReason(input string) (*AgentUpgradeBlockedReason, error) { + vals := map[string]AgentUpgradeBlockedReason{ + "agentnoheartbeat": AgentUpgradeBlockedReasonAgentNoHeartbeat, + "alreadyonlatestversion": AgentUpgradeBlockedReasonAlreadyOnLatestVersion, + "distroisnotreported": AgentUpgradeBlockedReasonDistroIsNotReported, + "distronotsupportedforupgrade": AgentUpgradeBlockedReasonDistroNotSupportedForUpgrade, + "incompatibleapplianceversion": AgentUpgradeBlockedReasonIncompatibleApplianceVersion, + "invalidagentversion": AgentUpgradeBlockedReasonInvalidAgentVersion, + "invaliddriverversion": AgentUpgradeBlockedReasonInvalidDriverVersion, + "missingupgradepath": AgentUpgradeBlockedReasonMissingUpgradePath, + "notprotected": AgentUpgradeBlockedReasonNotProtected, + "processservernoheartbeat": AgentUpgradeBlockedReasonProcessServerNoHeartbeat, + "rcmproxynoheartbeat": AgentUpgradeBlockedReasonRcmProxyNoHeartbeat, + "rebootrequired": AgentUpgradeBlockedReasonRebootRequired, + "unknown": AgentUpgradeBlockedReasonUnknown, + "unsupportedprotectionscenario": AgentUpgradeBlockedReasonUnsupportedProtectionScenario, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AgentUpgradeBlockedReason(input) + return &out, nil +} + +type AutoProtectionOfDataDisk string + +const ( + AutoProtectionOfDataDiskDisabled AutoProtectionOfDataDisk = "Disabled" + AutoProtectionOfDataDiskEnabled AutoProtectionOfDataDisk = "Enabled" +) + +func PossibleValuesForAutoProtectionOfDataDisk() []string { + return []string{ + string(AutoProtectionOfDataDiskDisabled), + string(AutoProtectionOfDataDiskEnabled), + } +} + +func parseAutoProtectionOfDataDisk(input string) (*AutoProtectionOfDataDisk, error) { + vals := map[string]AutoProtectionOfDataDisk{ + "disabled": AutoProtectionOfDataDiskDisabled, + "enabled": AutoProtectionOfDataDiskEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoProtectionOfDataDisk(input) + return &out, nil +} + +type DisableProtectionReason string + +const ( + DisableProtectionReasonMigrationComplete DisableProtectionReason = "MigrationComplete" + DisableProtectionReasonNotSpecified DisableProtectionReason = "NotSpecified" +) + +func PossibleValuesForDisableProtectionReason() []string { + return []string{ + string(DisableProtectionReasonMigrationComplete), + string(DisableProtectionReasonNotSpecified), + } +} + +func parseDisableProtectionReason(input string) (*DisableProtectionReason, error) { + vals := map[string]DisableProtectionReason{ + "migrationcomplete": DisableProtectionReasonMigrationComplete, + "notspecified": DisableProtectionReasonNotSpecified, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DisableProtectionReason(input) + return &out, nil +} + +type DiskAccountType string + +const ( + DiskAccountTypePremiumLRS DiskAccountType = "Premium_LRS" + DiskAccountTypeStandardLRS DiskAccountType = "Standard_LRS" + DiskAccountTypeStandardSSDLRS DiskAccountType = "StandardSSD_LRS" +) + +func PossibleValuesForDiskAccountType() []string { + return []string{ + string(DiskAccountTypePremiumLRS), + string(DiskAccountTypeStandardLRS), + string(DiskAccountTypeStandardSSDLRS), + } +} + +func parseDiskAccountType(input string) (*DiskAccountType, error) { + vals := map[string]DiskAccountType{ + "premium_lrs": DiskAccountTypePremiumLRS, + "standard_lrs": DiskAccountTypeStandardLRS, + "standardssd_lrs": DiskAccountTypeStandardSSDLRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiskAccountType(input) + return &out, nil +} + +type DiskReplicationProgressHealth string + +const ( + DiskReplicationProgressHealthInProgress DiskReplicationProgressHealth = "InProgress" + DiskReplicationProgressHealthNoProgress DiskReplicationProgressHealth = "NoProgress" + DiskReplicationProgressHealthNone DiskReplicationProgressHealth = "None" + DiskReplicationProgressHealthQueued DiskReplicationProgressHealth = "Queued" + DiskReplicationProgressHealthSlowProgress DiskReplicationProgressHealth = "SlowProgress" +) + +func PossibleValuesForDiskReplicationProgressHealth() []string { + return []string{ + string(DiskReplicationProgressHealthInProgress), + string(DiskReplicationProgressHealthNoProgress), + string(DiskReplicationProgressHealthNone), + string(DiskReplicationProgressHealthQueued), + string(DiskReplicationProgressHealthSlowProgress), + } +} + +func parseDiskReplicationProgressHealth(input string) (*DiskReplicationProgressHealth, error) { + vals := map[string]DiskReplicationProgressHealth{ + "inprogress": DiskReplicationProgressHealthInProgress, + "noprogress": DiskReplicationProgressHealthNoProgress, + "none": DiskReplicationProgressHealthNone, + "queued": DiskReplicationProgressHealthQueued, + "slowprogress": DiskReplicationProgressHealthSlowProgress, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiskReplicationProgressHealth(input) + return &out, nil +} + +type EthernetAddressType string + +const ( + EthernetAddressTypeDynamic EthernetAddressType = "Dynamic" + EthernetAddressTypeStatic EthernetAddressType = "Static" +) + +func PossibleValuesForEthernetAddressType() []string { + return []string{ + string(EthernetAddressTypeDynamic), + string(EthernetAddressTypeStatic), + } +} + +func parseEthernetAddressType(input string) (*EthernetAddressType, error) { + vals := map[string]EthernetAddressType{ + "dynamic": EthernetAddressTypeDynamic, + "static": EthernetAddressTypeStatic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EthernetAddressType(input) + return &out, nil +} + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} + +type InMageRcmFailbackRecoveryPointType string + +const ( + InMageRcmFailbackRecoveryPointTypeApplicationConsistent InMageRcmFailbackRecoveryPointType = "ApplicationConsistent" + InMageRcmFailbackRecoveryPointTypeCrashConsistent InMageRcmFailbackRecoveryPointType = "CrashConsistent" +) + +func PossibleValuesForInMageRcmFailbackRecoveryPointType() []string { + return []string{ + string(InMageRcmFailbackRecoveryPointTypeApplicationConsistent), + string(InMageRcmFailbackRecoveryPointTypeCrashConsistent), + } +} + +func parseInMageRcmFailbackRecoveryPointType(input string) (*InMageRcmFailbackRecoveryPointType, error) { + vals := map[string]InMageRcmFailbackRecoveryPointType{ + "applicationconsistent": InMageRcmFailbackRecoveryPointTypeApplicationConsistent, + "crashconsistent": InMageRcmFailbackRecoveryPointTypeCrashConsistent, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InMageRcmFailbackRecoveryPointType(input) + return &out, nil +} + +type LicenseType string + +const ( + LicenseTypeNoLicenseType LicenseType = "NoLicenseType" + LicenseTypeNotSpecified LicenseType = "NotSpecified" + LicenseTypeWindowsServer LicenseType = "WindowsServer" +) + +func PossibleValuesForLicenseType() []string { + return []string{ + string(LicenseTypeNoLicenseType), + string(LicenseTypeNotSpecified), + string(LicenseTypeWindowsServer), + } +} + +func parseLicenseType(input string) (*LicenseType, error) { + vals := map[string]LicenseType{ + "nolicensetype": LicenseTypeNoLicenseType, + "notspecified": LicenseTypeNotSpecified, + "windowsserver": LicenseTypeWindowsServer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseType(input) + return &out, nil +} + +type MobilityAgentUpgradeState string + +const ( + MobilityAgentUpgradeStateCommit MobilityAgentUpgradeState = "Commit" + MobilityAgentUpgradeStateCompleted MobilityAgentUpgradeState = "Completed" + MobilityAgentUpgradeStateNone MobilityAgentUpgradeState = "None" + MobilityAgentUpgradeStateStarted MobilityAgentUpgradeState = "Started" +) + +func PossibleValuesForMobilityAgentUpgradeState() []string { + return []string{ + string(MobilityAgentUpgradeStateCommit), + string(MobilityAgentUpgradeStateCompleted), + string(MobilityAgentUpgradeStateNone), + string(MobilityAgentUpgradeStateStarted), + } +} + +func parseMobilityAgentUpgradeState(input string) (*MobilityAgentUpgradeState, error) { + vals := map[string]MobilityAgentUpgradeState{ + "commit": MobilityAgentUpgradeStateCommit, + "completed": MobilityAgentUpgradeStateCompleted, + "none": MobilityAgentUpgradeStateNone, + "started": MobilityAgentUpgradeStateStarted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MobilityAgentUpgradeState(input) + return &out, nil +} + +type MultiVMGroupCreateOption string + +const ( + MultiVMGroupCreateOptionAutoCreated MultiVMGroupCreateOption = "AutoCreated" + MultiVMGroupCreateOptionUserSpecified MultiVMGroupCreateOption = "UserSpecified" +) + +func PossibleValuesForMultiVMGroupCreateOption() []string { + return []string{ + string(MultiVMGroupCreateOptionAutoCreated), + string(MultiVMGroupCreateOptionUserSpecified), + } +} + +func parseMultiVMGroupCreateOption(input string) (*MultiVMGroupCreateOption, error) { + vals := map[string]MultiVMGroupCreateOption{ + "autocreated": MultiVMGroupCreateOptionAutoCreated, + "userspecified": MultiVMGroupCreateOptionUserSpecified, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MultiVMGroupCreateOption(input) + return &out, nil +} + +type PlannedFailoverStatus string + +const ( + PlannedFailoverStatusCancelled PlannedFailoverStatus = "Cancelled" + PlannedFailoverStatusFailed PlannedFailoverStatus = "Failed" + PlannedFailoverStatusSucceeded PlannedFailoverStatus = "Succeeded" + PlannedFailoverStatusUnknown PlannedFailoverStatus = "Unknown" +) + +func PossibleValuesForPlannedFailoverStatus() []string { + return []string{ + string(PlannedFailoverStatusCancelled), + string(PlannedFailoverStatusFailed), + string(PlannedFailoverStatusSucceeded), + string(PlannedFailoverStatusUnknown), + } +} + +func parsePlannedFailoverStatus(input string) (*PlannedFailoverStatus, error) { + vals := map[string]PlannedFailoverStatus{ + "cancelled": PlannedFailoverStatusCancelled, + "failed": PlannedFailoverStatusFailed, + "succeeded": PlannedFailoverStatusSucceeded, + "unknown": PlannedFailoverStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PlannedFailoverStatus(input) + return &out, nil +} + +type RecoveryPointType string + +const ( + RecoveryPointTypeCustom RecoveryPointType = "Custom" + RecoveryPointTypeLatestTag RecoveryPointType = "LatestTag" + RecoveryPointTypeLatestTime RecoveryPointType = "LatestTime" +) + +func PossibleValuesForRecoveryPointType() []string { + return []string{ + string(RecoveryPointTypeCustom), + string(RecoveryPointTypeLatestTag), + string(RecoveryPointTypeLatestTime), + } +} + +func parseRecoveryPointType(input string) (*RecoveryPointType, error) { + vals := map[string]RecoveryPointType{ + "custom": RecoveryPointTypeCustom, + "latesttag": RecoveryPointTypeLatestTag, + "latesttime": RecoveryPointTypeLatestTime, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointType(input) + return &out, nil +} + +type ResyncState string + +const ( + ResyncStateNone ResyncState = "None" + ResyncStatePreparedForResynchronization ResyncState = "PreparedForResynchronization" + ResyncStateStartedResynchronization ResyncState = "StartedResynchronization" +) + +func PossibleValuesForResyncState() []string { + return []string{ + string(ResyncStateNone), + string(ResyncStatePreparedForResynchronization), + string(ResyncStateStartedResynchronization), + } +} + +func parseResyncState(input string) (*ResyncState, error) { + vals := map[string]ResyncState{ + "none": ResyncStateNone, + "preparedforresynchronization": ResyncStatePreparedForResynchronization, + "startedresynchronization": ResyncStateStartedResynchronization, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResyncState(input) + return &out, nil +} + +type SqlServerLicenseType string + +const ( + SqlServerLicenseTypeAHUB SqlServerLicenseType = "AHUB" + SqlServerLicenseTypeNoLicenseType SqlServerLicenseType = "NoLicenseType" + SqlServerLicenseTypeNotSpecified SqlServerLicenseType = "NotSpecified" + SqlServerLicenseTypePAYG SqlServerLicenseType = "PAYG" +) + +func PossibleValuesForSqlServerLicenseType() []string { + return []string{ + string(SqlServerLicenseTypeAHUB), + string(SqlServerLicenseTypeNoLicenseType), + string(SqlServerLicenseTypeNotSpecified), + string(SqlServerLicenseTypePAYG), + } +} + +func parseSqlServerLicenseType(input string) (*SqlServerLicenseType, error) { + vals := map[string]SqlServerLicenseType{ + "ahub": SqlServerLicenseTypeAHUB, + "nolicensetype": SqlServerLicenseTypeNoLicenseType, + "notspecified": SqlServerLicenseTypeNotSpecified, + "payg": SqlServerLicenseTypePAYG, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SqlServerLicenseType(input) + return &out, nil +} + +type VMEncryptionType string + +const ( + VMEncryptionTypeNotEncrypted VMEncryptionType = "NotEncrypted" + VMEncryptionTypeOnePassEncrypted VMEncryptionType = "OnePassEncrypted" + VMEncryptionTypeTwoPassEncrypted VMEncryptionType = "TwoPassEncrypted" +) + +func PossibleValuesForVMEncryptionType() []string { + return []string{ + string(VMEncryptionTypeNotEncrypted), + string(VMEncryptionTypeOnePassEncrypted), + string(VMEncryptionTypeTwoPassEncrypted), + } +} + +func parseVMEncryptionType(input string) (*VMEncryptionType, error) { + vals := map[string]VMEncryptionType{ + "notencrypted": VMEncryptionTypeNotEncrypted, + "onepassencrypted": VMEncryptionTypeOnePassEncrypted, + "twopassencrypted": VMEncryptionTypeTwoPassEncrypted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VMEncryptionType(input) + return &out, nil +} + +type VMReplicationProgressHealth string + +const ( + VMReplicationProgressHealthInProgress VMReplicationProgressHealth = "InProgress" + VMReplicationProgressHealthNoProgress VMReplicationProgressHealth = "NoProgress" + VMReplicationProgressHealthNone VMReplicationProgressHealth = "None" + VMReplicationProgressHealthSlowProgress VMReplicationProgressHealth = "SlowProgress" +) + +func PossibleValuesForVMReplicationProgressHealth() []string { + return []string{ + string(VMReplicationProgressHealthInProgress), + string(VMReplicationProgressHealthNoProgress), + string(VMReplicationProgressHealthNone), + string(VMReplicationProgressHealthSlowProgress), + } +} + +func parseVMReplicationProgressHealth(input string) (*VMReplicationProgressHealth, error) { + vals := map[string]VMReplicationProgressHealth{ + "inprogress": VMReplicationProgressHealthInProgress, + "noprogress": VMReplicationProgressHealthNoProgress, + "none": VMReplicationProgressHealthNone, + "slowprogress": VMReplicationProgressHealthSlowProgress, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VMReplicationProgressHealth(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotecteditem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotecteditem.go new file mode 100644 index 00000000000..2721262472d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotecteditem.go @@ -0,0 +1,166 @@ +package replicationprotecteditems + +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 = ReplicationProtectedItemId{} + +// ReplicationProtectedItemId is a struct representing the Resource ID for a Replication Protected Item +type ReplicationProtectedItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationProtectedItemName string +} + +// NewReplicationProtectedItemID returns a new ReplicationProtectedItemId struct +func NewReplicationProtectedItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectedItemName string) ReplicationProtectedItemId { + return ReplicationProtectedItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationProtectedItemName: replicationProtectedItemName, + } +} + +// ParseReplicationProtectedItemID parses 'input' into a ReplicationProtectedItemId +func ParseReplicationProtectedItemID(input string) (*ReplicationProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectedItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectedItemIDInsensitively parses 'input' case-insensitively into a ReplicationProtectedItemId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectedItemIDInsensitively(input string) (*ReplicationProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectedItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectedItemID checks that 'input' can be parsed as a Replication Protected Item ID +func ValidateReplicationProtectedItemID(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 := ParseReplicationProtectedItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protected Item ID +func (id ReplicationProtectedItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectedItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectedItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protected Item ID +func (id ReplicationProtectedItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationProtectedItems", "replicationProtectedItems", "replicationProtectedItems"), + resourceids.UserSpecifiedSegment("replicationProtectedItemName", "replicationProtectedItemValue"), + } +} + +// String returns a human-readable description of this Replication Protected Item ID +func (id ReplicationProtectedItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Protected Item Name: %q", id.ReplicationProtectedItemName), + } + return fmt.Sprintf("Replication Protected Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotecteditem_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotecteditem_test.go new file mode 100644 index 00000000000..7dd355929bd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotecteditem_test.go @@ -0,0 +1,417 @@ +package replicationprotecteditems + +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 = ReplicationProtectedItemId{} + +func TestNewReplicationProtectedItemID(t *testing.T) { + id := NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationProtectedItemName != "replicationProtectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectedItemName'", id.ReplicationProtectedItemName, "replicationProtectedItemValue") + } +} + +func TestFormatReplicationProtectedItemID(t *testing.T) { + actual := NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectedItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectedItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + } +} + +func TestParseReplicationProtectedItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationProtectedItemName: "rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectedItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + } +} + +func TestSegmentsForReplicationProtectedItemId(t *testing.T) { + segments := ReplicationProtectedItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectedItemId 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/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotectioncontainer.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotectioncontainer.go new file mode 100644 index 00000000000..1ca6577a818 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotectioncontainer.go @@ -0,0 +1,153 @@ +package replicationprotecteditems + +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 = ReplicationProtectionContainerId{} + +// ReplicationProtectionContainerId is a struct representing the Resource ID for a Replication Protection Container +type ReplicationProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string +} + +// NewReplicationProtectionContainerID returns a new ReplicationProtectionContainerId struct +func NewReplicationProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string) ReplicationProtectionContainerId { + return ReplicationProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + } +} + +// ParseReplicationProtectionContainerID parses 'input' into a ReplicationProtectionContainerId +func ParseReplicationProtectionContainerID(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectionContainerIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionContainerIDInsensitively(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectionContainerID checks that 'input' can be parsed as a Replication Protection Container ID +func ValidateReplicationProtectionContainerID(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 := ParseReplicationProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Container ID +func (id ReplicationProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container ID +func (id ReplicationProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + } +} + +// String returns a human-readable description of this Replication Protection Container ID +func (id ReplicationProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + } + return fmt.Sprintf("Replication Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotectioncontainer_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotectioncontainer_test.go new file mode 100644 index 00000000000..07822a3daec --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_replicationprotectioncontainer_test.go @@ -0,0 +1,372 @@ +package replicationprotecteditems + +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 = ReplicationProtectionContainerId{} + +func TestNewReplicationProtectionContainerID(t *testing.T) { + id := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } +} + +func TestFormatReplicationProtectionContainerID(t *testing.T) { + actual := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectionContainerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestParseReplicationProtectionContainerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestSegmentsForReplicationProtectionContainerId(t *testing.T) { + segments := ReplicationProtectionContainerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectionContainerId 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/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_vault.go new file mode 100644 index 00000000000..77d1d777450 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_vault.go @@ -0,0 +1,127 @@ +package replicationprotecteditems + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_vault_test.go new file mode 100644 index 00000000000..3e26debd4cd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationprotecteditems + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_adddisks_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_adddisks_autorest.go new file mode 100644 index 00000000000..c64e9d4f996 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_adddisks_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddDisksOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// AddDisks ... +func (c ReplicationProtectedItemsClient) AddDisks(ctx context.Context, id ReplicationProtectedItemId, input AddDisksInput) (result AddDisksOperationResponse, err error) { + req, err := c.preparerForAddDisks(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "AddDisks", nil, "Failure preparing request") + return + } + + result, err = c.senderForAddDisks(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "AddDisks", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// AddDisksThenPoll performs AddDisks then polls until it's completed +func (c ReplicationProtectedItemsClient) AddDisksThenPoll(ctx context.Context, id ReplicationProtectedItemId, input AddDisksInput) error { + result, err := c.AddDisks(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AddDisks: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after AddDisks: %+v", err) + } + + return nil +} + +// preparerForAddDisks prepares the AddDisks request. +func (c ReplicationProtectedItemsClient) preparerForAddDisks(ctx context.Context, id ReplicationProtectedItemId, input AddDisksInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/addDisks", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForAddDisks sends the AddDisks request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForAddDisks(ctx context.Context, req *http.Request) (future AddDisksOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_applyrecoverypoint_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_applyrecoverypoint_autorest.go new file mode 100644 index 00000000000..382d7c9fe7b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_applyrecoverypoint_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplyRecoveryPointOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ApplyRecoveryPoint ... +func (c ReplicationProtectedItemsClient) ApplyRecoveryPoint(ctx context.Context, id ReplicationProtectedItemId, input ApplyRecoveryPointInput) (result ApplyRecoveryPointOperationResponse, err error) { + req, err := c.preparerForApplyRecoveryPoint(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ApplyRecoveryPoint", nil, "Failure preparing request") + return + } + + result, err = c.senderForApplyRecoveryPoint(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ApplyRecoveryPoint", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ApplyRecoveryPointThenPoll performs ApplyRecoveryPoint then polls until it's completed +func (c ReplicationProtectedItemsClient) ApplyRecoveryPointThenPoll(ctx context.Context, id ReplicationProtectedItemId, input ApplyRecoveryPointInput) error { + result, err := c.ApplyRecoveryPoint(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ApplyRecoveryPoint: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ApplyRecoveryPoint: %+v", err) + } + + return nil +} + +// preparerForApplyRecoveryPoint prepares the ApplyRecoveryPoint request. +func (c ReplicationProtectedItemsClient) preparerForApplyRecoveryPoint(ctx context.Context, id ReplicationProtectedItemId, input ApplyRecoveryPointInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/applyRecoveryPoint", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForApplyRecoveryPoint sends the ApplyRecoveryPoint request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForApplyRecoveryPoint(ctx context.Context, req *http.Request) (future ApplyRecoveryPointOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_create_autorest.go new file mode 100644 index 00000000000..4cb329b11af --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationProtectedItemsClient) Create(ctx context.Context, id ReplicationProtectedItemId, input EnableProtectionInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationProtectedItemsClient) CreateThenPoll(ctx context.Context, id ReplicationProtectedItemId, input EnableProtectionInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationProtectedItemsClient) preparerForCreate(ctx context.Context, id ReplicationProtectedItemId, input EnableProtectionInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_delete_autorest.go new file mode 100644 index 00000000000..a81ebe03048 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_delete_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationProtectedItemsClient) Delete(ctx context.Context, id ReplicationProtectedItemId, input DisableProtectionInput) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationProtectedItemsClient) DeleteThenPoll(ctx context.Context, id ReplicationProtectedItemId, input DisableProtectionInput) error { + result, err := c.Delete(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationProtectedItemsClient) preparerForDelete(ctx context.Context, id ReplicationProtectedItemId, input DisableProtectionInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/remove", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_failovercancel_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_failovercancel_autorest.go new file mode 100644 index 00000000000..417fe2b0ae4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_failovercancel_autorest.go @@ -0,0 +1,78 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverCancelOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// FailoverCancel ... +func (c ReplicationProtectedItemsClient) FailoverCancel(ctx context.Context, id ReplicationProtectedItemId) (result FailoverCancelOperationResponse, err error) { + req, err := c.preparerForFailoverCancel(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "FailoverCancel", nil, "Failure preparing request") + return + } + + result, err = c.senderForFailoverCancel(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "FailoverCancel", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// FailoverCancelThenPoll performs FailoverCancel then polls until it's completed +func (c ReplicationProtectedItemsClient) FailoverCancelThenPoll(ctx context.Context, id ReplicationProtectedItemId) error { + result, err := c.FailoverCancel(ctx, id) + if err != nil { + return fmt.Errorf("performing FailoverCancel: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after FailoverCancel: %+v", err) + } + + return nil +} + +// preparerForFailoverCancel prepares the FailoverCancel request. +func (c ReplicationProtectedItemsClient) preparerForFailoverCancel(ctx context.Context, id ReplicationProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/failoverCancel", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForFailoverCancel sends the FailoverCancel request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForFailoverCancel(ctx context.Context, req *http.Request) (future FailoverCancelOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_failovercommit_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_failovercommit_autorest.go new file mode 100644 index 00000000000..b040a7c4922 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_failovercommit_autorest.go @@ -0,0 +1,78 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverCommitOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// FailoverCommit ... +func (c ReplicationProtectedItemsClient) FailoverCommit(ctx context.Context, id ReplicationProtectedItemId) (result FailoverCommitOperationResponse, err error) { + req, err := c.preparerForFailoverCommit(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "FailoverCommit", nil, "Failure preparing request") + return + } + + result, err = c.senderForFailoverCommit(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "FailoverCommit", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// FailoverCommitThenPoll performs FailoverCommit then polls until it's completed +func (c ReplicationProtectedItemsClient) FailoverCommitThenPoll(ctx context.Context, id ReplicationProtectedItemId) error { + result, err := c.FailoverCommit(ctx, id) + if err != nil { + return fmt.Errorf("performing FailoverCommit: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after FailoverCommit: %+v", err) + } + + return nil +} + +// preparerForFailoverCommit prepares the FailoverCommit request. +func (c ReplicationProtectedItemsClient) preparerForFailoverCommit(ctx context.Context, id ReplicationProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/failoverCommit", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForFailoverCommit sends the FailoverCommit request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForFailoverCommit(ctx context.Context, req *http.Request) (future FailoverCommitOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_get_autorest.go new file mode 100644 index 00000000000..bc6f6362d43 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationprotecteditems + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ReplicationProtectedItem +} + +// Get ... +func (c ReplicationProtectedItemsClient) Get(ctx context.Context, id ReplicationProtectedItemId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationProtectedItemsClient) preparerForGet(ctx context.Context, id ReplicationProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationProtectedItemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_list_autorest.go new file mode 100644 index 00000000000..6a52011567c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_list_autorest.go @@ -0,0 +1,220 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ReplicationProtectedItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ReplicationProtectedItem +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string + SkipToken *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + if o.SkipToken != nil { + out["skipToken"] = *o.SkipToken + } + + return out +} + +// List ... +func (c ReplicationProtectedItemsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationProtectedItemsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectedItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationProtectedItemsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationProtectedItemsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ReplicationProtectedItem `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationProtectedItemsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ReplicationProtectedItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectedItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate ReplicationProtectedItemOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ReplicationProtectedItem, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_listbyreplicationprotectioncontainers_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_listbyreplicationprotectioncontainers_autorest.go new file mode 100644 index 00000000000..9efb93d48d0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_listbyreplicationprotectioncontainers_autorest.go @@ -0,0 +1,186 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationProtectionContainersOperationResponse struct { + HttpResponse *http.Response + Model *[]ReplicationProtectedItem + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectionContainersOperationResponse, error) +} + +type ListByReplicationProtectionContainersCompleteResult struct { + Items []ReplicationProtectedItem +} + +func (r ListByReplicationProtectionContainersOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationProtectionContainersOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationProtectionContainers ... +func (c ReplicationProtectedItemsClient) ListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainers(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationProtectionContainers(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationProtectionContainers prepares the ListByReplicationProtectionContainers request. +func (c ReplicationProtectedItemsClient) preparerForListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectedItems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationProtectionContainersWithNextLink prepares the ListByReplicationProtectionContainers request with the given nextLink token. +func (c ReplicationProtectedItemsClient) preparerForListByReplicationProtectionContainersWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationProtectionContainers handles the response to the ListByReplicationProtectionContainers request. The method always +// closes the http.Response Body. +func (c ReplicationProtectedItemsClient) responderForListByReplicationProtectionContainers(resp *http.Response) (result ListByReplicationProtectionContainersOperationResponse, err error) { + type page struct { + Values []ReplicationProtectedItem `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainersWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationProtectionContainers(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationProtectionContainersComplete retrieves all of the results into a single object +func (c ReplicationProtectedItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, id ReplicationProtectionContainerId) (ListByReplicationProtectionContainersCompleteResult, error) { + return c.ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx, id, ReplicationProtectedItemOperationPredicate{}) +} + +// ListByReplicationProtectionContainersCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectedItemsClient) ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectionContainerId, predicate ReplicationProtectedItemOperationPredicate) (resp ListByReplicationProtectionContainersCompleteResult, err error) { + items := make([]ReplicationProtectedItem, 0) + + page, err := c.ListByReplicationProtectionContainers(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationProtectionContainersCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_plannedfailover_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_plannedfailover_autorest.go new file mode 100644 index 00000000000..ec7302d98a3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_plannedfailover_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PlannedFailoverOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// PlannedFailover ... +func (c ReplicationProtectedItemsClient) PlannedFailover(ctx context.Context, id ReplicationProtectedItemId, input PlannedFailoverInput) (result PlannedFailoverOperationResponse, err error) { + req, err := c.preparerForPlannedFailover(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "PlannedFailover", nil, "Failure preparing request") + return + } + + result, err = c.senderForPlannedFailover(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "PlannedFailover", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PlannedFailoverThenPoll performs PlannedFailover then polls until it's completed +func (c ReplicationProtectedItemsClient) PlannedFailoverThenPoll(ctx context.Context, id ReplicationProtectedItemId, input PlannedFailoverInput) error { + result, err := c.PlannedFailover(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PlannedFailover: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after PlannedFailover: %+v", err) + } + + return nil +} + +// preparerForPlannedFailover prepares the PlannedFailover request. +func (c ReplicationProtectedItemsClient) preparerForPlannedFailover(ctx context.Context, id ReplicationProtectedItemId, input PlannedFailoverInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/plannedFailover", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPlannedFailover sends the PlannedFailover request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForPlannedFailover(ctx context.Context, req *http.Request) (future PlannedFailoverOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_purge_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_purge_autorest.go new file mode 100644 index 00000000000..75cd5f1f7f7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_purge_autorest.go @@ -0,0 +1,78 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurgeOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Purge ... +func (c ReplicationProtectedItemsClient) Purge(ctx context.Context, id ReplicationProtectedItemId) (result PurgeOperationResponse, err error) { + req, err := c.preparerForPurge(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Purge", nil, "Failure preparing request") + return + } + + result, err = c.senderForPurge(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Purge", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PurgeThenPoll performs Purge then polls until it's completed +func (c ReplicationProtectedItemsClient) PurgeThenPoll(ctx context.Context, id ReplicationProtectedItemId) error { + result, err := c.Purge(ctx, id) + if err != nil { + return fmt.Errorf("performing Purge: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Purge: %+v", err) + } + + return nil +} + +// preparerForPurge prepares the Purge request. +func (c ReplicationProtectedItemsClient) preparerForPurge(ctx context.Context, id ReplicationProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPurge sends the Purge request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForPurge(ctx context.Context, req *http.Request) (future PurgeOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_removedisks_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_removedisks_autorest.go new file mode 100644 index 00000000000..8124ae4ea2c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_removedisks_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RemoveDisksOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// RemoveDisks ... +func (c ReplicationProtectedItemsClient) RemoveDisks(ctx context.Context, id ReplicationProtectedItemId, input RemoveDisksInput) (result RemoveDisksOperationResponse, err error) { + req, err := c.preparerForRemoveDisks(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "RemoveDisks", nil, "Failure preparing request") + return + } + + result, err = c.senderForRemoveDisks(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "RemoveDisks", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RemoveDisksThenPoll performs RemoveDisks then polls until it's completed +func (c ReplicationProtectedItemsClient) RemoveDisksThenPoll(ctx context.Context, id ReplicationProtectedItemId, input RemoveDisksInput) error { + result, err := c.RemoveDisks(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RemoveDisks: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after RemoveDisks: %+v", err) + } + + return nil +} + +// preparerForRemoveDisks prepares the RemoveDisks request. +func (c ReplicationProtectedItemsClient) preparerForRemoveDisks(ctx context.Context, id ReplicationProtectedItemId, input RemoveDisksInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/removeDisks", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRemoveDisks sends the RemoveDisks request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForRemoveDisks(ctx context.Context, req *http.Request) (future RemoveDisksOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_repairreplication_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_repairreplication_autorest.go new file mode 100644 index 00000000000..548d1b37a7c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_repairreplication_autorest.go @@ -0,0 +1,78 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepairReplicationOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// RepairReplication ... +func (c ReplicationProtectedItemsClient) RepairReplication(ctx context.Context, id ReplicationProtectedItemId) (result RepairReplicationOperationResponse, err error) { + req, err := c.preparerForRepairReplication(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "RepairReplication", nil, "Failure preparing request") + return + } + + result, err = c.senderForRepairReplication(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "RepairReplication", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RepairReplicationThenPoll performs RepairReplication then polls until it's completed +func (c ReplicationProtectedItemsClient) RepairReplicationThenPoll(ctx context.Context, id ReplicationProtectedItemId) error { + result, err := c.RepairReplication(ctx, id) + if err != nil { + return fmt.Errorf("performing RepairReplication: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after RepairReplication: %+v", err) + } + + return nil +} + +// preparerForRepairReplication prepares the RepairReplication request. +func (c ReplicationProtectedItemsClient) preparerForRepairReplication(ctx context.Context, id ReplicationProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/repairReplication", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRepairReplication sends the RepairReplication request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForRepairReplication(ctx context.Context, req *http.Request) (future RepairReplicationOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_reprotect_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_reprotect_autorest.go new file mode 100644 index 00000000000..3b8d794ffc5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_reprotect_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReprotectOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Reprotect ... +func (c ReplicationProtectedItemsClient) Reprotect(ctx context.Context, id ReplicationProtectedItemId, input ReverseReplicationInput) (result ReprotectOperationResponse, err error) { + req, err := c.preparerForReprotect(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Reprotect", nil, "Failure preparing request") + return + } + + result, err = c.senderForReprotect(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Reprotect", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ReprotectThenPoll performs Reprotect then polls until it's completed +func (c ReplicationProtectedItemsClient) ReprotectThenPoll(ctx context.Context, id ReplicationProtectedItemId, input ReverseReplicationInput) error { + result, err := c.Reprotect(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Reprotect: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Reprotect: %+v", err) + } + + return nil +} + +// preparerForReprotect prepares the Reprotect request. +func (c ReplicationProtectedItemsClient) preparerForReprotect(ctx context.Context, id ReplicationProtectedItemId, input ReverseReplicationInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/reProtect", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForReprotect sends the Reprotect request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForReprotect(ctx context.Context, req *http.Request) (future ReprotectOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_resolvehealtherrors_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_resolvehealtherrors_autorest.go new file mode 100644 index 00000000000..8e2beb422d3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_resolvehealtherrors_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolveHealthErrorsOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ResolveHealthErrors ... +func (c ReplicationProtectedItemsClient) ResolveHealthErrors(ctx context.Context, id ReplicationProtectedItemId, input ResolveHealthInput) (result ResolveHealthErrorsOperationResponse, err error) { + req, err := c.preparerForResolveHealthErrors(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ResolveHealthErrors", nil, "Failure preparing request") + return + } + + result, err = c.senderForResolveHealthErrors(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "ResolveHealthErrors", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ResolveHealthErrorsThenPoll performs ResolveHealthErrors then polls until it's completed +func (c ReplicationProtectedItemsClient) ResolveHealthErrorsThenPoll(ctx context.Context, id ReplicationProtectedItemId, input ResolveHealthInput) error { + result, err := c.ResolveHealthErrors(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ResolveHealthErrors: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ResolveHealthErrors: %+v", err) + } + + return nil +} + +// preparerForResolveHealthErrors prepares the ResolveHealthErrors request. +func (c ReplicationProtectedItemsClient) preparerForResolveHealthErrors(ctx context.Context, id ReplicationProtectedItemId, input ResolveHealthInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/resolveHealthErrors", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForResolveHealthErrors sends the ResolveHealthErrors request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForResolveHealthErrors(ctx context.Context, req *http.Request) (future ResolveHealthErrorsOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_switchprovider_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_switchprovider_autorest.go new file mode 100644 index 00000000000..f100a0e779d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_switchprovider_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SwitchProviderOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// SwitchProvider ... +func (c ReplicationProtectedItemsClient) SwitchProvider(ctx context.Context, id ReplicationProtectedItemId, input SwitchProviderInput) (result SwitchProviderOperationResponse, err error) { + req, err := c.preparerForSwitchProvider(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "SwitchProvider", nil, "Failure preparing request") + return + } + + result, err = c.senderForSwitchProvider(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "SwitchProvider", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// SwitchProviderThenPoll performs SwitchProvider then polls until it's completed +func (c ReplicationProtectedItemsClient) SwitchProviderThenPoll(ctx context.Context, id ReplicationProtectedItemId, input SwitchProviderInput) error { + result, err := c.SwitchProvider(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SwitchProvider: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after SwitchProvider: %+v", err) + } + + return nil +} + +// preparerForSwitchProvider prepares the SwitchProvider request. +func (c ReplicationProtectedItemsClient) preparerForSwitchProvider(ctx context.Context, id ReplicationProtectedItemId, input SwitchProviderInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/switchProvider", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForSwitchProvider sends the SwitchProvider request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForSwitchProvider(ctx context.Context, req *http.Request) (future SwitchProviderOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_testfailover_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_testfailover_autorest.go new file mode 100644 index 00000000000..b12f53ea115 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_testfailover_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestFailoverOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// TestFailover ... +func (c ReplicationProtectedItemsClient) TestFailover(ctx context.Context, id ReplicationProtectedItemId, input TestFailoverInput) (result TestFailoverOperationResponse, err error) { + req, err := c.preparerForTestFailover(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "TestFailover", nil, "Failure preparing request") + return + } + + result, err = c.senderForTestFailover(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "TestFailover", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TestFailoverThenPoll performs TestFailover then polls until it's completed +func (c ReplicationProtectedItemsClient) TestFailoverThenPoll(ctx context.Context, id ReplicationProtectedItemId, input TestFailoverInput) error { + result, err := c.TestFailover(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestFailover: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after TestFailover: %+v", err) + } + + return nil +} + +// preparerForTestFailover prepares the TestFailover request. +func (c ReplicationProtectedItemsClient) preparerForTestFailover(ctx context.Context, id ReplicationProtectedItemId, input TestFailoverInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/testFailover", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTestFailover sends the TestFailover request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForTestFailover(ctx context.Context, req *http.Request) (future TestFailoverOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_testfailovercleanup_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_testfailovercleanup_autorest.go new file mode 100644 index 00000000000..ce4cc28c4d7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_testfailovercleanup_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestFailoverCleanupOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// TestFailoverCleanup ... +func (c ReplicationProtectedItemsClient) TestFailoverCleanup(ctx context.Context, id ReplicationProtectedItemId, input TestFailoverCleanupInput) (result TestFailoverCleanupOperationResponse, err error) { + req, err := c.preparerForTestFailoverCleanup(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "TestFailoverCleanup", nil, "Failure preparing request") + return + } + + result, err = c.senderForTestFailoverCleanup(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "TestFailoverCleanup", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TestFailoverCleanupThenPoll performs TestFailoverCleanup then polls until it's completed +func (c ReplicationProtectedItemsClient) TestFailoverCleanupThenPoll(ctx context.Context, id ReplicationProtectedItemId, input TestFailoverCleanupInput) error { + result, err := c.TestFailoverCleanup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestFailoverCleanup: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after TestFailoverCleanup: %+v", err) + } + + return nil +} + +// preparerForTestFailoverCleanup prepares the TestFailoverCleanup request. +func (c ReplicationProtectedItemsClient) preparerForTestFailoverCleanup(ctx context.Context, id ReplicationProtectedItemId, input TestFailoverCleanupInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/testFailoverCleanup", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTestFailoverCleanup sends the TestFailoverCleanup request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForTestFailoverCleanup(ctx context.Context, req *http.Request) (future TestFailoverCleanupOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_unplannedfailover_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_unplannedfailover_autorest.go new file mode 100644 index 00000000000..b8c6e72514b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_unplannedfailover_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnplannedFailoverOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// UnplannedFailover ... +func (c ReplicationProtectedItemsClient) UnplannedFailover(ctx context.Context, id ReplicationProtectedItemId, input UnplannedFailoverInput) (result UnplannedFailoverOperationResponse, err error) { + req, err := c.preparerForUnplannedFailover(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "UnplannedFailover", nil, "Failure preparing request") + return + } + + result, err = c.senderForUnplannedFailover(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "UnplannedFailover", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UnplannedFailoverThenPoll performs UnplannedFailover then polls until it's completed +func (c ReplicationProtectedItemsClient) UnplannedFailoverThenPoll(ctx context.Context, id ReplicationProtectedItemId, input UnplannedFailoverInput) error { + result, err := c.UnplannedFailover(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UnplannedFailover: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after UnplannedFailover: %+v", err) + } + + return nil +} + +// preparerForUnplannedFailover prepares the UnplannedFailover request. +func (c ReplicationProtectedItemsClient) preparerForUnplannedFailover(ctx context.Context, id ReplicationProtectedItemId, input UnplannedFailoverInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/unplannedFailover", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUnplannedFailover sends the UnplannedFailover request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForUnplannedFailover(ctx context.Context, req *http.Request) (future UnplannedFailoverOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_update_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_update_autorest.go new file mode 100644 index 00000000000..99537c44d63 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_update_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ReplicationProtectedItemsClient) Update(ctx context.Context, id ReplicationProtectedItemId, input UpdateReplicationProtectedItemInput) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationProtectedItemsClient) UpdateThenPoll(ctx context.Context, id ReplicationProtectedItemId, input UpdateReplicationProtectedItemInput) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ReplicationProtectedItemsClient) preparerForUpdate(ctx context.Context, id ReplicationProtectedItemId, input UpdateReplicationProtectedItemInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_updateappliance_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_updateappliance_autorest.go new file mode 100644 index 00000000000..427047ac214 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_updateappliance_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateApplianceOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// UpdateAppliance ... +func (c ReplicationProtectedItemsClient) UpdateAppliance(ctx context.Context, id ReplicationProtectedItemId, input UpdateApplianceForReplicationProtectedItemInput) (result UpdateApplianceOperationResponse, err error) { + req, err := c.preparerForUpdateAppliance(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "UpdateAppliance", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdateAppliance(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "UpdateAppliance", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateApplianceThenPoll performs UpdateAppliance then polls until it's completed +func (c ReplicationProtectedItemsClient) UpdateApplianceThenPoll(ctx context.Context, id ReplicationProtectedItemId, input UpdateApplianceForReplicationProtectedItemInput) error { + result, err := c.UpdateAppliance(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UpdateAppliance: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after UpdateAppliance: %+v", err) + } + + return nil +} + +// preparerForUpdateAppliance prepares the UpdateAppliance request. +func (c ReplicationProtectedItemsClient) preparerForUpdateAppliance(ctx context.Context, id ReplicationProtectedItemId, input UpdateApplianceForReplicationProtectedItemInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/updateAppliance", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdateAppliance sends the UpdateAppliance request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForUpdateAppliance(ctx context.Context, req *http.Request) (future UpdateApplianceOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_updatemobilityservice_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_updatemobilityservice_autorest.go new file mode 100644 index 00000000000..2114a1531d9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/method_updatemobilityservice_autorest.go @@ -0,0 +1,79 @@ +package replicationprotecteditems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateMobilityServiceOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// UpdateMobilityService ... +func (c ReplicationProtectedItemsClient) UpdateMobilityService(ctx context.Context, id ReplicationProtectedItemId, input UpdateMobilityServiceRequest) (result UpdateMobilityServiceOperationResponse, err error) { + req, err := c.preparerForUpdateMobilityService(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "UpdateMobilityService", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdateMobilityService(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotecteditems.ReplicationProtectedItemsClient", "UpdateMobilityService", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateMobilityServiceThenPoll performs UpdateMobilityService then polls until it's completed +func (c ReplicationProtectedItemsClient) UpdateMobilityServiceThenPoll(ctx context.Context, id ReplicationProtectedItemId, input UpdateMobilityServiceRequest) error { + result, err := c.UpdateMobilityService(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UpdateMobilityService: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after UpdateMobilityService: %+v", err) + } + + return nil +} + +// preparerForUpdateMobilityService prepares the UpdateMobilityService request. +func (c ReplicationProtectedItemsClient) preparerForUpdateMobilityService(ctx context.Context, id ReplicationProtectedItemId, input UpdateMobilityServiceRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/updateMobilityService", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdateMobilityService sends the UpdateMobilityService request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectedItemsClient) senderForUpdateMobilityService(ctx context.Context, req *http.Request) (future UpdateMobilityServiceOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aadddisksinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aadddisksinput.go new file mode 100644 index 00000000000..814464cdc24 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aadddisksinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ AddDisksProviderSpecificInput = A2AAddDisksInput{} + +type A2AAddDisksInput struct { + VMDisks *[]A2AVMDiskInputDetails `json:"vmDisks,omitempty"` + VMManagedDisks *[]A2AVMManagedDiskInputDetails `json:"vmManagedDisks,omitempty"` + + // Fields inherited from AddDisksProviderSpecificInput +} + +var _ json.Marshaler = A2AAddDisksInput{} + +func (s A2AAddDisksInput) MarshalJSON() ([]byte, error) { + type wrapper A2AAddDisksInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AAddDisksInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AAddDisksInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AAddDisksInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aapplyrecoverypointinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aapplyrecoverypointinput.go new file mode 100644 index 00000000000..c2159e729a3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aapplyrecoverypointinput.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 _ ApplyRecoveryPointProviderSpecificInput = A2AApplyRecoveryPointInput{} + +type A2AApplyRecoveryPointInput struct { + + // Fields inherited from ApplyRecoveryPointProviderSpecificInput +} + +var _ json.Marshaler = A2AApplyRecoveryPointInput{} + +func (s A2AApplyRecoveryPointInput) MarshalJSON() ([]byte, error) { + type wrapper A2AApplyRecoveryPointInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AApplyRecoveryPointInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AApplyRecoveryPointInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AApplyRecoveryPointInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationapplyrecoverypointinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationapplyrecoverypointinput.go new file mode 100644 index 00000000000..16ecd46bef5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationapplyrecoverypointinput.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 _ ApplyRecoveryPointProviderSpecificInput = A2ACrossClusterMigrationApplyRecoveryPointInput{} + +type A2ACrossClusterMigrationApplyRecoveryPointInput struct { + + // Fields inherited from ApplyRecoveryPointProviderSpecificInput +} + +var _ json.Marshaler = A2ACrossClusterMigrationApplyRecoveryPointInput{} + +func (s A2ACrossClusterMigrationApplyRecoveryPointInput) MarshalJSON() ([]byte, error) { + type wrapper A2ACrossClusterMigrationApplyRecoveryPointInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ACrossClusterMigrationApplyRecoveryPointInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ACrossClusterMigrationApplyRecoveryPointInput: %+v", err) + } + decoded["instanceType"] = "A2ACrossClusterMigration" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ACrossClusterMigrationApplyRecoveryPointInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationenableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationenableprotectioninput.go new file mode 100644 index 00000000000..c03870f7d5d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationenableprotectioninput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ EnableProtectionProviderSpecificInput = A2ACrossClusterMigrationEnableProtectionInput{} + +type A2ACrossClusterMigrationEnableProtectionInput struct { + FabricObjectId *string `json:"fabricObjectId,omitempty"` + RecoveryContainerId *string `json:"recoveryContainerId,omitempty"` + + // Fields inherited from EnableProtectionProviderSpecificInput +} + +var _ json.Marshaler = A2ACrossClusterMigrationEnableProtectionInput{} + +func (s A2ACrossClusterMigrationEnableProtectionInput) MarshalJSON() ([]byte, error) { + type wrapper A2ACrossClusterMigrationEnableProtectionInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ACrossClusterMigrationEnableProtectionInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ACrossClusterMigrationEnableProtectionInput: %+v", err) + } + decoded["instanceType"] = "A2ACrossClusterMigration" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ACrossClusterMigrationEnableProtectionInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationreplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationreplicationdetails.go new file mode 100644 index 00000000000..7af3fda8ac7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2acrossclustermigrationreplicationdetails.go @@ -0,0 +1,46 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = A2ACrossClusterMigrationReplicationDetails{} + +type A2ACrossClusterMigrationReplicationDetails struct { + FabricObjectId *string `json:"fabricObjectId,omitempty"` + LifecycleId *string `json:"lifecycleId,omitempty"` + OsType *string `json:"osType,omitempty"` + PrimaryFabricLocation *string `json:"primaryFabricLocation,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = A2ACrossClusterMigrationReplicationDetails{} + +func (s A2ACrossClusterMigrationReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper A2ACrossClusterMigrationReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ACrossClusterMigrationReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ACrossClusterMigrationReplicationDetails: %+v", err) + } + decoded["instanceType"] = "A2ACrossClusterMigration" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ACrossClusterMigrationReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aenableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aenableprotectioninput.go new file mode 100644 index 00000000000..bd2dc9680ae --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aenableprotectioninput.go @@ -0,0 +1,60 @@ +package replicationprotecteditems + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EnableProtectionProviderSpecificInput = A2AEnableProtectionInput{} + +type A2AEnableProtectionInput struct { + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + FabricObjectId string `json:"fabricObjectId"` + MultiVMGroupId *string `json:"multiVmGroupId,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + RecoveryAvailabilitySetId *string `json:"recoveryAvailabilitySetId,omitempty"` + RecoveryAvailabilityZone *string `json:"recoveryAvailabilityZone,omitempty"` + RecoveryAzureNetworkId *string `json:"recoveryAzureNetworkId,omitempty"` + RecoveryBootDiagStorageAccountId *string `json:"recoveryBootDiagStorageAccountId,omitempty"` + RecoveryCapacityReservationGroupId *string `json:"recoveryCapacityReservationGroupId,omitempty"` + RecoveryCloudServiceId *string `json:"recoveryCloudServiceId,omitempty"` + RecoveryContainerId *string `json:"recoveryContainerId,omitempty"` + RecoveryExtendedLocation *edgezones.Model `json:"recoveryExtendedLocation,omitempty"` + RecoveryProximityPlacementGroupId *string `json:"recoveryProximityPlacementGroupId,omitempty"` + RecoveryResourceGroupId *string `json:"recoveryResourceGroupId,omitempty"` + RecoverySubnetName *string `json:"recoverySubnetName,omitempty"` + RecoveryVirtualMachineScaleSetId *string `json:"recoveryVirtualMachineScaleSetId,omitempty"` + VMDisks *[]A2AVMDiskInputDetails `json:"vmDisks,omitempty"` + VMManagedDisks *[]A2AVMManagedDiskInputDetails `json:"vmManagedDisks,omitempty"` + + // Fields inherited from EnableProtectionProviderSpecificInput +} + +var _ json.Marshaler = A2AEnableProtectionInput{} + +func (s A2AEnableProtectionInput) MarshalJSON() ([]byte, error) { + type wrapper A2AEnableProtectionInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AEnableProtectionInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AEnableProtectionInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AEnableProtectionInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aprotecteddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aprotecteddiskdetails.go new file mode 100644 index 00000000000..1f03409b8f6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aprotecteddiskdetails.go @@ -0,0 +1,30 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AProtectedDiskDetails struct { + AllowedDiskLevelOperation *[]string `json:"allowedDiskLevelOperation,omitempty"` + DataPendingAtSourceAgentInMB *float64 `json:"dataPendingAtSourceAgentInMB,omitempty"` + DataPendingInStagingStorageAccountInMB *float64 `json:"dataPendingInStagingStorageAccountInMB,omitempty"` + DekKeyVaultArmId *string `json:"dekKeyVaultArmId,omitempty"` + DiskCapacityInBytes *int64 `json:"diskCapacityInBytes,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskState *string `json:"diskState,omitempty"` + DiskType *string `json:"diskType,omitempty"` + DiskUri *string `json:"diskUri,omitempty"` + FailoverDiskName *string `json:"failoverDiskName,omitempty"` + IsDiskEncrypted *bool `json:"isDiskEncrypted,omitempty"` + IsDiskKeyEncrypted *bool `json:"isDiskKeyEncrypted,omitempty"` + KekKeyVaultArmId *string `json:"kekKeyVaultArmId,omitempty"` + KeyIdentifier *string `json:"keyIdentifier,omitempty"` + MonitoringJobType *string `json:"monitoringJobType,omitempty"` + MonitoringPercentageCompletion *int64 `json:"monitoringPercentageCompletion,omitempty"` + PrimaryDiskAzureStorageAccountId *string `json:"primaryDiskAzureStorageAccountId,omitempty"` + PrimaryStagingAzureStorageAccountId *string `json:"primaryStagingAzureStorageAccountId,omitempty"` + RecoveryAzureStorageAccountId *string `json:"recoveryAzureStorageAccountId,omitempty"` + RecoveryDiskUri *string `json:"recoveryDiskUri,omitempty"` + ResyncRequired *bool `json:"resyncRequired,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` + TfoDiskName *string `json:"tfoDiskName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aprotectedmanageddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aprotectedmanageddiskdetails.go new file mode 100644 index 00000000000..f531b7431ce --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aprotectedmanageddiskdetails.go @@ -0,0 +1,35 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AProtectedManagedDiskDetails struct { + AllowedDiskLevelOperation *[]string `json:"allowedDiskLevelOperation,omitempty"` + DataPendingAtSourceAgentInMB *float64 `json:"dataPendingAtSourceAgentInMB,omitempty"` + DataPendingInStagingStorageAccountInMB *float64 `json:"dataPendingInStagingStorageAccountInMB,omitempty"` + DekKeyVaultArmId *string `json:"dekKeyVaultArmId,omitempty"` + DiskCapacityInBytes *int64 `json:"diskCapacityInBytes,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskState *string `json:"diskState,omitempty"` + DiskType *string `json:"diskType,omitempty"` + FailoverDiskName *string `json:"failoverDiskName,omitempty"` + IsDiskEncrypted *bool `json:"isDiskEncrypted,omitempty"` + IsDiskKeyEncrypted *bool `json:"isDiskKeyEncrypted,omitempty"` + KekKeyVaultArmId *string `json:"kekKeyVaultArmId,omitempty"` + KeyIdentifier *string `json:"keyIdentifier,omitempty"` + MonitoringJobType *string `json:"monitoringJobType,omitempty"` + MonitoringPercentageCompletion *int64 `json:"monitoringPercentageCompletion,omitempty"` + PrimaryDiskEncryptionSetId *string `json:"primaryDiskEncryptionSetId,omitempty"` + PrimaryStagingAzureStorageAccountId *string `json:"primaryStagingAzureStorageAccountId,omitempty"` + RecoveryDiskEncryptionSetId *string `json:"recoveryDiskEncryptionSetId,omitempty"` + RecoveryOrignalTargetDiskId *string `json:"recoveryOrignalTargetDiskId,omitempty"` + RecoveryReplicaDiskAccountType *string `json:"recoveryReplicaDiskAccountType,omitempty"` + RecoveryReplicaDiskId *string `json:"recoveryReplicaDiskId,omitempty"` + RecoveryResourceGroupId *string `json:"recoveryResourceGroupId,omitempty"` + RecoveryTargetDiskAccountType *string `json:"recoveryTargetDiskAccountType,omitempty"` + RecoveryTargetDiskId *string `json:"recoveryTargetDiskId,omitempty"` + ResyncRequired *bool `json:"resyncRequired,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` + TfoDiskName *string `json:"tfoDiskName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aremovedisksinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aremovedisksinput.go new file mode 100644 index 00000000000..32f05ed2728 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aremovedisksinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ RemoveDisksProviderSpecificInput = A2ARemoveDisksInput{} + +type A2ARemoveDisksInput struct { + VMDisksUris *[]string `json:"vmDisksUris,omitempty"` + VMManagedDisksIds *[]string `json:"vmManagedDisksIds,omitempty"` + + // Fields inherited from RemoveDisksProviderSpecificInput +} + +var _ json.Marshaler = A2ARemoveDisksInput{} + +func (s A2ARemoveDisksInput) MarshalJSON() ([]byte, error) { + type wrapper A2ARemoveDisksInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ARemoveDisksInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ARemoveDisksInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ARemoveDisksInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2areplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2areplicationdetails.go new file mode 100644 index 00000000000..9b0fe1bfc91 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2areplicationdetails.go @@ -0,0 +1,95 @@ +package replicationprotecteditems + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ReplicationProviderSpecificSettings = A2AReplicationDetails{} + +type A2AReplicationDetails struct { + AgentCertificateExpiryDate *string `json:"agentCertificateExpiryDate,omitempty"` + AgentExpiryDate *string `json:"agentExpiryDate,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + AutoProtectionOfDataDisk *AutoProtectionOfDataDisk `json:"autoProtectionOfDataDisk,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + InitialPrimaryExtendedLocation *edgezones.Model `json:"initialPrimaryExtendedLocation,omitempty"` + InitialPrimaryFabricLocation *string `json:"initialPrimaryFabricLocation,omitempty"` + InitialPrimaryZone *string `json:"initialPrimaryZone,omitempty"` + InitialRecoveryExtendedLocation *edgezones.Model `json:"initialRecoveryExtendedLocation,omitempty"` + InitialRecoveryFabricLocation *string `json:"initialRecoveryFabricLocation,omitempty"` + InitialRecoveryZone *string `json:"initialRecoveryZone,omitempty"` + IsReplicationAgentCertificateUpdateRequired *bool `json:"isReplicationAgentCertificateUpdateRequired,omitempty"` + IsReplicationAgentUpdateRequired *bool `json:"isReplicationAgentUpdateRequired,omitempty"` + LastHeartbeat *string `json:"lastHeartbeat,omitempty"` + LastRpoCalculatedTime *string `json:"lastRpoCalculatedTime,omitempty"` + LifecycleId *string `json:"lifecycleId,omitempty"` + ManagementId *string `json:"managementId,omitempty"` + MonitoringJobType *string `json:"monitoringJobType,omitempty"` + MonitoringPercentageCompletion *int64 `json:"monitoringPercentageCompletion,omitempty"` + MultiVMGroupCreateOption *MultiVMGroupCreateOption `json:"multiVmGroupCreateOption,omitempty"` + MultiVMGroupId *string `json:"multiVmGroupId,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + OsType *string `json:"osType,omitempty"` + PrimaryAvailabilityZone *string `json:"primaryAvailabilityZone,omitempty"` + PrimaryExtendedLocation *edgezones.Model `json:"primaryExtendedLocation,omitempty"` + PrimaryFabricLocation *string `json:"primaryFabricLocation,omitempty"` + ProtectedDisks *[]A2AProtectedDiskDetails `json:"protectedDisks,omitempty"` + ProtectedManagedDisks *[]A2AProtectedManagedDiskDetails `json:"protectedManagedDisks,omitempty"` + RecoveryAvailabilitySet *string `json:"recoveryAvailabilitySet,omitempty"` + RecoveryAvailabilityZone *string `json:"recoveryAvailabilityZone,omitempty"` + RecoveryAzureGeneration *string `json:"recoveryAzureGeneration,omitempty"` + RecoveryAzureResourceGroupId *string `json:"recoveryAzureResourceGroupId,omitempty"` + RecoveryAzureVMName *string `json:"recoveryAzureVMName,omitempty"` + RecoveryAzureVMSize *string `json:"recoveryAzureVMSize,omitempty"` + RecoveryBootDiagStorageAccountId *string `json:"recoveryBootDiagStorageAccountId,omitempty"` + RecoveryCapacityReservationGroupId *string `json:"recoveryCapacityReservationGroupId,omitempty"` + RecoveryCloudService *string `json:"recoveryCloudService,omitempty"` + RecoveryExtendedLocation *edgezones.Model `json:"recoveryExtendedLocation,omitempty"` + RecoveryFabricLocation *string `json:"recoveryFabricLocation,omitempty"` + RecoveryFabricObjectId *string `json:"recoveryFabricObjectId,omitempty"` + RecoveryProximityPlacementGroupId *string `json:"recoveryProximityPlacementGroupId,omitempty"` + RecoveryVirtualMachineScaleSetId *string `json:"recoveryVirtualMachineScaleSetId,omitempty"` + RpoInSeconds *int64 `json:"rpoInSeconds,omitempty"` + SelectedRecoveryAzureNetworkId *string `json:"selectedRecoveryAzureNetworkId,omitempty"` + SelectedTfoAzureNetworkId *string `json:"selectedTfoAzureNetworkId,omitempty"` + TestFailoverRecoveryFabricObjectId *string `json:"testFailoverRecoveryFabricObjectId,omitempty"` + TfoAzureVMName *string `json:"tfoAzureVMName,omitempty"` + UnprotectedDisks *[]A2AUnprotectedDiskDetails `json:"unprotectedDisks,omitempty"` + VMEncryptionType *VMEncryptionType `json:"vmEncryptionType,omitempty"` + VMNics *[]VMNicDetails `json:"vmNics,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + VMSyncedConfigDetails *AzureToAzureVMSyncedConfigDetails `json:"vmSyncedConfigDetails,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = A2AReplicationDetails{} + +func (s A2AReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper A2AReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AReplicationDetails: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2areprotectinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2areprotectinput.go new file mode 100644 index 00000000000..2695d902be3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2areprotectinput.go @@ -0,0 +1,46 @@ +package replicationprotecteditems + +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 _ ReverseReplicationProviderSpecificInput = A2AReprotectInput{} + +type A2AReprotectInput struct { + PolicyId *string `json:"policyId,omitempty"` + RecoveryAvailabilitySetId *string `json:"recoveryAvailabilitySetId,omitempty"` + RecoveryCloudServiceId *string `json:"recoveryCloudServiceId,omitempty"` + RecoveryContainerId *string `json:"recoveryContainerId,omitempty"` + RecoveryResourceGroupId *string `json:"recoveryResourceGroupId,omitempty"` + VMDisks *[]A2AVMDiskInputDetails `json:"vmDisks,omitempty"` + + // Fields inherited from ReverseReplicationProviderSpecificInput +} + +var _ json.Marshaler = A2AReprotectInput{} + +func (s A2AReprotectInput) MarshalJSON() ([]byte, error) { + type wrapper A2AReprotectInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AReprotectInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AReprotectInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AReprotectInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2atestfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2atestfailoverinput.go new file mode 100644 index 00000000000..000fecac67e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2atestfailoverinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ TestFailoverProviderSpecificInput = A2ATestFailoverInput{} + +type A2ATestFailoverInput struct { + CloudServiceCreationOption *string `json:"cloudServiceCreationOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + + // Fields inherited from TestFailoverProviderSpecificInput +} + +var _ json.Marshaler = A2ATestFailoverInput{} + +func (s A2ATestFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper A2ATestFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ATestFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ATestFailoverInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ATestFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aunplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aunplannedfailoverinput.go new file mode 100644 index 00000000000..8c21ffe9c8e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aunplannedfailoverinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ UnplannedFailoverProviderSpecificInput = A2AUnplannedFailoverInput{} + +type A2AUnplannedFailoverInput struct { + CloudServiceCreationOption *string `json:"cloudServiceCreationOption,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + + // Fields inherited from UnplannedFailoverProviderSpecificInput +} + +var _ json.Marshaler = A2AUnplannedFailoverInput{} + +func (s A2AUnplannedFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper A2AUnplannedFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AUnplannedFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AUnplannedFailoverInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AUnplannedFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aunprotecteddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aunprotecteddiskdetails.go new file mode 100644 index 00000000000..e0a224a5724 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aunprotecteddiskdetails.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AUnprotectedDiskDetails struct { + DiskAutoProtectionStatus *AutoProtectionOfDataDisk `json:"diskAutoProtectionStatus,omitempty"` + DiskLunId *int64 `json:"diskLunId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aupdatereplicationprotectediteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aupdatereplicationprotectediteminput.go new file mode 100644 index 00000000000..f03e4a9a89a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2aupdatereplicationprotectediteminput.go @@ -0,0 +1,49 @@ +package replicationprotecteditems + +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 _ UpdateReplicationProtectedItemProviderInput = A2AUpdateReplicationProtectedItemInput{} + +type A2AUpdateReplicationProtectedItemInput struct { + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + ManagedDiskUpdateDetails *[]A2AVMManagedDiskUpdateDetails `json:"managedDiskUpdateDetails,omitempty"` + RecoveryBootDiagStorageAccountId *string `json:"recoveryBootDiagStorageAccountId,omitempty"` + RecoveryCapacityReservationGroupId *string `json:"recoveryCapacityReservationGroupId,omitempty"` + RecoveryCloudServiceId *string `json:"recoveryCloudServiceId,omitempty"` + RecoveryProximityPlacementGroupId *string `json:"recoveryProximityPlacementGroupId,omitempty"` + RecoveryResourceGroupId *string `json:"recoveryResourceGroupId,omitempty"` + RecoveryVirtualMachineScaleSetId *string `json:"recoveryVirtualMachineScaleSetId,omitempty"` + TfoAzureVMName *string `json:"tfoAzureVMName,omitempty"` + + // Fields inherited from UpdateReplicationProtectedItemProviderInput +} + +var _ json.Marshaler = A2AUpdateReplicationProtectedItemInput{} + +func (s A2AUpdateReplicationProtectedItemInput) MarshalJSON() ([]byte, error) { + type wrapper A2AUpdateReplicationProtectedItemInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AUpdateReplicationProtectedItemInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AUpdateReplicationProtectedItemInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AUpdateReplicationProtectedItemInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmdiskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmdiskinputdetails.go new file mode 100644 index 00000000000..c7aef1ff04a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmdiskinputdetails.go @@ -0,0 +1,10 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AVMDiskInputDetails struct { + DiskUri string `json:"diskUri"` + PrimaryStagingAzureStorageAccountId string `json:"primaryStagingAzureStorageAccountId"` + RecoveryAzureStorageAccountId string `json:"recoveryAzureStorageAccountId"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmmanageddiskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmmanageddiskinputdetails.go new file mode 100644 index 00000000000..d233d499b30 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmmanageddiskinputdetails.go @@ -0,0 +1,14 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AVMManagedDiskInputDetails struct { + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + DiskId string `json:"diskId"` + PrimaryStagingAzureStorageAccountId string `json:"primaryStagingAzureStorageAccountId"` + RecoveryDiskEncryptionSetId *string `json:"recoveryDiskEncryptionSetId,omitempty"` + RecoveryReplicaDiskAccountType *string `json:"recoveryReplicaDiskAccountType,omitempty"` + RecoveryResourceGroupId string `json:"recoveryResourceGroupId"` + RecoveryTargetDiskAccountType *string `json:"recoveryTargetDiskAccountType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmmanageddiskupdatedetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmmanageddiskupdatedetails.go new file mode 100644 index 00000000000..a021eaff3de --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_a2avmmanageddiskupdatedetails.go @@ -0,0 +1,13 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AVMManagedDiskUpdateDetails struct { + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + DiskId *string `json:"diskId,omitempty"` + FailoverDiskName *string `json:"failoverDiskName,omitempty"` + RecoveryReplicaDiskAccountType *string `json:"recoveryReplicaDiskAccountType,omitempty"` + RecoveryTargetDiskAccountType *string `json:"recoveryTargetDiskAccountType,omitempty"` + TfoDiskName *string `json:"tfoDiskName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksinput.go new file mode 100644 index 00000000000..fb324e0c8f7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddDisksInput struct { + Properties *AddDisksInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksinputproperties.go new file mode 100644 index 00000000000..2613527d5d4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksinputproperties.go @@ -0,0 +1,32 @@ +package replicationprotecteditems + +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 AddDisksInputProperties struct { + ProviderSpecificDetails AddDisksProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &AddDisksInputProperties{} + +func (s *AddDisksInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AddDisksInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalAddDisksProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'AddDisksInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksproviderspecificinput.go new file mode 100644 index 00000000000..1d4862cdb4c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_adddisksproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationprotecteditems + +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 AddDisksProviderSpecificInput interface { +} + +func unmarshalAddDisksProviderSpecificInputImplementation(input []byte) (AddDisksProviderSpecificInput, 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 AddDisksProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AAddDisksInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AAddDisksInput: %+v", err) + } + return out, nil + } + + type RawAddDisksProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawAddDisksProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointinput.go new file mode 100644 index 00000000000..6ae39e3cd2f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApplyRecoveryPointInput struct { + Properties ApplyRecoveryPointInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointinputproperties.go new file mode 100644 index 00000000000..debfef14272 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointinputproperties.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 ApplyRecoveryPointInputProperties struct { + ProviderSpecificDetails ApplyRecoveryPointProviderSpecificInput `json:"providerSpecificDetails"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` +} + +var _ json.Unmarshaler = &ApplyRecoveryPointInputProperties{} + +func (s *ApplyRecoveryPointInputProperties) UnmarshalJSON(bytes []byte) error { + type alias ApplyRecoveryPointInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ApplyRecoveryPointInputProperties: %+v", err) + } + + s.RecoveryPointId = decoded.RecoveryPointId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ApplyRecoveryPointInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalApplyRecoveryPointProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ApplyRecoveryPointInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointproviderspecificinput.go new file mode 100644 index 00000000000..57122ff7f9e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_applyrecoverypointproviderspecificinput.go @@ -0,0 +1,80 @@ +package replicationprotecteditems + +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 ApplyRecoveryPointProviderSpecificInput interface { +} + +func unmarshalApplyRecoveryPointProviderSpecificInputImplementation(input []byte) (ApplyRecoveryPointProviderSpecificInput, 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 ApplyRecoveryPointProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AApplyRecoveryPointInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AApplyRecoveryPointInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "A2ACrossClusterMigration") { + var out A2ACrossClusterMigrationApplyRecoveryPointInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ACrossClusterMigrationApplyRecoveryPointInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureApplyRecoveryPointInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureApplyRecoveryPointInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2ApplyRecoveryPointInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2ApplyRecoveryPointInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmApplyRecoveryPointInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmApplyRecoveryPointInput: %+v", err) + } + return out, nil + } + + type RawApplyRecoveryPointProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawApplyRecoveryPointProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_azuretoazurevmsyncedconfigdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_azuretoazurevmsyncedconfigdetails.go new file mode 100644 index 00000000000..7632016e150 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_azuretoazurevmsyncedconfigdetails.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureToAzureVMSyncedConfigDetails struct { + InputEndpoints *[]InputEndpoint `json:"inputEndpoints,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_azurevmdiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_azurevmdiskdetails.go new file mode 100644 index 00000000000..d2778fb03f3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_azurevmdiskdetails.go @@ -0,0 +1,17 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureVMDiskDetails struct { + CustomTargetDiskName *string `json:"customTargetDiskName,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId *string `json:"diskId,omitempty"` + LunId *string `json:"lunId,omitempty"` + MaxSizeMB *string `json:"maxSizeMB,omitempty"` + TargetDiskLocation *string `json:"targetDiskLocation,omitempty"` + TargetDiskName *string `json:"targetDiskName,omitempty"` + VhdId *string `json:"vhdId,omitempty"` + VhdName *string `json:"vhdName,omitempty"` + VhdType *string `json:"vhdType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_currentscenariodetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_currentscenariodetails.go new file mode 100644 index 00000000000..af5783a8a50 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_currentscenariodetails.go @@ -0,0 +1,28 @@ +package replicationprotecteditems + +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 CurrentScenarioDetails struct { + JobId *string `json:"jobId,omitempty"` + ScenarioName *string `json:"scenarioName,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *CurrentScenarioDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CurrentScenarioDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectioninput.go new file mode 100644 index 00000000000..c09eed86ccb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectioninput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DisableProtectionInput struct { + Properties DisableProtectionInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectioninputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectioninputproperties.go new file mode 100644 index 00000000000..bc2bea03f8b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectioninputproperties.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 DisableProtectionInputProperties struct { + DisableProtectionReason *DisableProtectionReason `json:"disableProtectionReason,omitempty"` + ReplicationProviderInput DisableProtectionProviderSpecificInput `json:"replicationProviderInput"` +} + +var _ json.Unmarshaler = &DisableProtectionInputProperties{} + +func (s *DisableProtectionInputProperties) UnmarshalJSON(bytes []byte) error { + type alias DisableProtectionInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DisableProtectionInputProperties: %+v", err) + } + + s.DisableProtectionReason = decoded.DisableProtectionReason + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DisableProtectionInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["replicationProviderInput"]; ok { + impl, err := unmarshalDisableProtectionProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ReplicationProviderInput' for 'DisableProtectionInputProperties': %+v", err) + } + s.ReplicationProviderInput = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectionproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectionproviderspecificinput.go new file mode 100644 index 00000000000..4317025792c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_disableprotectionproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationprotecteditems + +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 DisableProtectionProviderSpecificInput interface { +} + +func unmarshalDisableProtectionProviderSpecificInputImplementation(input []byte) (DisableProtectionProviderSpecificInput, 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 DisableProtectionProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMageDisableProtectionProviderSpecificInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageDisableProtectionProviderSpecificInput: %+v", err) + } + return out, nil + } + + type RawDisableProtectionProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawDisableProtectionProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskdetails.go new file mode 100644 index 00000000000..f64e47bcb4c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskdetails.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskDetails struct { + MaxSizeMB *int64 `json:"maxSizeMB,omitempty"` + VhdId *string `json:"vhdId,omitempty"` + VhdName *string `json:"vhdName,omitempty"` + VhdType *string `json:"vhdType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskencryptioninfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskencryptioninfo.go new file mode 100644 index 00000000000..57df685211a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskencryptioninfo.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionInfo struct { + DiskEncryptionKeyInfo *DiskEncryptionKeyInfo `json:"diskEncryptionKeyInfo,omitempty"` + KeyEncryptionKeyInfo *KeyEncryptionKeyInfo `json:"keyEncryptionKeyInfo,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskencryptionkeyinfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskencryptionkeyinfo.go new file mode 100644 index 00000000000..6ccd7c74d35 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_diskencryptionkeyinfo.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionKeyInfo struct { + KeyVaultResourceArmId *string `json:"keyVaultResourceArmId,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectioninput.go new file mode 100644 index 00000000000..1fc5ffdfc7b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectioninput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnableProtectionInput struct { + Properties *EnableProtectionInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectioninputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectioninputproperties.go new file mode 100644 index 00000000000..dfbab8a6577 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectioninputproperties.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 EnableProtectionInputProperties struct { + PolicyId *string `json:"policyId,omitempty"` + ProtectableItemId *string `json:"protectableItemId,omitempty"` + ProviderSpecificDetails EnableProtectionProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &EnableProtectionInputProperties{} + +func (s *EnableProtectionInputProperties) UnmarshalJSON(bytes []byte) error { + type alias EnableProtectionInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into EnableProtectionInputProperties: %+v", err) + } + + s.PolicyId = decoded.PolicyId + s.ProtectableItemId = decoded.ProtectableItemId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EnableProtectionInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalEnableProtectionProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'EnableProtectionInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectionproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectionproviderspecificinput.go new file mode 100644 index 00000000000..083a58aa9ae --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_enableprotectionproviderspecificinput.go @@ -0,0 +1,88 @@ +package replicationprotecteditems + +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 EnableProtectionProviderSpecificInput interface { +} + +func unmarshalEnableProtectionProviderSpecificInputImplementation(input []byte) (EnableProtectionProviderSpecificInput, 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 EnableProtectionProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2ACrossClusterMigration") { + var out A2ACrossClusterMigrationEnableProtectionInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ACrossClusterMigrationEnableProtectionInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AEnableProtectionInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AEnableProtectionInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureEnableProtectionInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureEnableProtectionInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2EnableProtectionInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2EnableProtectionInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMageEnableProtectionInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageEnableProtectionInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmEnableProtectionInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmEnableProtectionInput: %+v", err) + } + return out, nil + } + + type RawEnableProtectionProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawEnableProtectionProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_healtherror.go new file mode 100644 index 00000000000..9b403536983 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureapplyrecoverypointinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureapplyrecoverypointinput.go new file mode 100644 index 00000000000..630a66a8c5f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureapplyrecoverypointinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ ApplyRecoveryPointProviderSpecificInput = HyperVReplicaAzureApplyRecoveryPointInput{} + +type HyperVReplicaAzureApplyRecoveryPointInput struct { + PrimaryKekCertificatePfx *string `json:"primaryKekCertificatePfx,omitempty"` + SecondaryKekCertificatePfx *string `json:"secondaryKekCertificatePfx,omitempty"` + + // Fields inherited from ApplyRecoveryPointProviderSpecificInput +} + +var _ json.Marshaler = HyperVReplicaAzureApplyRecoveryPointInput{} + +func (s HyperVReplicaAzureApplyRecoveryPointInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureApplyRecoveryPointInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureApplyRecoveryPointInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureApplyRecoveryPointInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureApplyRecoveryPointInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurediskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurediskinputdetails.go new file mode 100644 index 00000000000..ed63611334a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurediskinputdetails.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HyperVReplicaAzureDiskInputDetails struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskType *DiskAccountType `json:"diskType,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureenableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureenableprotectioninput.go new file mode 100644 index 00000000000..d57f1faad3e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureenableprotectioninput.go @@ -0,0 +1,68 @@ +package replicationprotecteditems + +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 _ EnableProtectionProviderSpecificInput = HyperVReplicaAzureEnableProtectionInput{} + +type HyperVReplicaAzureEnableProtectionInput struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskType *DiskAccountType `json:"diskType,omitempty"` + DisksToInclude *[]string `json:"disksToInclude,omitempty"` + DisksToIncludeForManagedDisks *[]HyperVReplicaAzureDiskInputDetails `json:"disksToIncludeForManagedDisks,omitempty"` + EnableRdpOnTargetOption *string `json:"enableRdpOnTargetOption,omitempty"` + HvHostVMId *string `json:"hvHostVmId,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` + OsType *string `json:"osType,omitempty"` + SeedManagedDiskTags *map[string]string `json:"seedManagedDiskTags,omitempty"` + SqlServerLicenseType *SqlServerLicenseType `json:"sqlServerLicenseType,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetAzureNetworkId *string `json:"targetAzureNetworkId,omitempty"` + TargetAzureSubnetId *string `json:"targetAzureSubnetId,omitempty"` + TargetAzureV1ResourceGroupId *string `json:"targetAzureV1ResourceGroupId,omitempty"` + TargetAzureV2ResourceGroupId *string `json:"targetAzureV2ResourceGroupId,omitempty"` + TargetAzureVMName *string `json:"targetAzureVmName,omitempty"` + TargetManagedDiskTags *map[string]string `json:"targetManagedDiskTags,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetStorageAccountId *string `json:"targetStorageAccountId,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + UseManagedDisks *string `json:"useManagedDisks,omitempty"` + UseManagedDisksForReplication *string `json:"useManagedDisksForReplication,omitempty"` + VhdId *string `json:"vhdId,omitempty"` + VirtualMachineName *string `json:"vmName,omitempty"` + + // Fields inherited from EnableProtectionProviderSpecificInput +} + +var _ json.Marshaler = HyperVReplicaAzureEnableProtectionInput{} + +func (s HyperVReplicaAzureEnableProtectionInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureEnableProtectionInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureEnableProtectionInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureEnableProtectionInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureEnableProtectionInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurefailbackproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurefailbackproviderinput.go new file mode 100644 index 00000000000..d188fac0658 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurefailbackproviderinput.go @@ -0,0 +1,43 @@ +package replicationprotecteditems + +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 _ PlannedFailoverProviderSpecificFailoverInput = HyperVReplicaAzureFailbackProviderInput{} + +type HyperVReplicaAzureFailbackProviderInput struct { + DataSyncOption *string `json:"dataSyncOption,omitempty"` + ProviderIdForAlternateRecovery *string `json:"providerIdForAlternateRecovery,omitempty"` + RecoveryVMCreationOption *string `json:"recoveryVmCreationOption,omitempty"` + + // Fields inherited from PlannedFailoverProviderSpecificFailoverInput +} + +var _ json.Marshaler = HyperVReplicaAzureFailbackProviderInput{} + +func (s HyperVReplicaAzureFailbackProviderInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureFailbackProviderInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureFailbackProviderInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureFailbackProviderInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzureFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureFailbackProviderInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazuremanageddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazuremanageddiskdetails.go new file mode 100644 index 00000000000..b4d03b24573 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazuremanageddiskdetails.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HyperVReplicaAzureManagedDiskDetails struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId *string `json:"diskId,omitempty"` + ReplicaDiskType *string `json:"replicaDiskType,omitempty"` + SeedManagedDiskId *string `json:"seedManagedDiskId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureplannedfailoverproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureplannedfailoverproviderinput.go new file mode 100644 index 00000000000..27aaf794005 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureplannedfailoverproviderinput.go @@ -0,0 +1,43 @@ +package replicationprotecteditems + +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 _ PlannedFailoverProviderSpecificFailoverInput = HyperVReplicaAzurePlannedFailoverProviderInput{} + +type HyperVReplicaAzurePlannedFailoverProviderInput struct { + PrimaryKekCertificatePfx *string `json:"primaryKekCertificatePfx,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + SecondaryKekCertificatePfx *string `json:"secondaryKekCertificatePfx,omitempty"` + + // Fields inherited from PlannedFailoverProviderSpecificFailoverInput +} + +var _ json.Marshaler = HyperVReplicaAzurePlannedFailoverProviderInput{} + +func (s HyperVReplicaAzurePlannedFailoverProviderInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzurePlannedFailoverProviderInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzurePlannedFailoverProviderInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzurePlannedFailoverProviderInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzurePlannedFailoverProviderInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurereplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurereplicationdetails.go new file mode 100644 index 00000000000..9a2b95da942 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurereplicationdetails.go @@ -0,0 +1,73 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = HyperVReplicaAzureReplicationDetails{} + +type HyperVReplicaAzureReplicationDetails struct { + AzureVMDiskDetails *[]AzureVMDiskDetails `json:"azureVmDiskDetails,omitempty"` + EnableRdpOnTargetOption *string `json:"enableRdpOnTargetOption,omitempty"` + Encryption *string `json:"encryption,omitempty"` + InitialReplicationDetails *InitialReplicationDetails `json:"initialReplicationDetails,omitempty"` + LastRecoveryPointReceived *string `json:"lastRecoveryPointReceived,omitempty"` + LastReplicatedTime *string `json:"lastReplicatedTime,omitempty"` + LastRpoCalculatedTime *string `json:"lastRpoCalculatedTime,omitempty"` + LicenseType *string `json:"licenseType,omitempty"` + OSDetails *OSDetails `json:"oSDetails,omitempty"` + ProtectedManagedDisks *[]HyperVReplicaAzureManagedDiskDetails `json:"protectedManagedDisks,omitempty"` + RecoveryAvailabilitySetId *string `json:"recoveryAvailabilitySetId,omitempty"` + RecoveryAzureLogStorageAccountId *string `json:"recoveryAzureLogStorageAccountId,omitempty"` + RecoveryAzureResourceGroupId *string `json:"recoveryAzureResourceGroupId,omitempty"` + RecoveryAzureStorageAccount *string `json:"recoveryAzureStorageAccount,omitempty"` + RecoveryAzureVMName *string `json:"recoveryAzureVmName,omitempty"` + RecoveryAzureVMSize *string `json:"recoveryAzureVMSize,omitempty"` + RpoInSeconds *int64 `json:"rpoInSeconds,omitempty"` + SeedManagedDiskTags *map[string]string `json:"seedManagedDiskTags,omitempty"` + SelectedRecoveryAzureNetworkId *string `json:"selectedRecoveryAzureNetworkId,omitempty"` + SelectedSourceNicId *string `json:"selectedSourceNicId,omitempty"` + SourceVMCPUCount *int64 `json:"sourceVmCpuCount,omitempty"` + SourceVMRamSizeInMB *int64 `json:"sourceVmRamSizeInMB,omitempty"` + SqlServerLicenseType *string `json:"sqlServerLicenseType,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetManagedDiskTags *map[string]string `json:"targetManagedDiskTags,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + UseManagedDisks *string `json:"useManagedDisks,omitempty"` + VMId *string `json:"vmId,omitempty"` + VMNics *[]VMNicDetails `json:"vmNics,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = HyperVReplicaAzureReplicationDetails{} + +func (s HyperVReplicaAzureReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureReplicationDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurereprotectinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurereprotectinput.go new file mode 100644 index 00000000000..e611c351d80 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazurereprotectinput.go @@ -0,0 +1,46 @@ +package replicationprotecteditems + +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 _ ReverseReplicationProviderSpecificInput = HyperVReplicaAzureReprotectInput{} + +type HyperVReplicaAzureReprotectInput struct { + HvHostVMId *string `json:"hvHostVmId,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` + OsType *string `json:"osType,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + VHDId *string `json:"vHDId,omitempty"` + VirtualMachineName *string `json:"vmName,omitempty"` + + // Fields inherited from ReverseReplicationProviderSpecificInput +} + +var _ json.Marshaler = HyperVReplicaAzureReprotectInput{} + +func (s HyperVReplicaAzureReprotectInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureReprotectInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureReprotectInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureReprotectInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureReprotectInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazuretestfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazuretestfailoverinput.go new file mode 100644 index 00000000000..6bc556ad0bf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazuretestfailoverinput.go @@ -0,0 +1,43 @@ +package replicationprotecteditems + +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 _ TestFailoverProviderSpecificInput = HyperVReplicaAzureTestFailoverInput{} + +type HyperVReplicaAzureTestFailoverInput struct { + PrimaryKekCertificatePfx *string `json:"primaryKekCertificatePfx,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + SecondaryKekCertificatePfx *string `json:"secondaryKekCertificatePfx,omitempty"` + + // Fields inherited from TestFailoverProviderSpecificInput +} + +var _ json.Marshaler = HyperVReplicaAzureTestFailoverInput{} + +func (s HyperVReplicaAzureTestFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureTestFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureTestFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureTestFailoverInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureTestFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureunplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureunplannedfailoverinput.go new file mode 100644 index 00000000000..f02c6da0c29 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureunplannedfailoverinput.go @@ -0,0 +1,43 @@ +package replicationprotecteditems + +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 _ UnplannedFailoverProviderSpecificInput = HyperVReplicaAzureUnplannedFailoverInput{} + +type HyperVReplicaAzureUnplannedFailoverInput struct { + PrimaryKekCertificatePfx *string `json:"primaryKekCertificatePfx,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + SecondaryKekCertificatePfx *string `json:"secondaryKekCertificatePfx,omitempty"` + + // Fields inherited from UnplannedFailoverProviderSpecificInput +} + +var _ json.Marshaler = HyperVReplicaAzureUnplannedFailoverInput{} + +func (s HyperVReplicaAzureUnplannedFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureUnplannedFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureUnplannedFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureUnplannedFailoverInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureUnplannedFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureupdatereplicationprotectediteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureupdatereplicationprotectediteminput.go new file mode 100644 index 00000000000..8daafb5940f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicaazureupdatereplicationprotectediteminput.go @@ -0,0 +1,51 @@ +package replicationprotecteditems + +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 _ UpdateReplicationProtectedItemProviderInput = HyperVReplicaAzureUpdateReplicationProtectedItemInput{} + +type HyperVReplicaAzureUpdateReplicationProtectedItemInput struct { + DiskIdToDiskEncryptionMap *map[string]string `json:"diskIdToDiskEncryptionMap,omitempty"` + RecoveryAzureV1ResourceGroupId *string `json:"recoveryAzureV1ResourceGroupId,omitempty"` + RecoveryAzureV2ResourceGroupId *string `json:"recoveryAzureV2ResourceGroupId,omitempty"` + SqlServerLicenseType *SqlServerLicenseType `json:"sqlServerLicenseType,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetManagedDiskTags *map[string]string `json:"targetManagedDiskTags,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + UseManagedDisks *string `json:"useManagedDisks,omitempty"` + VMDisks *[]UpdateDiskInput `json:"vmDisks,omitempty"` + + // Fields inherited from UpdateReplicationProtectedItemProviderInput +} + +var _ json.Marshaler = HyperVReplicaAzureUpdateReplicationProtectedItemInput{} + +func (s HyperVReplicaAzureUpdateReplicationProtectedItemInput) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaAzureUpdateReplicationProtectedItemInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaAzureUpdateReplicationProtectedItemInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaAzureUpdateReplicationProtectedItemInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaAzureUpdateReplicationProtectedItemInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicabasereplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicabasereplicationdetails.go new file mode 100644 index 00000000000..3422c9c1b70 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicabasereplicationdetails.go @@ -0,0 +1,47 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = HyperVReplicaBaseReplicationDetails{} + +type HyperVReplicaBaseReplicationDetails struct { + InitialReplicationDetails *InitialReplicationDetails `json:"initialReplicationDetails,omitempty"` + LastReplicatedTime *string `json:"lastReplicatedTime,omitempty"` + VMDiskDetails *[]DiskDetails `json:"vMDiskDetails,omitempty"` + VMId *string `json:"vmId,omitempty"` + VMNics *[]VMNicDetails `json:"vmNics,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = HyperVReplicaBaseReplicationDetails{} + +func (s HyperVReplicaBaseReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaBaseReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaBaseReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaBaseReplicationDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaBaseReplicationDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaBaseReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicabluereplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicabluereplicationdetails.go new file mode 100644 index 00000000000..8eefc928b64 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicabluereplicationdetails.go @@ -0,0 +1,47 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = HyperVReplicaBlueReplicationDetails{} + +type HyperVReplicaBlueReplicationDetails struct { + InitialReplicationDetails *InitialReplicationDetails `json:"initialReplicationDetails,omitempty"` + LastReplicatedTime *string `json:"lastReplicatedTime,omitempty"` + VMDiskDetails *[]DiskDetails `json:"vMDiskDetails,omitempty"` + VMId *string `json:"vmId,omitempty"` + VMNics *[]VMNicDetails `json:"vmNics,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = HyperVReplicaBlueReplicationDetails{} + +func (s HyperVReplicaBlueReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaBlueReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaBlueReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaBlueReplicationDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012R2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaBlueReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicareplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicareplicationdetails.go new file mode 100644 index 00000000000..5fa220c4dca --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_hypervreplicareplicationdetails.go @@ -0,0 +1,47 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = HyperVReplicaReplicationDetails{} + +type HyperVReplicaReplicationDetails struct { + InitialReplicationDetails *InitialReplicationDetails `json:"initialReplicationDetails,omitempty"` + LastReplicatedTime *string `json:"lastReplicatedTime,omitempty"` + VMDiskDetails *[]DiskDetails `json:"vMDiskDetails,omitempty"` + VMId *string `json:"vmId,omitempty"` + VMNics *[]VMNicDetails `json:"vmNics,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = HyperVReplicaReplicationDetails{} + +func (s HyperVReplicaReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper HyperVReplicaReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HyperVReplicaReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HyperVReplicaReplicationDetails: %+v", err) + } + decoded["instanceType"] = "HyperVReplica2012" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HyperVReplicaReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_initialreplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_initialreplicationdetails.go new file mode 100644 index 00000000000..62fc3a51fc8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_initialreplicationdetails.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InitialReplicationDetails struct { + InitialReplicationProgressPercentage *string `json:"initialReplicationProgressPercentage,omitempty"` + InitialReplicationType *string `json:"initialReplicationType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageagentdetails.go new file mode 100644 index 00000000000..f899ff2af9d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageagentdetails.go @@ -0,0 +1,29 @@ +package replicationprotecteditems + +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 InMageAgentDetails struct { + AgentExpiryDate *string `json:"agentExpiryDate,omitempty"` + AgentUpdateStatus *string `json:"agentUpdateStatus,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + PostUpdateRebootStatus *string `json:"postUpdateRebootStatus,omitempty"` +} + +func (o *InMageAgentDetails) GetAgentExpiryDateAsTime() (*time.Time, error) { + if o.AgentExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AgentExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageAgentDetails) SetAgentExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AgentExpiryDate = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2applyrecoverypointinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2applyrecoverypointinput.go new file mode 100644 index 00000000000..5085ebf28bf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2applyrecoverypointinput.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 _ ApplyRecoveryPointProviderSpecificInput = InMageAzureV2ApplyRecoveryPointInput{} + +type InMageAzureV2ApplyRecoveryPointInput struct { + + // Fields inherited from ApplyRecoveryPointProviderSpecificInput +} + +var _ json.Marshaler = InMageAzureV2ApplyRecoveryPointInput{} + +func (s InMageAzureV2ApplyRecoveryPointInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2ApplyRecoveryPointInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2ApplyRecoveryPointInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2ApplyRecoveryPointInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2ApplyRecoveryPointInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2diskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2diskinputdetails.go new file mode 100644 index 00000000000..608f4030e29 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2diskinputdetails.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageAzureV2DiskInputDetails struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskType *DiskAccountType `json:"diskType,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2enableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2enableprotectioninput.go new file mode 100644 index 00000000000..9e64f09d6fb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2enableprotectioninput.go @@ -0,0 +1,66 @@ +package replicationprotecteditems + +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 _ EnableProtectionProviderSpecificInput = InMageAzureV2EnableProtectionInput{} + +type InMageAzureV2EnableProtectionInput struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskType *DiskAccountType `json:"diskType,omitempty"` + DisksToInclude *[]InMageAzureV2DiskInputDetails `json:"disksToInclude,omitempty"` + EnableRdpOnTargetOption *string `json:"enableRdpOnTargetOption,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` + MasterTargetId *string `json:"masterTargetId,omitempty"` + MultiVMGroupId *string `json:"multiVmGroupId,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + SeedManagedDiskTags *map[string]string `json:"seedManagedDiskTags,omitempty"` + SqlServerLicenseType *SqlServerLicenseType `json:"sqlServerLicenseType,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetAzureNetworkId *string `json:"targetAzureNetworkId,omitempty"` + TargetAzureSubnetId *string `json:"targetAzureSubnetId,omitempty"` + TargetAzureV1ResourceGroupId *string `json:"targetAzureV1ResourceGroupId,omitempty"` + TargetAzureV2ResourceGroupId *string `json:"targetAzureV2ResourceGroupId,omitempty"` + TargetAzureVMName *string `json:"targetAzureVmName,omitempty"` + TargetManagedDiskTags *map[string]string `json:"targetManagedDiskTags,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + + // Fields inherited from EnableProtectionProviderSpecificInput +} + +var _ json.Marshaler = InMageAzureV2EnableProtectionInput{} + +func (s InMageAzureV2EnableProtectionInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2EnableProtectionInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2EnableProtectionInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2EnableProtectionInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2EnableProtectionInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2manageddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2manageddiskdetails.go new file mode 100644 index 00000000000..3ee19942044 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2manageddiskdetails.go @@ -0,0 +1,12 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageAzureV2ManagedDiskDetails struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId *string `json:"diskId,omitempty"` + ReplicaDiskType *string `json:"replicaDiskType,omitempty"` + SeedManagedDiskId *string `json:"seedManagedDiskId,omitempty"` + TargetDiskName *string `json:"targetDiskName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2protecteddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2protecteddiskdetails.go new file mode 100644 index 00000000000..95a2304ffef --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2protecteddiskdetails.go @@ -0,0 +1,72 @@ +package replicationprotecteditems + +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 InMageAzureV2ProtectedDiskDetails struct { + DiskCapacityInBytes *int64 `json:"diskCapacityInBytes,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskResized *string `json:"diskResized,omitempty"` + FileSystemCapacityInBytes *int64 `json:"fileSystemCapacityInBytes,omitempty"` + HealthErrorCode *string `json:"healthErrorCode,omitempty"` + LastRpoCalculatedTime *string `json:"lastRpoCalculatedTime,omitempty"` + ProgressHealth *string `json:"progressHealth,omitempty"` + ProgressStatus *string `json:"progressStatus,omitempty"` + ProtectionStage *string `json:"protectionStage,omitempty"` + PsDataInMegaBytes *float64 `json:"psDataInMegaBytes,omitempty"` + ResyncDurationInSeconds *int64 `json:"resyncDurationInSeconds,omitempty"` + ResyncLast15MinutesTransferredBytes *int64 `json:"resyncLast15MinutesTransferredBytes,omitempty"` + ResyncLastDataTransferTimeUTC *string `json:"resyncLastDataTransferTimeUTC,omitempty"` + ResyncProcessedBytes *int64 `json:"resyncProcessedBytes,omitempty"` + ResyncProgressPercentage *int64 `json:"resyncProgressPercentage,omitempty"` + ResyncRequired *string `json:"resyncRequired,omitempty"` + ResyncStartTime *string `json:"resyncStartTime,omitempty"` + ResyncTotalTransferredBytes *int64 `json:"resyncTotalTransferredBytes,omitempty"` + RpoInSeconds *int64 `json:"rpoInSeconds,omitempty"` + SecondsToTakeSwitchProvider *int64 `json:"secondsToTakeSwitchProvider,omitempty"` + SourceDataInMegaBytes *float64 `json:"sourceDataInMegaBytes,omitempty"` + TargetDataInMegaBytes *float64 `json:"targetDataInMegaBytes,omitempty"` +} + +func (o *InMageAzureV2ProtectedDiskDetails) GetLastRpoCalculatedTimeAsTime() (*time.Time, error) { + if o.LastRpoCalculatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRpoCalculatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageAzureV2ProtectedDiskDetails) SetLastRpoCalculatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRpoCalculatedTime = &formatted +} + +func (o *InMageAzureV2ProtectedDiskDetails) GetResyncLastDataTransferTimeUTCAsTime() (*time.Time, error) { + if o.ResyncLastDataTransferTimeUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResyncLastDataTransferTimeUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageAzureV2ProtectedDiskDetails) SetResyncLastDataTransferTimeUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResyncLastDataTransferTimeUTC = &formatted +} + +func (o *InMageAzureV2ProtectedDiskDetails) GetResyncStartTimeAsTime() (*time.Time, error) { + if o.ResyncStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResyncStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageAzureV2ProtectedDiskDetails) SetResyncStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResyncStartTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2replicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2replicationdetails.go new file mode 100644 index 00000000000..d26606cca5e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2replicationdetails.go @@ -0,0 +1,107 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = InMageAzureV2ReplicationDetails{} + +type InMageAzureV2ReplicationDetails struct { + AgentExpiryDate *string `json:"agentExpiryDate,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + AzureVMDiskDetails *[]AzureVMDiskDetails `json:"azureVMDiskDetails,omitempty"` + AzureVMGeneration *string `json:"azureVmGeneration,omitempty"` + CompressedDataRateInMB *float64 `json:"compressedDataRateInMB,omitempty"` + DataStores *[]string `json:"datastores,omitempty"` + DiscoveryType *string `json:"discoveryType,omitempty"` + DiskResized *string `json:"diskResized,omitempty"` + EnableRdpOnTargetOption *string `json:"enableRdpOnTargetOption,omitempty"` + FirmwareType *string `json:"firmwareType,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + InfrastructureVMId *string `json:"infrastructureVmId,omitempty"` + IsAdditionalStatsAvailable *bool `json:"isAdditionalStatsAvailable,omitempty"` + IsAgentUpdateRequired *string `json:"isAgentUpdateRequired,omitempty"` + IsRebootAfterUpdateRequired *string `json:"isRebootAfterUpdateRequired,omitempty"` + LastHeartbeat *string `json:"lastHeartbeat,omitempty"` + LastRecoveryPointReceived *string `json:"lastRecoveryPointReceived,omitempty"` + LastRpoCalculatedTime *string `json:"lastRpoCalculatedTime,omitempty"` + LastUpdateReceivedTime *string `json:"lastUpdateReceivedTime,omitempty"` + LicenseType *string `json:"licenseType,omitempty"` + MasterTargetId *string `json:"masterTargetId,omitempty"` + MultiVMGroupId *string `json:"multiVmGroupId,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + MultiVMSyncStatus *string `json:"multiVmSyncStatus,omitempty"` + OsDiskId *string `json:"osDiskId,omitempty"` + OsType *string `json:"osType,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + ProcessServerName *string `json:"processServerName,omitempty"` + ProtectedDisks *[]InMageAzureV2ProtectedDiskDetails `json:"protectedDisks,omitempty"` + ProtectedManagedDisks *[]InMageAzureV2ManagedDiskDetails `json:"protectedManagedDisks,omitempty"` + ProtectionStage *string `json:"protectionStage,omitempty"` + RecoveryAvailabilitySetId *string `json:"recoveryAvailabilitySetId,omitempty"` + RecoveryAzureLogStorageAccountId *string `json:"recoveryAzureLogStorageAccountId,omitempty"` + RecoveryAzureResourceGroupId *string `json:"recoveryAzureResourceGroupId,omitempty"` + RecoveryAzureStorageAccount *string `json:"recoveryAzureStorageAccount,omitempty"` + RecoveryAzureVMName *string `json:"recoveryAzureVMName,omitempty"` + RecoveryAzureVMSize *string `json:"recoveryAzureVMSize,omitempty"` + ReplicaId *string `json:"replicaId,omitempty"` + ResyncProgressPercentage *int64 `json:"resyncProgressPercentage,omitempty"` + RpoInSeconds *int64 `json:"rpoInSeconds,omitempty"` + SeedManagedDiskTags *map[string]string `json:"seedManagedDiskTags,omitempty"` + SelectedRecoveryAzureNetworkId *string `json:"selectedRecoveryAzureNetworkId,omitempty"` + SelectedSourceNicId *string `json:"selectedSourceNicId,omitempty"` + SelectedTfoAzureNetworkId *string `json:"selectedTfoAzureNetworkId,omitempty"` + SourceVMCPUCount *int64 `json:"sourceVmCpuCount,omitempty"` + SourceVMRamSizeInMB *int64 `json:"sourceVmRamSizeInMB,omitempty"` + SqlServerLicenseType *string `json:"sqlServerLicenseType,omitempty"` + SwitchProviderBlockingErrorDetails *[]InMageAzureV2SwitchProviderBlockingErrorDetails `json:"switchProviderBlockingErrorDetails,omitempty"` + SwitchProviderDetails *InMageAzureV2SwitchProviderDetails `json:"switchProviderDetails,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetManagedDiskTags *map[string]string `json:"targetManagedDiskTags,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetVMId *string `json:"targetVmId,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + TotalDataTransferred *int64 `json:"totalDataTransferred,omitempty"` + TotalProgressHealth *string `json:"totalProgressHealth,omitempty"` + UncompressedDataRateInMB *float64 `json:"uncompressedDataRateInMB,omitempty"` + UseManagedDisks *string `json:"useManagedDisks,omitempty"` + VCenterInfrastructureId *string `json:"vCenterInfrastructureId,omitempty"` + VMId *string `json:"vmId,omitempty"` + VMNics *[]VMNicDetails `json:"vmNics,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + ValidationErrors *[]HealthError `json:"validationErrors,omitempty"` + VhdName *string `json:"vhdName,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = InMageAzureV2ReplicationDetails{} + +func (s InMageAzureV2ReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2ReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2ReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2ReplicationDetails: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2ReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2reprotectinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2reprotectinput.go new file mode 100644 index 00000000000..7acf1b58f0d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2reprotectinput.go @@ -0,0 +1,47 @@ +package replicationprotecteditems + +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 _ ReverseReplicationProviderSpecificInput = InMageAzureV2ReprotectInput{} + +type InMageAzureV2ReprotectInput struct { + DisksToInclude *[]string `json:"disksToInclude,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` + MasterTargetId *string `json:"masterTargetId,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + + // Fields inherited from ReverseReplicationProviderSpecificInput +} + +var _ json.Marshaler = InMageAzureV2ReprotectInput{} + +func (s InMageAzureV2ReprotectInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2ReprotectInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2ReprotectInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2ReprotectInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2ReprotectInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderblockingerrordetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderblockingerrordetails.go new file mode 100644 index 00000000000..d8507ad72aa --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderblockingerrordetails.go @@ -0,0 +1,13 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageAzureV2SwitchProviderBlockingErrorDetails struct { + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorMessageParameters *map[string]string `json:"errorMessageParameters,omitempty"` + ErrorTags *map[string]string `json:"errorTags,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderdetails.go new file mode 100644 index 00000000000..5c6e64b3e06 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderdetails.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageAzureV2SwitchProviderDetails struct { + TargetApplianceId *string `json:"targetApplianceId,omitempty"` + TargetFabricId *string `json:"targetFabricId,omitempty"` + TargetResourceId *string `json:"targetResourceId,omitempty"` + TargetVaultId *string `json:"targetVaultId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderproviderinput.go new file mode 100644 index 00000000000..2a55685836d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2switchproviderproviderinput.go @@ -0,0 +1,43 @@ +package replicationprotecteditems + +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 _ SwitchProviderProviderSpecificInput = InMageAzureV2SwitchProviderProviderInput{} + +type InMageAzureV2SwitchProviderProviderInput struct { + TargetApplianceID string `json:"targetApplianceID"` + TargetFabricID string `json:"targetFabricID"` + TargetVaultID string `json:"targetVaultID"` + + // Fields inherited from SwitchProviderProviderSpecificInput +} + +var _ json.Marshaler = InMageAzureV2SwitchProviderProviderInput{} + +func (s InMageAzureV2SwitchProviderProviderInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2SwitchProviderProviderInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2SwitchProviderProviderInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2SwitchProviderProviderInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2SwitchProviderProviderInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2testfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2testfailoverinput.go new file mode 100644 index 00000000000..cedd7a7a713 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2testfailoverinput.go @@ -0,0 +1,41 @@ +package replicationprotecteditems + +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 _ TestFailoverProviderSpecificInput = InMageAzureV2TestFailoverInput{} + +type InMageAzureV2TestFailoverInput struct { + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + + // Fields inherited from TestFailoverProviderSpecificInput +} + +var _ json.Marshaler = InMageAzureV2TestFailoverInput{} + +func (s InMageAzureV2TestFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2TestFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2TestFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2TestFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2TestFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2unplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2unplannedfailoverinput.go new file mode 100644 index 00000000000..5879981c993 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2unplannedfailoverinput.go @@ -0,0 +1,41 @@ +package replicationprotecteditems + +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 _ UnplannedFailoverProviderSpecificInput = InMageAzureV2UnplannedFailoverInput{} + +type InMageAzureV2UnplannedFailoverInput struct { + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + + // Fields inherited from UnplannedFailoverProviderSpecificInput +} + +var _ json.Marshaler = InMageAzureV2UnplannedFailoverInput{} + +func (s InMageAzureV2UnplannedFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2UnplannedFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2UnplannedFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2UnplannedFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2UnplannedFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2updatereplicationprotectediteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2updatereplicationprotectediteminput.go new file mode 100644 index 00000000000..02552cd40da --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageazurev2updatereplicationprotectediteminput.go @@ -0,0 +1,50 @@ +package replicationprotecteditems + +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 _ UpdateReplicationProtectedItemProviderInput = InMageAzureV2UpdateReplicationProtectedItemInput{} + +type InMageAzureV2UpdateReplicationProtectedItemInput struct { + RecoveryAzureV1ResourceGroupId *string `json:"recoveryAzureV1ResourceGroupId,omitempty"` + RecoveryAzureV2ResourceGroupId *string `json:"recoveryAzureV2ResourceGroupId,omitempty"` + SqlServerLicenseType *SqlServerLicenseType `json:"sqlServerLicenseType,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetManagedDiskTags *map[string]string `json:"targetManagedDiskTags,omitempty"` + TargetNicTags *map[string]string `json:"targetNicTags,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetVMTags *map[string]string `json:"targetVmTags,omitempty"` + UseManagedDisks *string `json:"useManagedDisks,omitempty"` + VMDisks *[]UpdateDiskInput `json:"vmDisks,omitempty"` + + // Fields inherited from UpdateReplicationProtectedItemProviderInput +} + +var _ json.Marshaler = InMageAzureV2UpdateReplicationProtectedItemInput{} + +func (s InMageAzureV2UpdateReplicationProtectedItemInput) MarshalJSON() ([]byte, error) { + type wrapper InMageAzureV2UpdateReplicationProtectedItemInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageAzureV2UpdateReplicationProtectedItemInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageAzureV2UpdateReplicationProtectedItemInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageAzureV2UpdateReplicationProtectedItemInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagedisableprotectionproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagedisableprotectionproviderspecificinput.go new file mode 100644 index 00000000000..5a6d99ee2bd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagedisableprotectionproviderspecificinput.go @@ -0,0 +1,41 @@ +package replicationprotecteditems + +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 _ DisableProtectionProviderSpecificInput = InMageDisableProtectionProviderSpecificInput{} + +type InMageDisableProtectionProviderSpecificInput struct { + ReplicaVMDeletionStatus *string `json:"replicaVmDeletionStatus,omitempty"` + + // Fields inherited from DisableProtectionProviderSpecificInput +} + +var _ json.Marshaler = InMageDisableProtectionProviderSpecificInput{} + +func (s InMageDisableProtectionProviderSpecificInput) MarshalJSON() ([]byte, error) { + type wrapper InMageDisableProtectionProviderSpecificInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageDisableProtectionProviderSpecificInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageDisableProtectionProviderSpecificInput: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageDisableProtectionProviderSpecificInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagediskexclusioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagediskexclusioninput.go new file mode 100644 index 00000000000..f43893e5555 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagediskexclusioninput.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageDiskExclusionInput struct { + DiskSignatureOptions *[]InMageDiskSignatureExclusionOptions `json:"diskSignatureOptions,omitempty"` + VolumeOptions *[]InMageVolumeExclusionOptions `json:"volumeOptions,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagedisksignatureexclusionoptions.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagedisksignatureexclusionoptions.go new file mode 100644 index 00000000000..4668154b630 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagedisksignatureexclusionoptions.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageDiskSignatureExclusionOptions struct { + DiskSignature *string `json:"diskSignature,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageenableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageenableprotectioninput.go new file mode 100644 index 00000000000..846db30cbb8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageenableprotectioninput.go @@ -0,0 +1,50 @@ +package replicationprotecteditems + +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 _ EnableProtectionProviderSpecificInput = InMageEnableProtectionInput{} + +type InMageEnableProtectionInput struct { + DatastoreName *string `json:"datastoreName,omitempty"` + DiskExclusionInput *InMageDiskExclusionInput `json:"diskExclusionInput,omitempty"` + DisksToInclude *[]string `json:"disksToInclude,omitempty"` + MasterTargetId string `json:"masterTargetId"` + MultiVMGroupId string `json:"multiVmGroupId"` + MultiVMGroupName string `json:"multiVmGroupName"` + ProcessServerId string `json:"processServerId"` + RetentionDrive string `json:"retentionDrive"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + VMFriendlyName *string `json:"vmFriendlyName,omitempty"` + + // Fields inherited from EnableProtectionProviderSpecificInput +} + +var _ json.Marshaler = InMageEnableProtectionInput{} + +func (s InMageEnableProtectionInput) MarshalJSON() ([]byte, error) { + type wrapper InMageEnableProtectionInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageEnableProtectionInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageEnableProtectionInput: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageEnableProtectionInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageprotecteddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageprotecteddiskdetails.go new file mode 100644 index 00000000000..283ba9307e4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageprotecteddiskdetails.go @@ -0,0 +1,71 @@ +package replicationprotecteditems + +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 InMageProtectedDiskDetails struct { + DiskCapacityInBytes *int64 `json:"diskCapacityInBytes,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskResized *string `json:"diskResized,omitempty"` + FileSystemCapacityInBytes *int64 `json:"fileSystemCapacityInBytes,omitempty"` + HealthErrorCode *string `json:"healthErrorCode,omitempty"` + LastRpoCalculatedTime *string `json:"lastRpoCalculatedTime,omitempty"` + ProgressHealth *string `json:"progressHealth,omitempty"` + ProgressStatus *string `json:"progressStatus,omitempty"` + ProtectionStage *string `json:"protectionStage,omitempty"` + PsDataInMB *float64 `json:"psDataInMB,omitempty"` + ResyncDurationInSeconds *int64 `json:"resyncDurationInSeconds,omitempty"` + ResyncLast15MinutesTransferredBytes *int64 `json:"resyncLast15MinutesTransferredBytes,omitempty"` + ResyncLastDataTransferTimeUTC *string `json:"resyncLastDataTransferTimeUTC,omitempty"` + ResyncProcessedBytes *int64 `json:"resyncProcessedBytes,omitempty"` + ResyncProgressPercentage *int64 `json:"resyncProgressPercentage,omitempty"` + ResyncRequired *string `json:"resyncRequired,omitempty"` + ResyncStartTime *string `json:"resyncStartTime,omitempty"` + ResyncTotalTransferredBytes *int64 `json:"resyncTotalTransferredBytes,omitempty"` + RpoInSeconds *int64 `json:"rpoInSeconds,omitempty"` + SourceDataInMB *float64 `json:"sourceDataInMB,omitempty"` + TargetDataInMB *float64 `json:"targetDataInMB,omitempty"` +} + +func (o *InMageProtectedDiskDetails) GetLastRpoCalculatedTimeAsTime() (*time.Time, error) { + if o.LastRpoCalculatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRpoCalculatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageProtectedDiskDetails) SetLastRpoCalculatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRpoCalculatedTime = &formatted +} + +func (o *InMageProtectedDiskDetails) GetResyncLastDataTransferTimeUTCAsTime() (*time.Time, error) { + if o.ResyncLastDataTransferTimeUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResyncLastDataTransferTimeUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageProtectedDiskDetails) SetResyncLastDataTransferTimeUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResyncLastDataTransferTimeUTC = &formatted +} + +func (o *InMageProtectedDiskDetails) GetResyncStartTimeAsTime() (*time.Time, error) { + if o.ResyncStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResyncStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageProtectedDiskDetails) SetResyncStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResyncStartTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmagentupgradeblockingerrordetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmagentupgradeblockingerrordetails.go new file mode 100644 index 00000000000..6235f92ce41 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmagentupgradeblockingerrordetails.go @@ -0,0 +1,13 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmAgentUpgradeBlockingErrorDetails struct { + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorMessageParameters *map[string]string `json:"errorMessageParameters,omitempty"` + ErrorTags *map[string]string `json:"errorTags,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmapplyrecoverypointinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmapplyrecoverypointinput.go new file mode 100644 index 00000000000..316da5fb056 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmapplyrecoverypointinput.go @@ -0,0 +1,41 @@ +package replicationprotecteditems + +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 _ ApplyRecoveryPointProviderSpecificInput = InMageRcmApplyRecoveryPointInput{} + +type InMageRcmApplyRecoveryPointInput struct { + RecoveryPointId string `json:"recoveryPointId"` + + // Fields inherited from ApplyRecoveryPointProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmApplyRecoveryPointInput{} + +func (s InMageRcmApplyRecoveryPointInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmApplyRecoveryPointInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmApplyRecoveryPointInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmApplyRecoveryPointInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmApplyRecoveryPointInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdiscoveredprotectedvmdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdiscoveredprotectedvmdetails.go new file mode 100644 index 00000000000..345e3b53683 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdiscoveredprotectedvmdetails.go @@ -0,0 +1,61 @@ +package replicationprotecteditems + +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 InMageRcmDiscoveredProtectedVMDetails struct { + CreatedTimestamp *string `json:"createdTimestamp,omitempty"` + DataStores *[]string `json:"datastores,omitempty"` + IPAddresses *[]string `json:"ipAddresses,omitempty"` + IsDeleted *bool `json:"isDeleted,omitempty"` + LastDiscoveryTimeInUtc *string `json:"lastDiscoveryTimeInUtc,omitempty"` + OsName *string `json:"osName,omitempty"` + PowerStatus *string `json:"powerStatus,omitempty"` + UpdatedTimestamp *string `json:"updatedTimestamp,omitempty"` + VCenterFqdn *string `json:"vCenterFqdn,omitempty"` + VCenterId *string `json:"vCenterId,omitempty"` + VMFqdn *string `json:"vmFqdn,omitempty"` + VMwareToolsStatus *string `json:"vmwareToolsStatus,omitempty"` +} + +func (o *InMageRcmDiscoveredProtectedVMDetails) GetCreatedTimestampAsTime() (*time.Time, error) { + if o.CreatedTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmDiscoveredProtectedVMDetails) SetCreatedTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTimestamp = &formatted +} + +func (o *InMageRcmDiscoveredProtectedVMDetails) GetLastDiscoveryTimeInUtcAsTime() (*time.Time, error) { + if o.LastDiscoveryTimeInUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastDiscoveryTimeInUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmDiscoveredProtectedVMDetails) SetLastDiscoveryTimeInUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastDiscoveryTimeInUtc = &formatted +} + +func (o *InMageRcmDiscoveredProtectedVMDetails) GetUpdatedTimestampAsTime() (*time.Time, error) { + if o.UpdatedTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmDiscoveredProtectedVMDetails) SetUpdatedTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedTimestamp = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdiskinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdiskinput.go new file mode 100644 index 00000000000..083eabe8d9a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdiskinput.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmDiskInput struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId string `json:"diskId"` + DiskType DiskAccountType `json:"diskType"` + LogStorageAccountId string `json:"logStorageAccountId"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdisksdefaultinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdisksdefaultinput.go new file mode 100644 index 00000000000..64213070d05 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmdisksdefaultinput.go @@ -0,0 +1,10 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmDisksDefaultInput struct { + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskType DiskAccountType `json:"diskType"` + LogStorageAccountId string `json:"logStorageAccountId"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmenableprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmenableprotectioninput.go new file mode 100644 index 00000000000..aaf09991d81 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmenableprotectioninput.go @@ -0,0 +1,58 @@ +package replicationprotecteditems + +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 _ EnableProtectionProviderSpecificInput = InMageRcmEnableProtectionInput{} + +type InMageRcmEnableProtectionInput struct { + DisksDefault *InMageRcmDisksDefaultInput `json:"disksDefault,omitempty"` + DisksToInclude *[]InMageRcmDiskInput `json:"disksToInclude,omitempty"` + FabricDiscoveryMachineId string `json:"fabricDiscoveryMachineId"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + ProcessServerId string `json:"processServerId"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetBootDiagnosticsStorageAccountId *string `json:"targetBootDiagnosticsStorageAccountId,omitempty"` + TargetNetworkId *string `json:"targetNetworkId,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetResourceGroupId string `json:"targetResourceGroupId"` + TargetSubnetName *string `json:"targetSubnetName,omitempty"` + TargetVMName *string `json:"targetVmName,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TestNetworkId *string `json:"testNetworkId,omitempty"` + TestSubnetName *string `json:"testSubnetName,omitempty"` + + // Fields inherited from EnableProtectionProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmEnableProtectionInput{} + +func (s InMageRcmEnableProtectionInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmEnableProtectionInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmEnableProtectionInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmEnableProtectionInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmEnableProtectionInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackdiscoveredprotectedvmdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackdiscoveredprotectedvmdetails.go new file mode 100644 index 00000000000..e90a52a1048 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackdiscoveredprotectedvmdetails.go @@ -0,0 +1,61 @@ +package replicationprotecteditems + +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 InMageRcmFailbackDiscoveredProtectedVMDetails struct { + CreatedTimestamp *string `json:"createdTimestamp,omitempty"` + DataStores *[]string `json:"datastores,omitempty"` + IPAddresses *[]string `json:"ipAddresses,omitempty"` + IsDeleted *bool `json:"isDeleted,omitempty"` + LastDiscoveryTimeInUtc *string `json:"lastDiscoveryTimeInUtc,omitempty"` + OsName *string `json:"osName,omitempty"` + PowerStatus *string `json:"powerStatus,omitempty"` + UpdatedTimestamp *string `json:"updatedTimestamp,omitempty"` + VCenterFqdn *string `json:"vCenterFqdn,omitempty"` + VCenterId *string `json:"vCenterId,omitempty"` + VMFqdn *string `json:"vmFqdn,omitempty"` + VMwareToolsStatus *string `json:"vmwareToolsStatus,omitempty"` +} + +func (o *InMageRcmFailbackDiscoveredProtectedVMDetails) GetCreatedTimestampAsTime() (*time.Time, error) { + if o.CreatedTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmFailbackDiscoveredProtectedVMDetails) SetCreatedTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTimestamp = &formatted +} + +func (o *InMageRcmFailbackDiscoveredProtectedVMDetails) GetLastDiscoveryTimeInUtcAsTime() (*time.Time, error) { + if o.LastDiscoveryTimeInUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastDiscoveryTimeInUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmFailbackDiscoveredProtectedVMDetails) SetLastDiscoveryTimeInUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastDiscoveryTimeInUtc = &formatted +} + +func (o *InMageRcmFailbackDiscoveredProtectedVMDetails) GetUpdatedTimestampAsTime() (*time.Time, error) { + if o.UpdatedTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmFailbackDiscoveredProtectedVMDetails) SetUpdatedTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedTimestamp = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackmobilityagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackmobilityagentdetails.go new file mode 100644 index 00000000000..6ef3f5e7b37 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackmobilityagentdetails.go @@ -0,0 +1,58 @@ +package replicationprotecteditems + +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 InMageRcmFailbackMobilityAgentDetails struct { + AgentVersionExpiryDate *string `json:"agentVersionExpiryDate,omitempty"` + DriverVersion *string `json:"driverVersion,omitempty"` + DriverVersionExpiryDate *string `json:"driverVersionExpiryDate,omitempty"` + IsUpgradeable *string `json:"isUpgradeable,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + LatestUpgradableVersionWithoutReboot *string `json:"latestUpgradableVersionWithoutReboot,omitempty"` + LatestVersion *string `json:"latestVersion,omitempty"` + ReasonsBlockingUpgrade *[]AgentUpgradeBlockedReason `json:"reasonsBlockingUpgrade,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *InMageRcmFailbackMobilityAgentDetails) GetAgentVersionExpiryDateAsTime() (*time.Time, error) { + if o.AgentVersionExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AgentVersionExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmFailbackMobilityAgentDetails) SetAgentVersionExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AgentVersionExpiryDate = &formatted +} + +func (o *InMageRcmFailbackMobilityAgentDetails) GetDriverVersionExpiryDateAsTime() (*time.Time, error) { + if o.DriverVersionExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DriverVersionExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmFailbackMobilityAgentDetails) SetDriverVersionExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DriverVersionExpiryDate = &formatted +} + +func (o *InMageRcmFailbackMobilityAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmFailbackMobilityAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbacknicdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbacknicdetails.go new file mode 100644 index 00000000000..44ac3499256 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbacknicdetails.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmFailbackNicDetails struct { + AdapterType *string `json:"adapterType,omitempty"` + MacAddress *string `json:"macAddress,omitempty"` + NetworkName *string `json:"networkName,omitempty"` + SourceIPAddress *string `json:"sourceIpAddress,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackplannedfailoverproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackplannedfailoverproviderinput.go new file mode 100644 index 00000000000..4fb7cddae1e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackplannedfailoverproviderinput.go @@ -0,0 +1,41 @@ +package replicationprotecteditems + +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 _ PlannedFailoverProviderSpecificFailoverInput = InMageRcmFailbackPlannedFailoverProviderInput{} + +type InMageRcmFailbackPlannedFailoverProviderInput struct { + RecoveryPointType InMageRcmFailbackRecoveryPointType `json:"recoveryPointType"` + + // Fields inherited from PlannedFailoverProviderSpecificFailoverInput +} + +var _ json.Marshaler = InMageRcmFailbackPlannedFailoverProviderInput{} + +func (s InMageRcmFailbackPlannedFailoverProviderInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFailbackPlannedFailoverProviderInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFailbackPlannedFailoverProviderInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFailbackPlannedFailoverProviderInput: %+v", err) + } + decoded["instanceType"] = "InMageRcmFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFailbackPlannedFailoverProviderInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackprotecteddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackprotecteddiskdetails.go new file mode 100644 index 00000000000..0d93a99814a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackprotecteddiskdetails.go @@ -0,0 +1,36 @@ +package replicationprotecteditems + +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 InMageRcmFailbackProtectedDiskDetails struct { + CapacityInBytes *int64 `json:"capacityInBytes,omitempty"` + DataPendingAtSourceAgentInMB *float64 `json:"dataPendingAtSourceAgentInMB,omitempty"` + DataPendingInLogDataStoreInMB *float64 `json:"dataPendingInLogDataStoreInMB,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskUuid *string `json:"diskUuid,omitempty"` + IrDetails *InMageRcmFailbackSyncDetails `json:"irDetails,omitempty"` + IsInitialReplicationComplete *string `json:"isInitialReplicationComplete,omitempty"` + IsOSDisk *string `json:"isOSDisk,omitempty"` + LastSyncTime *string `json:"lastSyncTime,omitempty"` + ResyncDetails *InMageRcmFailbackSyncDetails `json:"resyncDetails,omitempty"` +} + +func (o *InMageRcmFailbackProtectedDiskDetails) GetLastSyncTimeAsTime() (*time.Time, error) { + if o.LastSyncTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSyncTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmFailbackProtectedDiskDetails) SetLastSyncTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSyncTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackreplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackreplicationdetails.go new file mode 100644 index 00000000000..20af36d13aa --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackreplicationdetails.go @@ -0,0 +1,69 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = InMageRcmFailbackReplicationDetails{} + +type InMageRcmFailbackReplicationDetails struct { + AzureVirtualMachineId *string `json:"azureVirtualMachineId,omitempty"` + DiscoveredVMDetails *InMageRcmFailbackDiscoveredProtectedVMDetails `json:"discoveredVmDetails,omitempty"` + InitialReplicationProcessedBytes *int64 `json:"initialReplicationProcessedBytes,omitempty"` + InitialReplicationProgressHealth *VMReplicationProgressHealth `json:"initialReplicationProgressHealth,omitempty"` + InitialReplicationProgressPercentage *int64 `json:"initialReplicationProgressPercentage,omitempty"` + InitialReplicationTransferredBytes *int64 `json:"initialReplicationTransferredBytes,omitempty"` + InternalIdentifier *string `json:"internalIdentifier,omitempty"` + IsAgentRegistrationSuccessfulAfterFailover *bool `json:"isAgentRegistrationSuccessfulAfterFailover,omitempty"` + LastPlannedFailoverStartTime *string `json:"lastPlannedFailoverStartTime,omitempty"` + LastPlannedFailoverStatus *PlannedFailoverStatus `json:"lastPlannedFailoverStatus,omitempty"` + LastUsedPolicyFriendlyName *string `json:"lastUsedPolicyFriendlyName,omitempty"` + LastUsedPolicyId *string `json:"lastUsedPolicyId,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` + MobilityAgentDetails *InMageRcmFailbackMobilityAgentDetails `json:"mobilityAgentDetails,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + OsType *string `json:"osType,omitempty"` + ProtectedDisks *[]InMageRcmFailbackProtectedDiskDetails `json:"protectedDisks,omitempty"` + ReprotectAgentId *string `json:"reprotectAgentId,omitempty"` + ReprotectAgentName *string `json:"reprotectAgentName,omitempty"` + ResyncProcessedBytes *int64 `json:"resyncProcessedBytes,omitempty"` + ResyncProgressHealth *VMReplicationProgressHealth `json:"resyncProgressHealth,omitempty"` + ResyncProgressPercentage *int64 `json:"resyncProgressPercentage,omitempty"` + ResyncRequired *string `json:"resyncRequired,omitempty"` + ResyncState *ResyncState `json:"resyncState,omitempty"` + ResyncTransferredBytes *int64 `json:"resyncTransferredBytes,omitempty"` + TargetDataStoreName *string `json:"targetDataStoreName,omitempty"` + TargetVMName *string `json:"targetVmName,omitempty"` + TargetvCenterId *string `json:"targetvCenterId,omitempty"` + VMNics *[]InMageRcmFailbackNicDetails `json:"vmNics,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = InMageRcmFailbackReplicationDetails{} + +func (s InMageRcmFailbackReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFailbackReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFailbackReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFailbackReplicationDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcmFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFailbackReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackreprotectinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackreprotectinput.go new file mode 100644 index 00000000000..766cbb8d8f6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbackreprotectinput.go @@ -0,0 +1,43 @@ +package replicationprotecteditems + +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 _ ReverseReplicationProviderSpecificInput = InMageRcmFailbackReprotectInput{} + +type InMageRcmFailbackReprotectInput struct { + PolicyId string `json:"policyId"` + ProcessServerId string `json:"processServerId"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + + // Fields inherited from ReverseReplicationProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmFailbackReprotectInput{} + +func (s InMageRcmFailbackReprotectInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmFailbackReprotectInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmFailbackReprotectInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmFailbackReprotectInput: %+v", err) + } + decoded["instanceType"] = "InMageRcmFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmFailbackReprotectInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbacksyncdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbacksyncdetails.go new file mode 100644 index 00000000000..5451ccadcf1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmfailbacksyncdetails.go @@ -0,0 +1,15 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmFailbackSyncDetails struct { + Last15MinutesTransferredBytes *int64 `json:"last15MinutesTransferredBytes,omitempty"` + LastDataTransferTimeUtc *string `json:"lastDataTransferTimeUtc,omitempty"` + LastRefreshTime *string `json:"lastRefreshTime,omitempty"` + ProcessedBytes *int64 `json:"processedBytes,omitempty"` + ProgressHealth *DiskReplicationProgressHealth `json:"progressHealth,omitempty"` + ProgressPercentage *int64 `json:"progressPercentage,omitempty"` + StartTime *string `json:"startTime,omitempty"` + TransferredBytes *int64 `json:"transferredBytes,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmlastagentupgradeerrordetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmlastagentupgradeerrordetails.go new file mode 100644 index 00000000000..8e87e3b48bc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmlastagentupgradeerrordetails.go @@ -0,0 +1,13 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmLastAgentUpgradeErrorDetails struct { + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorMessageParameters *map[string]string `json:"errorMessageParameters,omitempty"` + ErrorTags *map[string]string `json:"errorTags,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmmobilityagentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmmobilityagentdetails.go new file mode 100644 index 00000000000..bc2431c22ae --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmmobilityagentdetails.go @@ -0,0 +1,59 @@ +package replicationprotecteditems + +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 InMageRcmMobilityAgentDetails struct { + AgentVersionExpiryDate *string `json:"agentVersionExpiryDate,omitempty"` + DriverVersion *string `json:"driverVersion,omitempty"` + DriverVersionExpiryDate *string `json:"driverVersionExpiryDate,omitempty"` + IsUpgradeable *string `json:"isUpgradeable,omitempty"` + LastHeartbeatUtc *string `json:"lastHeartbeatUtc,omitempty"` + LatestAgentReleaseDate *string `json:"latestAgentReleaseDate,omitempty"` + LatestUpgradableVersionWithoutReboot *string `json:"latestUpgradableVersionWithoutReboot,omitempty"` + LatestVersion *string `json:"latestVersion,omitempty"` + ReasonsBlockingUpgrade *[]AgentUpgradeBlockedReason `json:"reasonsBlockingUpgrade,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *InMageRcmMobilityAgentDetails) GetAgentVersionExpiryDateAsTime() (*time.Time, error) { + if o.AgentVersionExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AgentVersionExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmMobilityAgentDetails) SetAgentVersionExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AgentVersionExpiryDate = &formatted +} + +func (o *InMageRcmMobilityAgentDetails) GetDriverVersionExpiryDateAsTime() (*time.Time, error) { + if o.DriverVersionExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DriverVersionExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmMobilityAgentDetails) SetDriverVersionExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DriverVersionExpiryDate = &formatted +} + +func (o *InMageRcmMobilityAgentDetails) GetLastHeartbeatUtcAsTime() (*time.Time, error) { + if o.LastHeartbeatUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeatUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InMageRcmMobilityAgentDetails) SetLastHeartbeatUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeatUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmnicdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmnicdetails.go new file mode 100644 index 00000000000..83396d6b89e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmnicdetails.go @@ -0,0 +1,20 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmNicDetails struct { + IsPrimaryNic *string `json:"isPrimaryNic,omitempty"` + IsSelectedForFailover *string `json:"isSelectedForFailover,omitempty"` + NicId *string `json:"nicId,omitempty"` + SourceIPAddress *string `json:"sourceIPAddress,omitempty"` + SourceIPAddressType *EthernetAddressType `json:"sourceIPAddressType,omitempty"` + SourceNetworkId *string `json:"sourceNetworkId,omitempty"` + SourceSubnetName *string `json:"sourceSubnetName,omitempty"` + TargetIPAddress *string `json:"targetIPAddress,omitempty"` + TargetIPAddressType *EthernetAddressType `json:"targetIPAddressType,omitempty"` + TargetSubnetName *string `json:"targetSubnetName,omitempty"` + TestIPAddress *string `json:"testIPAddress,omitempty"` + TestIPAddressType *EthernetAddressType `json:"testIPAddressType,omitempty"` + TestSubnetName *string `json:"testSubnetName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmnicinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmnicinput.go new file mode 100644 index 00000000000..552bb0d12d7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmnicinput.go @@ -0,0 +1,14 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmNicInput struct { + IsPrimaryNic string `json:"isPrimaryNic"` + IsSelectedForFailover *string `json:"isSelectedForFailover,omitempty"` + NicId string `json:"nicId"` + TargetStaticIPAddress *string `json:"targetStaticIPAddress,omitempty"` + TargetSubnetName *string `json:"targetSubnetName,omitempty"` + TestStaticIPAddress *string `json:"testStaticIPAddress,omitempty"` + TestSubnetName *string `json:"testSubnetName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmprotecteddiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmprotecteddiskdetails.go new file mode 100644 index 00000000000..c592b09c3dd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmprotecteddiskdetails.go @@ -0,0 +1,22 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmProtectedDiskDetails struct { + CapacityInBytes *int64 `json:"capacityInBytes,omitempty"` + DataPendingAtSourceAgentInMB *float64 `json:"dataPendingAtSourceAgentInMB,omitempty"` + DataPendingInLogDataStoreInMB *float64 `json:"dataPendingInLogDataStoreInMB,omitempty"` + DiskEncryptionSetId *string `json:"diskEncryptionSetId,omitempty"` + DiskId *string `json:"diskId,omitempty"` + DiskName *string `json:"diskName,omitempty"` + DiskType *DiskAccountType `json:"diskType,omitempty"` + IrDetails *InMageRcmSyncDetails `json:"irDetails,omitempty"` + IsInitialReplicationComplete *string `json:"isInitialReplicationComplete,omitempty"` + IsOSDisk *string `json:"isOSDisk,omitempty"` + LogStorageAccountId *string `json:"logStorageAccountId,omitempty"` + ResyncDetails *InMageRcmSyncDetails `json:"resyncDetails,omitempty"` + SeedBlobUri *string `json:"seedBlobUri,omitempty"` + SeedManagedDiskId *string `json:"seedManagedDiskId,omitempty"` + TargetManagedDiskId *string `json:"targetManagedDiskId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmreplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmreplicationdetails.go new file mode 100644 index 00000000000..8d8f494fcff --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmreplicationdetails.go @@ -0,0 +1,92 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = InMageRcmReplicationDetails{} + +type InMageRcmReplicationDetails struct { + AgentUpgradeAttemptToVersion *string `json:"agentUpgradeAttemptToVersion,omitempty"` + AgentUpgradeBlockingErrorDetails *[]InMageRcmAgentUpgradeBlockingErrorDetails `json:"agentUpgradeBlockingErrorDetails,omitempty"` + AgentUpgradeJobId *string `json:"agentUpgradeJobId,omitempty"` + AgentUpgradeState *MobilityAgentUpgradeState `json:"agentUpgradeState,omitempty"` + AllocatedMemoryInMB *float64 `json:"allocatedMemoryInMB,omitempty"` + DiscoveredVMDetails *InMageRcmDiscoveredProtectedVMDetails `json:"discoveredVmDetails,omitempty"` + DiscoveryType *string `json:"discoveryType,omitempty"` + FabricDiscoveryMachineId *string `json:"fabricDiscoveryMachineId,omitempty"` + FailoverRecoveryPointId *string `json:"failoverRecoveryPointId,omitempty"` + FirmwareType *string `json:"firmwareType,omitempty"` + InitialReplicationProcessedBytes *int64 `json:"initialReplicationProcessedBytes,omitempty"` + InitialReplicationProgressHealth *VMReplicationProgressHealth `json:"initialReplicationProgressHealth,omitempty"` + InitialReplicationProgressPercentage *int64 `json:"initialReplicationProgressPercentage,omitempty"` + InitialReplicationTransferredBytes *int64 `json:"initialReplicationTransferredBytes,omitempty"` + InternalIdentifier *string `json:"internalIdentifier,omitempty"` + IsAgentRegistrationSuccessfulAfterFailover *bool `json:"isAgentRegistrationSuccessfulAfterFailover,omitempty"` + IsLastUpgradeSuccessful *string `json:"isLastUpgradeSuccessful,omitempty"` + LastAgentUpgradeErrorDetails *[]InMageRcmLastAgentUpgradeErrorDetails `json:"lastAgentUpgradeErrorDetails,omitempty"` + LastAgentUpgradeType *string `json:"lastAgentUpgradeType,omitempty"` + LastRecoveryPointId *string `json:"lastRecoveryPointId,omitempty"` + LastRecoveryPointReceived *string `json:"lastRecoveryPointReceived,omitempty"` + LastRpoCalculatedTime *string `json:"lastRpoCalculatedTime,omitempty"` + LastRpoInSeconds *int64 `json:"lastRpoInSeconds,omitempty"` + LicenseType *string `json:"licenseType,omitempty"` + MobilityAgentDetails *InMageRcmMobilityAgentDetails `json:"mobilityAgentDetails,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + OsType *string `json:"osType,omitempty"` + PrimaryNicIPAddress *string `json:"primaryNicIpAddress,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + ProcessServerName *string `json:"processServerName,omitempty"` + ProcessorCoreCount *int64 `json:"processorCoreCount,omitempty"` + ProtectedDisks *[]InMageRcmProtectedDiskDetails `json:"protectedDisks,omitempty"` + ResyncProcessedBytes *int64 `json:"resyncProcessedBytes,omitempty"` + ResyncProgressHealth *VMReplicationProgressHealth `json:"resyncProgressHealth,omitempty"` + ResyncProgressPercentage *int64 `json:"resyncProgressPercentage,omitempty"` + ResyncRequired *string `json:"resyncRequired,omitempty"` + ResyncState *ResyncState `json:"resyncState,omitempty"` + ResyncTransferredBytes *int64 `json:"resyncTransferredBytes,omitempty"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetBootDiagnosticsStorageAccountId *string `json:"targetBootDiagnosticsStorageAccountId,omitempty"` + TargetGeneration *string `json:"targetGeneration,omitempty"` + TargetLocation *string `json:"targetLocation,omitempty"` + TargetNetworkId *string `json:"targetNetworkId,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVMName *string `json:"targetVmName,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TestNetworkId *string `json:"testNetworkId,omitempty"` + VMNics *[]InMageRcmNicDetails `json:"vmNics,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = InMageRcmReplicationDetails{} + +func (s InMageRcmReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmReplicationDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmreprotectinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmreprotectinput.go new file mode 100644 index 00000000000..f36bee34a6c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmreprotectinput.go @@ -0,0 +1,44 @@ +package replicationprotecteditems + +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 _ ReverseReplicationProviderSpecificInput = InMageRcmReprotectInput{} + +type InMageRcmReprotectInput struct { + DatastoreName string `json:"datastoreName"` + LogStorageAccountId string `json:"logStorageAccountId"` + PolicyId *string `json:"policyId,omitempty"` + ReprotectAgentId string `json:"reprotectAgentId"` + + // Fields inherited from ReverseReplicationProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmReprotectInput{} + +func (s InMageRcmReprotectInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmReprotectInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmReprotectInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmReprotectInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmReprotectInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmsyncdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmsyncdetails.go new file mode 100644 index 00000000000..a8388f3c5f8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmsyncdetails.go @@ -0,0 +1,15 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageRcmSyncDetails struct { + Last15MinutesTransferredBytes *int64 `json:"last15MinutesTransferredBytes,omitempty"` + LastDataTransferTimeUtc *string `json:"lastDataTransferTimeUtc,omitempty"` + LastRefreshTime *string `json:"lastRefreshTime,omitempty"` + ProcessedBytes *int64 `json:"processedBytes,omitempty"` + ProgressHealth *DiskReplicationProgressHealth `json:"progressHealth,omitempty"` + ProgressPercentage *int64 `json:"progressPercentage,omitempty"` + StartTime *string `json:"startTime,omitempty"` + TransferredBytes *int64 `json:"transferredBytes,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmtestfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmtestfailoverinput.go new file mode 100644 index 00000000000..4f3264c0859 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmtestfailoverinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ TestFailoverProviderSpecificInput = InMageRcmTestFailoverInput{} + +type InMageRcmTestFailoverInput struct { + NetworkId *string `json:"networkId,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + + // Fields inherited from TestFailoverProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmTestFailoverInput{} + +func (s InMageRcmTestFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmTestFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmTestFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmTestFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmTestFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmunplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmunplannedfailoverinput.go new file mode 100644 index 00000000000..688ddd4e9f1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmunplannedfailoverinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ UnplannedFailoverProviderSpecificInput = InMageRcmUnplannedFailoverInput{} + +type InMageRcmUnplannedFailoverInput struct { + PerformShutdown string `json:"performShutdown"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + + // Fields inherited from UnplannedFailoverProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmUnplannedFailoverInput{} + +func (s InMageRcmUnplannedFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmUnplannedFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmUnplannedFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmUnplannedFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmUnplannedFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmupdateapplianceforreplicationprotectediteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmupdateapplianceforreplicationprotectediteminput.go new file mode 100644 index 00000000000..59a0e19cd4a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmupdateapplianceforreplicationprotectediteminput.go @@ -0,0 +1,41 @@ +package replicationprotecteditems + +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 _ UpdateApplianceForReplicationProtectedItemProviderSpecificInput = InMageRcmUpdateApplianceForReplicationProtectedItemInput{} + +type InMageRcmUpdateApplianceForReplicationProtectedItemInput struct { + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + + // Fields inherited from UpdateApplianceForReplicationProtectedItemProviderSpecificInput +} + +var _ json.Marshaler = InMageRcmUpdateApplianceForReplicationProtectedItemInput{} + +func (s InMageRcmUpdateApplianceForReplicationProtectedItemInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmUpdateApplianceForReplicationProtectedItemInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmUpdateApplianceForReplicationProtectedItemInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmUpdateApplianceForReplicationProtectedItemInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmUpdateApplianceForReplicationProtectedItemInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmupdatereplicationprotectediteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmupdatereplicationprotectediteminput.go new file mode 100644 index 00000000000..428a0dc1aeb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagercmupdatereplicationprotectediteminput.go @@ -0,0 +1,51 @@ +package replicationprotecteditems + +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 _ UpdateReplicationProtectedItemProviderInput = InMageRcmUpdateReplicationProtectedItemInput{} + +type InMageRcmUpdateReplicationProtectedItemInput struct { + LicenseType *LicenseType `json:"licenseType,omitempty"` + TargetAvailabilitySetId *string `json:"targetAvailabilitySetId,omitempty"` + TargetAvailabilityZone *string `json:"targetAvailabilityZone,omitempty"` + TargetBootDiagnosticsStorageAccountId *string `json:"targetBootDiagnosticsStorageAccountId,omitempty"` + TargetNetworkId *string `json:"targetNetworkId,omitempty"` + TargetProximityPlacementGroupId *string `json:"targetProximityPlacementGroupId,omitempty"` + TargetResourceGroupId *string `json:"targetResourceGroupId,omitempty"` + TargetVMName *string `json:"targetVmName,omitempty"` + TargetVMSize *string `json:"targetVmSize,omitempty"` + TestNetworkId *string `json:"testNetworkId,omitempty"` + VMNics *[]InMageRcmNicInput `json:"vmNics,omitempty"` + + // Fields inherited from UpdateReplicationProtectedItemProviderInput +} + +var _ json.Marshaler = InMageRcmUpdateReplicationProtectedItemInput{} + +func (s InMageRcmUpdateReplicationProtectedItemInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmUpdateReplicationProtectedItemInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmUpdateReplicationProtectedItemInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmUpdateReplicationProtectedItemInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmUpdateReplicationProtectedItemInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagereplicationdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagereplicationdetails.go new file mode 100644 index 00000000000..b12af712d38 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagereplicationdetails.go @@ -0,0 +1,80 @@ +package replicationprotecteditems + +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 _ ReplicationProviderSpecificSettings = InMageReplicationDetails{} + +type InMageReplicationDetails struct { + ActiveSiteType *string `json:"activeSiteType,omitempty"` + AgentDetails *InMageAgentDetails `json:"agentDetails,omitempty"` + AzureStorageAccountId *string `json:"azureStorageAccountId,omitempty"` + CompressedDataRateInMB *float64 `json:"compressedDataRateInMB,omitempty"` + ConsistencyPoints *map[string]string `json:"consistencyPoints,omitempty"` + DataStores *[]string `json:"datastores,omitempty"` + DiscoveryType *string `json:"discoveryType,omitempty"` + DiskResized *string `json:"diskResized,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + InfrastructureVMId *string `json:"infrastructureVmId,omitempty"` + IsAdditionalStatsAvailable *bool `json:"isAdditionalStatsAvailable,omitempty"` + LastHeartbeat *string `json:"lastHeartbeat,omitempty"` + LastRpoCalculatedTime *string `json:"lastRpoCalculatedTime,omitempty"` + LastUpdateReceivedTime *string `json:"lastUpdateReceivedTime,omitempty"` + MasterTargetId *string `json:"masterTargetId,omitempty"` + MultiVMGroupId *string `json:"multiVmGroupId,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + MultiVMSyncStatus *string `json:"multiVmSyncStatus,omitempty"` + OsDetails *OSDiskDetails `json:"osDetails,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + ProtectedDisks *[]InMageProtectedDiskDetails `json:"protectedDisks,omitempty"` + ProtectionStage *string `json:"protectionStage,omitempty"` + RebootAfterUpdateStatus *string `json:"rebootAfterUpdateStatus,omitempty"` + ReplicaId *string `json:"replicaId,omitempty"` + ResyncDetails *InitialReplicationDetails `json:"resyncDetails,omitempty"` + RetentionWindowEnd *string `json:"retentionWindowEnd,omitempty"` + RetentionWindowStart *string `json:"retentionWindowStart,omitempty"` + RpoInSeconds *int64 `json:"rpoInSeconds,omitempty"` + SourceVMCPUCount *int64 `json:"sourceVmCpuCount,omitempty"` + SourceVMRamSizeInMB *int64 `json:"sourceVmRamSizeInMB,omitempty"` + TotalDataTransferred *int64 `json:"totalDataTransferred,omitempty"` + TotalProgressHealth *string `json:"totalProgressHealth,omitempty"` + UncompressedDataRateInMB *float64 `json:"uncompressedDataRateInMB,omitempty"` + VCenterInfrastructureId *string `json:"vCenterInfrastructureId,omitempty"` + VMId *string `json:"vmId,omitempty"` + VMNics *[]VMNicDetails `json:"vmNics,omitempty"` + VMProtectionState *string `json:"vmProtectionState,omitempty"` + VMProtectionStateDescription *string `json:"vmProtectionStateDescription,omitempty"` + ValidationErrors *[]HealthError `json:"validationErrors,omitempty"` + + // Fields inherited from ReplicationProviderSpecificSettings +} + +var _ json.Marshaler = InMageReplicationDetails{} + +func (s InMageReplicationDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageReplicationDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageReplicationDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageReplicationDetails: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageReplicationDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagereprotectinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagereprotectinput.go new file mode 100644 index 00000000000..8ed97d029c8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagereprotectinput.go @@ -0,0 +1,48 @@ +package replicationprotecteditems + +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 _ ReverseReplicationProviderSpecificInput = InMageReprotectInput{} + +type InMageReprotectInput struct { + DatastoreName *string `json:"datastoreName,omitempty"` + DiskExclusionInput *InMageDiskExclusionInput `json:"diskExclusionInput,omitempty"` + DisksToInclude *[]string `json:"disksToInclude,omitempty"` + MasterTargetId string `json:"masterTargetId"` + ProcessServerId string `json:"processServerId"` + ProfileId string `json:"profileId"` + RetentionDrive string `json:"retentionDrive"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` + + // Fields inherited from ReverseReplicationProviderSpecificInput +} + +var _ json.Marshaler = InMageReprotectInput{} + +func (s InMageReprotectInput) MarshalJSON() ([]byte, error) { + type wrapper InMageReprotectInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageReprotectInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageReprotectInput: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageReprotectInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagetestfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagetestfailoverinput.go new file mode 100644 index 00000000000..68347d06749 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagetestfailoverinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ TestFailoverProviderSpecificInput = InMageTestFailoverInput{} + +type InMageTestFailoverInput struct { + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointType *RecoveryPointType `json:"recoveryPointType,omitempty"` + + // Fields inherited from TestFailoverProviderSpecificInput +} + +var _ json.Marshaler = InMageTestFailoverInput{} + +func (s InMageTestFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper InMageTestFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageTestFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageTestFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageTestFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageunplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageunplannedfailoverinput.go new file mode 100644 index 00000000000..e03da157307 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmageunplannedfailoverinput.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 _ UnplannedFailoverProviderSpecificInput = InMageUnplannedFailoverInput{} + +type InMageUnplannedFailoverInput struct { + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointType *RecoveryPointType `json:"recoveryPointType,omitempty"` + + // Fields inherited from UnplannedFailoverProviderSpecificInput +} + +var _ json.Marshaler = InMageUnplannedFailoverInput{} + +func (s InMageUnplannedFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper InMageUnplannedFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageUnplannedFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageUnplannedFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageUnplannedFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagevolumeexclusionoptions.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagevolumeexclusionoptions.go new file mode 100644 index 00000000000..f8a523a289d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inmagevolumeexclusionoptions.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InMageVolumeExclusionOptions struct { + OnlyExcludeIfSingleVolume *string `json:"onlyExcludeIfSingleVolume,omitempty"` + VolumeLabel *string `json:"volumeLabel,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_innerhealtherror.go new file mode 100644 index 00000000000..dc06e717b80 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationprotecteditems + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inputendpoint.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inputendpoint.go new file mode 100644 index 00000000000..a0e3fd45e70 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_inputendpoint.go @@ -0,0 +1,11 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InputEndpoint struct { + EndpointName *string `json:"endpointName,omitempty"` + PrivatePort *int64 `json:"privatePort,omitempty"` + Protocol *string `json:"protocol,omitempty"` + PublicPort *int64 `json:"publicPort,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_ipconfigdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_ipconfigdetails.go new file mode 100644 index 00000000000..74ce87533d6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_ipconfigdetails.go @@ -0,0 +1,22 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPConfigDetails struct { + IPAddressType *string `json:"ipAddressType,omitempty"` + IsPrimary *bool `json:"isPrimary,omitempty"` + IsSeletedForFailover *bool `json:"isSeletedForFailover,omitempty"` + Name *string `json:"name,omitempty"` + RecoveryIPAddressType *string `json:"recoveryIPAddressType,omitempty"` + RecoveryLBBackendAddressPoolIds *[]string `json:"recoveryLBBackendAddressPoolIds,omitempty"` + RecoveryPublicIPAddressId *string `json:"recoveryPublicIPAddressId,omitempty"` + RecoveryStaticIPAddress *string `json:"recoveryStaticIPAddress,omitempty"` + RecoverySubnetName *string `json:"recoverySubnetName,omitempty"` + StaticIPAddress *string `json:"staticIPAddress,omitempty"` + SubnetName *string `json:"subnetName,omitempty"` + TfoLBBackendAddressPoolIds *[]string `json:"tfoLBBackendAddressPoolIds,omitempty"` + TfoPublicIPAddressId *string `json:"tfoPublicIPAddressId,omitempty"` + TfoStaticIPAddress *string `json:"tfoStaticIPAddress,omitempty"` + TfoSubnetName *string `json:"tfoSubnetName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_ipconfiginputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_ipconfiginputdetails.go new file mode 100644 index 00000000000..de0609e9a0d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_ipconfiginputdetails.go @@ -0,0 +1,18 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPConfigInputDetails struct { + IPConfigName *string `json:"ipConfigName,omitempty"` + IsPrimary *bool `json:"isPrimary,omitempty"` + IsSeletedForFailover *bool `json:"isSeletedForFailover,omitempty"` + RecoveryLBBackendAddressPoolIds *[]string `json:"recoveryLBBackendAddressPoolIds,omitempty"` + RecoveryPublicIPAddressId *string `json:"recoveryPublicIPAddressId,omitempty"` + RecoveryStaticIPAddress *string `json:"recoveryStaticIPAddress,omitempty"` + RecoverySubnetName *string `json:"recoverySubnetName,omitempty"` + TfoLBBackendAddressPoolIds *[]string `json:"tfoLBBackendAddressPoolIds,omitempty"` + TfoPublicIPAddressId *string `json:"tfoPublicIPAddressId,omitempty"` + TfoStaticIPAddress *string `json:"tfoStaticIPAddress,omitempty"` + TfoSubnetName *string `json:"tfoSubnetName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_keyencryptionkeyinfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_keyencryptionkeyinfo.go new file mode 100644 index 00000000000..b0d163a1195 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_keyencryptionkeyinfo.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyEncryptionKeyInfo struct { + KeyIdentifier *string `json:"keyIdentifier,omitempty"` + KeyVaultResourceArmId *string `json:"keyVaultResourceArmId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_osdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_osdetails.go new file mode 100644 index 00000000000..ffe22cbffdc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_osdetails.go @@ -0,0 +1,13 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSDetails struct { + OSMajorVersion *string `json:"oSMajorVersion,omitempty"` + OSMinorVersion *string `json:"oSMinorVersion,omitempty"` + OSVersion *string `json:"oSVersion,omitempty"` + OsEdition *string `json:"osEdition,omitempty"` + OsType *string `json:"osType,omitempty"` + ProductType *string `json:"productType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_osdiskdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_osdiskdetails.go new file mode 100644 index 00000000000..9686e06d452 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_osdiskdetails.go @@ -0,0 +1,10 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSDiskDetails struct { + OsType *string `json:"osType,omitempty"` + OsVhdId *string `json:"osVhdId,omitempty"` + VhdName *string `json:"vhdName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverinput.go new file mode 100644 index 00000000000..ccf7d67c6ad --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PlannedFailoverInput struct { + Properties *PlannedFailoverInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverinputproperties.go new file mode 100644 index 00000000000..4a6bb1dae0a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverinputproperties.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 PlannedFailoverInputProperties struct { + FailoverDirection *string `json:"failoverDirection,omitempty"` + ProviderSpecificDetails PlannedFailoverProviderSpecificFailoverInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &PlannedFailoverInputProperties{} + +func (s *PlannedFailoverInputProperties) UnmarshalJSON(bytes []byte) error { + type alias PlannedFailoverInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into PlannedFailoverInputProperties: %+v", err) + } + + s.FailoverDirection = decoded.FailoverDirection + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PlannedFailoverInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalPlannedFailoverProviderSpecificFailoverInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'PlannedFailoverInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverproviderspecificfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverproviderspecificfailoverinput.go new file mode 100644 index 00000000000..698064832fc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_plannedfailoverproviderspecificfailoverinput.go @@ -0,0 +1,64 @@ +package replicationprotecteditems + +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 PlannedFailoverProviderSpecificFailoverInput interface { +} + +func unmarshalPlannedFailoverProviderSpecificFailoverInputImplementation(input []byte) (PlannedFailoverProviderSpecificFailoverInput, 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 PlannedFailoverProviderSpecificFailoverInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzureFailback") { + var out HyperVReplicaAzureFailbackProviderInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureFailbackProviderInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzurePlannedFailoverProviderInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzurePlannedFailoverProviderInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcmFailback") { + var out InMageRcmFailbackPlannedFailoverProviderInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFailbackPlannedFailoverProviderInput: %+v", err) + } + return out, nil + } + + type RawPlannedFailoverProviderSpecificFailoverInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawPlannedFailoverProviderSpecificFailoverInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksinput.go new file mode 100644 index 00000000000..bfb58b0e932 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RemoveDisksInput struct { + Properties *RemoveDisksInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksinputproperties.go new file mode 100644 index 00000000000..eb805049101 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksinputproperties.go @@ -0,0 +1,32 @@ +package replicationprotecteditems + +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 RemoveDisksInputProperties struct { + ProviderSpecificDetails RemoveDisksProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &RemoveDisksInputProperties{} + +func (s *RemoveDisksInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RemoveDisksInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalRemoveDisksProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'RemoveDisksInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksproviderspecificinput.go new file mode 100644 index 00000000000..ca1162fbc2f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_removedisksproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationprotecteditems + +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 RemoveDisksProviderSpecificInput interface { +} + +func unmarshalRemoveDisksProviderSpecificInputImplementation(input []byte) (RemoveDisksProviderSpecificInput, 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 RemoveDisksProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2ARemoveDisksInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ARemoveDisksInput: %+v", err) + } + return out, nil + } + + type RawRemoveDisksProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRemoveDisksProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationprotecteditem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationprotecteditem.go new file mode 100644 index 00000000000..8c86ba791a1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationprotecteditem.go @@ -0,0 +1,12 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectedItem struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ReplicationProtectedItemProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationprotecteditemproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationprotecteditemproperties.go new file mode 100644 index 00000000000..fcf1010f232 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationprotecteditemproperties.go @@ -0,0 +1,123 @@ +package replicationprotecteditems + +import ( + "encoding/json" + "fmt" + "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 ReplicationProtectedItemProperties struct { + ActiveLocation *string `json:"activeLocation,omitempty"` + AllowedOperations *[]string `json:"allowedOperations,omitempty"` + CurrentScenario *CurrentScenarioDetails `json:"currentScenario,omitempty"` + EventCorrelationId *string `json:"eventCorrelationId,omitempty"` + FailoverHealth *string `json:"failoverHealth,omitempty"` + FailoverRecoveryPointId *string `json:"failoverRecoveryPointId,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + LastSuccessfulFailoverTime *string `json:"lastSuccessfulFailoverTime,omitempty"` + LastSuccessfulTestFailoverTime *string `json:"lastSuccessfulTestFailoverTime,omitempty"` + PolicyFriendlyName *string `json:"policyFriendlyName,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PrimaryFabricFriendlyName *string `json:"primaryFabricFriendlyName,omitempty"` + PrimaryFabricProvider *string `json:"primaryFabricProvider,omitempty"` + PrimaryProtectionContainerFriendlyName *string `json:"primaryProtectionContainerFriendlyName,omitempty"` + ProtectableItemId *string `json:"protectableItemId,omitempty"` + ProtectedItemType *string `json:"protectedItemType,omitempty"` + ProtectionState *string `json:"protectionState,omitempty"` + ProtectionStateDescription *string `json:"protectionStateDescription,omitempty"` + ProviderSpecificDetails ReplicationProviderSpecificSettings `json:"providerSpecificDetails"` + RecoveryContainerId *string `json:"recoveryContainerId,omitempty"` + RecoveryFabricFriendlyName *string `json:"recoveryFabricFriendlyName,omitempty"` + RecoveryFabricId *string `json:"recoveryFabricId,omitempty"` + RecoveryProtectionContainerFriendlyName *string `json:"recoveryProtectionContainerFriendlyName,omitempty"` + RecoveryServicesProviderId *string `json:"recoveryServicesProviderId,omitempty"` + ReplicationHealth *string `json:"replicationHealth,omitempty"` + SwitchProviderState *string `json:"switchProviderState,omitempty"` + SwitchProviderStateDescription *string `json:"switchProviderStateDescription,omitempty"` + TestFailoverState *string `json:"testFailoverState,omitempty"` + TestFailoverStateDescription *string `json:"testFailoverStateDescription,omitempty"` +} + +func (o *ReplicationProtectedItemProperties) GetLastSuccessfulFailoverTimeAsTime() (*time.Time, error) { + if o.LastSuccessfulFailoverTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSuccessfulFailoverTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReplicationProtectedItemProperties) SetLastSuccessfulFailoverTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSuccessfulFailoverTime = &formatted +} + +func (o *ReplicationProtectedItemProperties) GetLastSuccessfulTestFailoverTimeAsTime() (*time.Time, error) { + if o.LastSuccessfulTestFailoverTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSuccessfulTestFailoverTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReplicationProtectedItemProperties) SetLastSuccessfulTestFailoverTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSuccessfulTestFailoverTime = &formatted +} + +var _ json.Unmarshaler = &ReplicationProtectedItemProperties{} + +func (s *ReplicationProtectedItemProperties) UnmarshalJSON(bytes []byte) error { + type alias ReplicationProtectedItemProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ReplicationProtectedItemProperties: %+v", err) + } + + s.ActiveLocation = decoded.ActiveLocation + s.AllowedOperations = decoded.AllowedOperations + s.CurrentScenario = decoded.CurrentScenario + s.EventCorrelationId = decoded.EventCorrelationId + s.FailoverHealth = decoded.FailoverHealth + s.FailoverRecoveryPointId = decoded.FailoverRecoveryPointId + s.FriendlyName = decoded.FriendlyName + s.HealthErrors = decoded.HealthErrors + s.LastSuccessfulFailoverTime = decoded.LastSuccessfulFailoverTime + s.LastSuccessfulTestFailoverTime = decoded.LastSuccessfulTestFailoverTime + s.PolicyFriendlyName = decoded.PolicyFriendlyName + s.PolicyId = decoded.PolicyId + s.PrimaryFabricFriendlyName = decoded.PrimaryFabricFriendlyName + s.PrimaryFabricProvider = decoded.PrimaryFabricProvider + s.PrimaryProtectionContainerFriendlyName = decoded.PrimaryProtectionContainerFriendlyName + s.ProtectableItemId = decoded.ProtectableItemId + s.ProtectedItemType = decoded.ProtectedItemType + s.ProtectionState = decoded.ProtectionState + s.ProtectionStateDescription = decoded.ProtectionStateDescription + s.RecoveryContainerId = decoded.RecoveryContainerId + s.RecoveryFabricFriendlyName = decoded.RecoveryFabricFriendlyName + s.RecoveryFabricId = decoded.RecoveryFabricId + s.RecoveryProtectionContainerFriendlyName = decoded.RecoveryProtectionContainerFriendlyName + s.RecoveryServicesProviderId = decoded.RecoveryServicesProviderId + s.ReplicationHealth = decoded.ReplicationHealth + s.SwitchProviderState = decoded.SwitchProviderState + s.SwitchProviderStateDescription = decoded.SwitchProviderStateDescription + s.TestFailoverState = decoded.TestFailoverState + s.TestFailoverStateDescription = decoded.TestFailoverStateDescription + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ReplicationProtectedItemProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalReplicationProviderSpecificSettingsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ReplicationProtectedItemProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationproviderspecificsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationproviderspecificsettings.go new file mode 100644 index 00000000000..d77ec28b132 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_replicationproviderspecificsettings.go @@ -0,0 +1,120 @@ +package replicationprotecteditems + +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 ReplicationProviderSpecificSettings interface { +} + +func unmarshalReplicationProviderSpecificSettingsImplementation(input []byte) (ReplicationProviderSpecificSettings, 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 ReplicationProviderSpecificSettings into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2ACrossClusterMigration") { + var out A2ACrossClusterMigrationReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ACrossClusterMigrationReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaBaseReplicationDetails") { + var out HyperVReplicaBaseReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaBaseReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplica2012R2") { + var out HyperVReplicaBlueReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaBlueReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplica2012") { + var out HyperVReplicaReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2ReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2ReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcmFailback") { + var out InMageRcmFailbackReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFailbackReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmReplicationDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMageReplicationDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageReplicationDetails: %+v", err) + } + return out, nil + } + + type RawReplicationProviderSpecificSettingsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawReplicationProviderSpecificSettingsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealtherror.go new file mode 100644 index 00000000000..0fc7181b7ab --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealtherror.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolveHealthError struct { + HealthErrorId *string `json:"healthErrorId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealthinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealthinput.go new file mode 100644 index 00000000000..57ce7884f4b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealthinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolveHealthInput struct { + Properties *ResolveHealthInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealthinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealthinputproperties.go new file mode 100644 index 00000000000..735fbf2ee53 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_resolvehealthinputproperties.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolveHealthInputProperties struct { + HealthErrors *[]ResolveHealthError `json:"healthErrors,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationinput.go new file mode 100644 index 00000000000..dcd65ebb176 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReverseReplicationInput struct { + Properties *ReverseReplicationInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationinputproperties.go new file mode 100644 index 00000000000..9d4d4c1da7f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationinputproperties.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 ReverseReplicationInputProperties struct { + FailoverDirection *string `json:"failoverDirection,omitempty"` + ProviderSpecificDetails ReverseReplicationProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &ReverseReplicationInputProperties{} + +func (s *ReverseReplicationInputProperties) UnmarshalJSON(bytes []byte) error { + type alias ReverseReplicationInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ReverseReplicationInputProperties: %+v", err) + } + + s.FailoverDirection = decoded.FailoverDirection + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ReverseReplicationInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalReverseReplicationProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ReverseReplicationInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationproviderspecificinput.go new file mode 100644 index 00000000000..102244fac96 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_reversereplicationproviderspecificinput.go @@ -0,0 +1,88 @@ +package replicationprotecteditems + +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 ReverseReplicationProviderSpecificInput interface { +} + +func unmarshalReverseReplicationProviderSpecificInputImplementation(input []byte) (ReverseReplicationProviderSpecificInput, 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 ReverseReplicationProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AReprotectInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AReprotectInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureReprotectInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureReprotectInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2ReprotectInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2ReprotectInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcmFailback") { + var out InMageRcmFailbackReprotectInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmFailbackReprotectInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmReprotectInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmReprotectInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMageReprotectInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageReprotectInput: %+v", err) + } + return out, nil + } + + type RawReverseReplicationProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawReverseReplicationProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderinput.go new file mode 100644 index 00000000000..701b7dcfb6f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SwitchProviderInput struct { + Properties *SwitchProviderInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderinputproperties.go new file mode 100644 index 00000000000..86770b49b74 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderinputproperties.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 SwitchProviderInputProperties struct { + ProviderSpecificDetails SwitchProviderProviderSpecificInput `json:"providerSpecificDetails"` + TargetInstanceType *string `json:"targetInstanceType,omitempty"` +} + +var _ json.Unmarshaler = &SwitchProviderInputProperties{} + +func (s *SwitchProviderInputProperties) UnmarshalJSON(bytes []byte) error { + type alias SwitchProviderInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SwitchProviderInputProperties: %+v", err) + } + + s.TargetInstanceType = decoded.TargetInstanceType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SwitchProviderInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalSwitchProviderProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'SwitchProviderInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderproviderspecificinput.go new file mode 100644 index 00000000000..8d4bd2cfb15 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_switchproviderproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationprotecteditems + +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 SwitchProviderProviderSpecificInput interface { +} + +func unmarshalSwitchProviderProviderSpecificInputImplementation(input []byte) (SwitchProviderProviderSpecificInput, 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 SwitchProviderProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2SwitchProviderProviderInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2SwitchProviderProviderInput: %+v", err) + } + return out, nil + } + + type RawSwitchProviderProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawSwitchProviderProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailovercleanupinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailovercleanupinput.go new file mode 100644 index 00000000000..29c6eb3256b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailovercleanupinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestFailoverCleanupInput struct { + Properties TestFailoverCleanupInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailovercleanupinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailovercleanupinputproperties.go new file mode 100644 index 00000000000..9699a278467 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailovercleanupinputproperties.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestFailoverCleanupInputProperties struct { + Comments *string `json:"comments,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverinput.go new file mode 100644 index 00000000000..88eb28a5898 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestFailoverInput struct { + Properties TestFailoverInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverinputproperties.go new file mode 100644 index 00000000000..098e800430b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverinputproperties.go @@ -0,0 +1,44 @@ +package replicationprotecteditems + +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 TestFailoverInputProperties struct { + FailoverDirection *string `json:"failoverDirection,omitempty"` + NetworkId *string `json:"networkId,omitempty"` + NetworkType *string `json:"networkType,omitempty"` + ProviderSpecificDetails TestFailoverProviderSpecificInput `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &TestFailoverInputProperties{} + +func (s *TestFailoverInputProperties) UnmarshalJSON(bytes []byte) error { + type alias TestFailoverInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into TestFailoverInputProperties: %+v", err) + } + + s.FailoverDirection = decoded.FailoverDirection + s.NetworkId = decoded.NetworkId + s.NetworkType = decoded.NetworkType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TestFailoverInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalTestFailoverProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'TestFailoverInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverproviderspecificinput.go new file mode 100644 index 00000000000..363ba814fee --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_testfailoverproviderspecificinput.go @@ -0,0 +1,80 @@ +package replicationprotecteditems + +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 TestFailoverProviderSpecificInput interface { +} + +func unmarshalTestFailoverProviderSpecificInputImplementation(input []byte) (TestFailoverProviderSpecificInput, 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 TestFailoverProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2ATestFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ATestFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureTestFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureTestFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2TestFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2TestFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmTestFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmTestFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMageTestFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageTestFailoverInput: %+v", err) + } + return out, nil + } + + type RawTestFailoverProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawTestFailoverProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverinput.go new file mode 100644 index 00000000000..12ae4f94f48 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverinput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnplannedFailoverInput struct { + Properties UnplannedFailoverInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverinputproperties.go new file mode 100644 index 00000000000..b998698389d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverinputproperties.go @@ -0,0 +1,42 @@ +package replicationprotecteditems + +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 UnplannedFailoverInputProperties struct { + FailoverDirection *string `json:"failoverDirection,omitempty"` + ProviderSpecificDetails UnplannedFailoverProviderSpecificInput `json:"providerSpecificDetails"` + SourceSiteOperations *string `json:"sourceSiteOperations,omitempty"` +} + +var _ json.Unmarshaler = &UnplannedFailoverInputProperties{} + +func (s *UnplannedFailoverInputProperties) UnmarshalJSON(bytes []byte) error { + type alias UnplannedFailoverInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into UnplannedFailoverInputProperties: %+v", err) + } + + s.FailoverDirection = decoded.FailoverDirection + s.SourceSiteOperations = decoded.SourceSiteOperations + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling UnplannedFailoverInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalUnplannedFailoverProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'UnplannedFailoverInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverproviderspecificinput.go new file mode 100644 index 00000000000..24adfb5efc2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_unplannedfailoverproviderspecificinput.go @@ -0,0 +1,80 @@ +package replicationprotecteditems + +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 UnplannedFailoverProviderSpecificInput interface { +} + +func unmarshalUnplannedFailoverProviderSpecificInputImplementation(input []byte) (UnplannedFailoverProviderSpecificInput, 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 UnplannedFailoverProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AUnplannedFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AUnplannedFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureUnplannedFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureUnplannedFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2UnplannedFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2UnplannedFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmUnplannedFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmUnplannedFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out InMageUnplannedFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageUnplannedFailoverInput: %+v", err) + } + return out, nil + } + + type RawUnplannedFailoverProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawUnplannedFailoverProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotectediteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotectediteminput.go new file mode 100644 index 00000000000..8bb8dbd243c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotectediteminput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateApplianceForReplicationProtectedItemInput struct { + Properties UpdateApplianceForReplicationProtectedItemInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotectediteminputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotectediteminputproperties.go new file mode 100644 index 00000000000..a1073c0228c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotectediteminputproperties.go @@ -0,0 +1,40 @@ +package replicationprotecteditems + +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 UpdateApplianceForReplicationProtectedItemInputProperties struct { + ProviderSpecificDetails UpdateApplianceForReplicationProtectedItemProviderSpecificInput `json:"providerSpecificDetails"` + TargetApplianceId string `json:"targetApplianceId"` +} + +var _ json.Unmarshaler = &UpdateApplianceForReplicationProtectedItemInputProperties{} + +func (s *UpdateApplianceForReplicationProtectedItemInputProperties) UnmarshalJSON(bytes []byte) error { + type alias UpdateApplianceForReplicationProtectedItemInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into UpdateApplianceForReplicationProtectedItemInputProperties: %+v", err) + } + + s.TargetApplianceId = decoded.TargetApplianceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling UpdateApplianceForReplicationProtectedItemInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalUpdateApplianceForReplicationProtectedItemProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'UpdateApplianceForReplicationProtectedItemInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotecteditemproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotecteditemproviderspecificinput.go new file mode 100644 index 00000000000..3095b5c9887 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updateapplianceforreplicationprotecteditemproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationprotecteditems + +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 UpdateApplianceForReplicationProtectedItemProviderSpecificInput interface { +} + +func unmarshalUpdateApplianceForReplicationProtectedItemProviderSpecificInputImplementation(input []byte) (UpdateApplianceForReplicationProtectedItemProviderSpecificInput, 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 UpdateApplianceForReplicationProtectedItemProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmUpdateApplianceForReplicationProtectedItemInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmUpdateApplianceForReplicationProtectedItemInput: %+v", err) + } + return out, nil + } + + type RawUpdateApplianceForReplicationProtectedItemProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawUpdateApplianceForReplicationProtectedItemProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatediskinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatediskinput.go new file mode 100644 index 00000000000..89c2747dd8b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatediskinput.go @@ -0,0 +1,9 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateDiskInput struct { + DiskId string `json:"diskId"` + TargetDiskName *string `json:"targetDiskName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatemobilityservicerequest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatemobilityservicerequest.go new file mode 100644 index 00000000000..88df4c561c1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatemobilityservicerequest.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateMobilityServiceRequest struct { + Properties *UpdateMobilityServiceRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatemobilityservicerequestproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatemobilityservicerequestproperties.go new file mode 100644 index 00000000000..bc5afdc6871 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatemobilityservicerequestproperties.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateMobilityServiceRequestProperties struct { + RunAsAccountId *string `json:"runAsAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotectediteminput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotectediteminput.go new file mode 100644 index 00000000000..6a33ddab87b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotectediteminput.go @@ -0,0 +1,8 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateReplicationProtectedItemInput struct { + Properties *UpdateReplicationProtectedItemInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotectediteminputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotectediteminputproperties.go new file mode 100644 index 00000000000..ce7313ff7b9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotectediteminputproperties.go @@ -0,0 +1,56 @@ +package replicationprotecteditems + +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 UpdateReplicationProtectedItemInputProperties struct { + EnableRdpOnTargetOption *string `json:"enableRdpOnTargetOption,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + ProviderSpecificDetails UpdateReplicationProtectedItemProviderInput `json:"providerSpecificDetails"` + RecoveryAvailabilitySetId *string `json:"recoveryAvailabilitySetId,omitempty"` + RecoveryAzureVMName *string `json:"recoveryAzureVMName,omitempty"` + RecoveryAzureVMSize *string `json:"recoveryAzureVMSize,omitempty"` + SelectedRecoveryAzureNetworkId *string `json:"selectedRecoveryAzureNetworkId,omitempty"` + SelectedSourceNicId *string `json:"selectedSourceNicId,omitempty"` + SelectedTfoAzureNetworkId *string `json:"selectedTfoAzureNetworkId,omitempty"` + VMNics *[]VMNicInputDetails `json:"vmNics,omitempty"` +} + +var _ json.Unmarshaler = &UpdateReplicationProtectedItemInputProperties{} + +func (s *UpdateReplicationProtectedItemInputProperties) UnmarshalJSON(bytes []byte) error { + type alias UpdateReplicationProtectedItemInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into UpdateReplicationProtectedItemInputProperties: %+v", err) + } + + s.EnableRdpOnTargetOption = decoded.EnableRdpOnTargetOption + s.LicenseType = decoded.LicenseType + s.RecoveryAvailabilitySetId = decoded.RecoveryAvailabilitySetId + s.RecoveryAzureVMName = decoded.RecoveryAzureVMName + s.RecoveryAzureVMSize = decoded.RecoveryAzureVMSize + s.SelectedRecoveryAzureNetworkId = decoded.SelectedRecoveryAzureNetworkId + s.SelectedSourceNicId = decoded.SelectedSourceNicId + s.SelectedTfoAzureNetworkId = decoded.SelectedTfoAzureNetworkId + s.VMNics = decoded.VMNics + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling UpdateReplicationProtectedItemInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalUpdateReplicationProtectedItemProviderInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'UpdateReplicationProtectedItemInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotecteditemproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotecteditemproviderinput.go new file mode 100644 index 00000000000..ff45951720d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_updatereplicationprotecteditemproviderinput.go @@ -0,0 +1,72 @@ +package replicationprotecteditems + +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 UpdateReplicationProtectedItemProviderInput interface { +} + +func unmarshalUpdateReplicationProtectedItemProviderInputImplementation(input []byte) (UpdateReplicationProtectedItemProviderInput, 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 UpdateReplicationProtectedItemProviderInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AUpdateReplicationProtectedItemInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AUpdateReplicationProtectedItemInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out HyperVReplicaAzureUpdateReplicationProtectedItemInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HyperVReplicaAzureUpdateReplicationProtectedItemInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out InMageAzureV2UpdateReplicationProtectedItemInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageAzureV2UpdateReplicationProtectedItemInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmUpdateReplicationProtectedItemInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmUpdateReplicationProtectedItemInput: %+v", err) + } + return out, nil + } + + type RawUpdateReplicationProtectedItemProviderInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawUpdateReplicationProtectedItemProviderInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_vmnicdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_vmnicdetails.go new file mode 100644 index 00000000000..aa704f28341 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_vmnicdetails.go @@ -0,0 +1,26 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMNicDetails struct { + EnableAcceleratedNetworkingOnRecovery *bool `json:"enableAcceleratedNetworkingOnRecovery,omitempty"` + EnableAcceleratedNetworkingOnTfo *bool `json:"enableAcceleratedNetworkingOnTfo,omitempty"` + IPConfigs *[]IPConfigDetails `json:"ipConfigs,omitempty"` + NicId *string `json:"nicId,omitempty"` + RecoveryNetworkSecurityGroupId *string `json:"recoveryNetworkSecurityGroupId,omitempty"` + RecoveryNicName *string `json:"recoveryNicName,omitempty"` + RecoveryNicResourceGroupName *string `json:"recoveryNicResourceGroupName,omitempty"` + RecoveryVMNetworkId *string `json:"recoveryVMNetworkId,omitempty"` + ReplicaNicId *string `json:"replicaNicId,omitempty"` + ReuseExistingNic *bool `json:"reuseExistingNic,omitempty"` + SelectionType *string `json:"selectionType,omitempty"` + SourceNicArmId *string `json:"sourceNicArmId,omitempty"` + TargetNicName *string `json:"targetNicName,omitempty"` + TfoNetworkSecurityGroupId *string `json:"tfoNetworkSecurityGroupId,omitempty"` + TfoRecoveryNicName *string `json:"tfoRecoveryNicName,omitempty"` + TfoRecoveryNicResourceGroupName *string `json:"tfoRecoveryNicResourceGroupName,omitempty"` + TfoReuseExistingNic *bool `json:"tfoReuseExistingNic,omitempty"` + TfoVMNetworkId *string `json:"tfoVMNetworkId,omitempty"` + VMNetworkName *string `json:"vMNetworkName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_vmnicinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_vmnicinputdetails.go new file mode 100644 index 00000000000..7c18c51a759 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/model_vmnicinputdetails.go @@ -0,0 +1,21 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VMNicInputDetails struct { + EnableAcceleratedNetworkingOnRecovery *bool `json:"enableAcceleratedNetworkingOnRecovery,omitempty"` + EnableAcceleratedNetworkingOnTfo *bool `json:"enableAcceleratedNetworkingOnTfo,omitempty"` + IPConfigs *[]IPConfigInputDetails `json:"ipConfigs,omitempty"` + NicId *string `json:"nicId,omitempty"` + RecoveryNetworkSecurityGroupId *string `json:"recoveryNetworkSecurityGroupId,omitempty"` + RecoveryNicName *string `json:"recoveryNicName,omitempty"` + RecoveryNicResourceGroupName *string `json:"recoveryNicResourceGroupName,omitempty"` + ReuseExistingNic *bool `json:"reuseExistingNic,omitempty"` + SelectionType *string `json:"selectionType,omitempty"` + TargetNicName *string `json:"targetNicName,omitempty"` + TfoNetworkSecurityGroupId *string `json:"tfoNetworkSecurityGroupId,omitempty"` + TfoNicName *string `json:"tfoNicName,omitempty"` + TfoNicResourceGroupName *string `json:"tfoNicResourceGroupName,omitempty"` + TfoReuseExistingNic *bool `json:"tfoReuseExistingNic,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/predicates.go new file mode 100644 index 00000000000..d767b25ccdc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/predicates.go @@ -0,0 +1,32 @@ +package replicationprotecteditems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectedItemOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ReplicationProtectedItemOperationPredicate) Matches(input ReplicationProtectedItem) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/version.go new file mode 100644 index 00000000000..29481605930 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotecteditems/version.go @@ -0,0 +1,12 @@ +package replicationprotecteditems + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationprotecteditems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/README.md new file mode 100644 index 00000000000..5ff98528d4a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/README.md @@ -0,0 +1,133 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings` Documentation + +The `replicationprotectioncontainermappings` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings" +``` + + +### Client Initialization + +```go +client := replicationprotectioncontainermappings.NewReplicationProtectionContainerMappingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationProtectionContainerMappingsClient.Create` + +```go +ctx := context.TODO() +id := replicationprotectioncontainermappings.NewReplicationProtectionContainerMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectionContainerMappingValue") + +payload := replicationprotectioncontainermappings.CreateProtectionContainerMappingInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectionContainerMappingsClient.Delete` + +```go +ctx := context.TODO() +id := replicationprotectioncontainermappings.NewReplicationProtectionContainerMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectionContainerMappingValue") + +payload := replicationprotectioncontainermappings.RemoveProtectionContainerMappingInput{ + // ... +} + + +if err := client.DeleteThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectionContainerMappingsClient.Get` + +```go +ctx := context.TODO() +id := replicationprotectioncontainermappings.NewReplicationProtectionContainerMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectionContainerMappingValue") + +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: `ReplicationProtectionContainerMappingsClient.List` + +```go +ctx := context.TODO() +id := replicationprotectioncontainermappings.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationProtectionContainerMappingsClient.ListByReplicationProtectionContainers` + +```go +ctx := context.TODO() +id := replicationprotectioncontainermappings.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +// alternatively `client.ListByReplicationProtectionContainers(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationProtectionContainersComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationProtectionContainerMappingsClient.Purge` + +```go +ctx := context.TODO() +id := replicationprotectioncontainermappings.NewReplicationProtectionContainerMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectionContainerMappingValue") + +if err := client.PurgeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectionContainerMappingsClient.Update` + +```go +ctx := context.TODO() +id := replicationprotectioncontainermappings.NewReplicationProtectionContainerMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectionContainerMappingValue") + +payload := replicationprotectioncontainermappings.UpdateProtectionContainerMappingInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/client.go new file mode 100644 index 00000000000..68e64166c0b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/client.go @@ -0,0 +1,18 @@ +package replicationprotectioncontainermappings + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectionContainerMappingsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationProtectionContainerMappingsClientWithBaseURI(endpoint string) ReplicationProtectionContainerMappingsClient { + return ReplicationProtectionContainerMappingsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/constants.go new file mode 100644 index 00000000000..dbdbabf2c6d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/constants.go @@ -0,0 +1,90 @@ +package replicationprotectioncontainermappings + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentAutoUpdateStatus string + +const ( + AgentAutoUpdateStatusDisabled AgentAutoUpdateStatus = "Disabled" + AgentAutoUpdateStatusEnabled AgentAutoUpdateStatus = "Enabled" +) + +func PossibleValuesForAgentAutoUpdateStatus() []string { + return []string{ + string(AgentAutoUpdateStatusDisabled), + string(AgentAutoUpdateStatusEnabled), + } +} + +func parseAgentAutoUpdateStatus(input string) (*AgentAutoUpdateStatus, error) { + vals := map[string]AgentAutoUpdateStatus{ + "disabled": AgentAutoUpdateStatusDisabled, + "enabled": AgentAutoUpdateStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AgentAutoUpdateStatus(input) + return &out, nil +} + +type AutomationAccountAuthenticationType string + +const ( + AutomationAccountAuthenticationTypeRunAsAccount AutomationAccountAuthenticationType = "RunAsAccount" + AutomationAccountAuthenticationTypeSystemAssignedIdentity AutomationAccountAuthenticationType = "SystemAssignedIdentity" +) + +func PossibleValuesForAutomationAccountAuthenticationType() []string { + return []string{ + string(AutomationAccountAuthenticationTypeRunAsAccount), + string(AutomationAccountAuthenticationTypeSystemAssignedIdentity), + } +} + +func parseAutomationAccountAuthenticationType(input string) (*AutomationAccountAuthenticationType, error) { + vals := map[string]AutomationAccountAuthenticationType{ + "runasaccount": AutomationAccountAuthenticationTypeRunAsAccount, + "systemassignedidentity": AutomationAccountAuthenticationTypeSystemAssignedIdentity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationAccountAuthenticationType(input) + return &out, nil +} + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainer.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainer.go new file mode 100644 index 00000000000..9f349e9f3f7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainer.go @@ -0,0 +1,153 @@ +package replicationprotectioncontainermappings + +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 = ReplicationProtectionContainerId{} + +// ReplicationProtectionContainerId is a struct representing the Resource ID for a Replication Protection Container +type ReplicationProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string +} + +// NewReplicationProtectionContainerID returns a new ReplicationProtectionContainerId struct +func NewReplicationProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string) ReplicationProtectionContainerId { + return ReplicationProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + } +} + +// ParseReplicationProtectionContainerID parses 'input' into a ReplicationProtectionContainerId +func ParseReplicationProtectionContainerID(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectionContainerIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionContainerIDInsensitively(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectionContainerID checks that 'input' can be parsed as a Replication Protection Container ID +func ValidateReplicationProtectionContainerID(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 := ParseReplicationProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Container ID +func (id ReplicationProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container ID +func (id ReplicationProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + } +} + +// String returns a human-readable description of this Replication Protection Container ID +func (id ReplicationProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + } + return fmt.Sprintf("Replication Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainer_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainer_test.go new file mode 100644 index 00000000000..429bd646a88 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainer_test.go @@ -0,0 +1,372 @@ +package replicationprotectioncontainermappings + +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 = ReplicationProtectionContainerId{} + +func TestNewReplicationProtectionContainerID(t *testing.T) { + id := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } +} + +func TestFormatReplicationProtectionContainerID(t *testing.T) { + actual := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectionContainerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestParseReplicationProtectionContainerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestSegmentsForReplicationProtectionContainerId(t *testing.T) { + segments := ReplicationProtectionContainerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectionContainerId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainermapping.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainermapping.go new file mode 100644 index 00000000000..12a2716ff0f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainermapping.go @@ -0,0 +1,166 @@ +package replicationprotectioncontainermappings + +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 = ReplicationProtectionContainerMappingId{} + +// ReplicationProtectionContainerMappingId is a struct representing the Resource ID for a Replication Protection Container Mapping +type ReplicationProtectionContainerMappingId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationProtectionContainerMappingName string +} + +// NewReplicationProtectionContainerMappingID returns a new ReplicationProtectionContainerMappingId struct +func NewReplicationProtectionContainerMappingID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectionContainerMappingName string) ReplicationProtectionContainerMappingId { + return ReplicationProtectionContainerMappingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationProtectionContainerMappingName: replicationProtectionContainerMappingName, + } +} + +// ParseReplicationProtectionContainerMappingID parses 'input' into a ReplicationProtectionContainerMappingId +func ParseReplicationProtectionContainerMappingID(input string) (*ReplicationProtectionContainerMappingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerMappingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerMappingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerMappingName, ok = parsed.Parsed["replicationProtectionContainerMappingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerMappingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectionContainerMappingIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerMappingId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionContainerMappingIDInsensitively(input string) (*ReplicationProtectionContainerMappingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerMappingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerMappingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerMappingName, ok = parsed.Parsed["replicationProtectionContainerMappingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerMappingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectionContainerMappingID checks that 'input' can be parsed as a Replication Protection Container Mapping ID +func ValidateReplicationProtectionContainerMappingID(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 := ParseReplicationProtectionContainerMappingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Container Mapping ID +func (id ReplicationProtectionContainerMappingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectionContainerMappings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectionContainerMappingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container Mapping ID +func (id ReplicationProtectionContainerMappingId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationProtectionContainerMappings", "replicationProtectionContainerMappings", "replicationProtectionContainerMappings"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerMappingName", "replicationProtectionContainerMappingValue"), + } +} + +// String returns a human-readable description of this Replication Protection Container Mapping ID +func (id ReplicationProtectionContainerMappingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Protection Container Mapping Name: %q", id.ReplicationProtectionContainerMappingName), + } + return fmt.Sprintf("Replication Protection Container Mapping (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainermapping_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainermapping_test.go new file mode 100644 index 00000000000..9af958780d4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_replicationprotectioncontainermapping_test.go @@ -0,0 +1,417 @@ +package replicationprotectioncontainermappings + +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 = ReplicationProtectionContainerMappingId{} + +func TestNewReplicationProtectionContainerMappingID(t *testing.T) { + id := NewReplicationProtectionContainerMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectionContainerMappingValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationProtectionContainerMappingName != "replicationProtectionContainerMappingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerMappingName'", id.ReplicationProtectionContainerMappingName, "replicationProtectionContainerMappingValue") + } +} + +func TestFormatReplicationProtectionContainerMappingID(t *testing.T) { + actual := NewReplicationProtectionContainerMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectionContainerMappingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectionContainerMappings/replicationProtectionContainerMappingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectionContainerMappingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerMappingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectionContainerMappings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectionContainerMappings/replicationProtectionContainerMappingValue", + Expected: &ReplicationProtectionContainerMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectionContainerMappingName: "replicationProtectionContainerMappingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectionContainerMappings/replicationProtectionContainerMappingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerMappingID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectionContainerMappingName != v.Expected.ReplicationProtectionContainerMappingName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerMappingName", v.Expected.ReplicationProtectionContainerMappingName, actual.ReplicationProtectionContainerMappingName) + } + + } +} + +func TestParseReplicationProtectionContainerMappingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerMappingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectionContainerMappings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRmApPiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectionContainerMappings/replicationProtectionContainerMappingValue", + Expected: &ReplicationProtectionContainerMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectionContainerMappingName: "replicationProtectionContainerMappingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectionContainerMappings/replicationProtectionContainerMappingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRmApPiNgS/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRmApPiNgVaLuE", + Expected: &ReplicationProtectionContainerMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationProtectionContainerMappingName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRmApPiNgVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRmApPiNgS/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRmApPiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerMappingIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectionContainerMappingName != v.Expected.ReplicationProtectionContainerMappingName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerMappingName", v.Expected.ReplicationProtectionContainerMappingName, actual.ReplicationProtectionContainerMappingName) + } + + } +} + +func TestSegmentsForReplicationProtectionContainerMappingId(t *testing.T) { + segments := ReplicationProtectionContainerMappingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectionContainerMappingId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_vault.go new file mode 100644 index 00000000000..7e2961a1de4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_vault.go @@ -0,0 +1,127 @@ +package replicationprotectioncontainermappings + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_vault_test.go new file mode 100644 index 00000000000..f794486d04b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationprotectioncontainermappings + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_create_autorest.go new file mode 100644 index 00000000000..4a924ca6a5d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationprotectioncontainermappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationProtectionContainerMappingsClient) Create(ctx context.Context, id ReplicationProtectionContainerMappingId, input CreateProtectionContainerMappingInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationProtectionContainerMappingsClient) CreateThenPoll(ctx context.Context, id ReplicationProtectionContainerMappingId, input CreateProtectionContainerMappingInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationProtectionContainerMappingsClient) preparerForCreate(ctx context.Context, id ReplicationProtectionContainerMappingId, input CreateProtectionContainerMappingInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainerMappingsClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_delete_autorest.go new file mode 100644 index 00000000000..718e777ec94 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_delete_autorest.go @@ -0,0 +1,79 @@ +package replicationprotectioncontainermappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationProtectionContainerMappingsClient) Delete(ctx context.Context, id ReplicationProtectionContainerMappingId, input RemoveProtectionContainerMappingInput) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationProtectionContainerMappingsClient) DeleteThenPoll(ctx context.Context, id ReplicationProtectionContainerMappingId, input RemoveProtectionContainerMappingInput) error { + result, err := c.Delete(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationProtectionContainerMappingsClient) preparerForDelete(ctx context.Context, id ReplicationProtectionContainerMappingId, input RemoveProtectionContainerMappingInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/remove", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainerMappingsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_get_autorest.go new file mode 100644 index 00000000000..e08c1f3da3b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationprotectioncontainermappings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionContainerMapping +} + +// Get ... +func (c ReplicationProtectionContainerMappingsClient) Get(ctx context.Context, id ReplicationProtectionContainerMappingId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationProtectionContainerMappingsClient) preparerForGet(ctx context.Context, id ReplicationProtectionContainerMappingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionContainerMappingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_list_autorest.go new file mode 100644 index 00000000000..a558d13e24f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationprotectioncontainermappings + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionContainerMapping + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ProtectionContainerMapping +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationProtectionContainerMappingsClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationProtectionContainerMappingsClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectionContainerMappings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationProtectionContainerMappingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionContainerMappingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ProtectionContainerMapping `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationProtectionContainerMappingsClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ProtectionContainerMappingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectionContainerMappingsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate ProtectionContainerMappingOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ProtectionContainerMapping, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_listbyreplicationprotectioncontainers_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_listbyreplicationprotectioncontainers_autorest.go new file mode 100644 index 00000000000..3cd3a0febff --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_listbyreplicationprotectioncontainers_autorest.go @@ -0,0 +1,186 @@ +package replicationprotectioncontainermappings + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationProtectionContainersOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionContainerMapping + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectionContainersOperationResponse, error) +} + +type ListByReplicationProtectionContainersCompleteResult struct { + Items []ProtectionContainerMapping +} + +func (r ListByReplicationProtectionContainersOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationProtectionContainersOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationProtectionContainers ... +func (c ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId) (resp ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainers(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationProtectionContainers(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationProtectionContainers prepares the ListByReplicationProtectionContainers request. +func (c ReplicationProtectionContainerMappingsClient) preparerForListByReplicationProtectionContainers(ctx context.Context, id ReplicationProtectionContainerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectionContainerMappings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationProtectionContainersWithNextLink prepares the ListByReplicationProtectionContainers request with the given nextLink token. +func (c ReplicationProtectionContainerMappingsClient) preparerForListByReplicationProtectionContainersWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationProtectionContainers handles the response to the ListByReplicationProtectionContainers request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionContainerMappingsClient) responderForListByReplicationProtectionContainers(resp *http.Response) (result ListByReplicationProtectionContainersOperationResponse, err error) { + type page struct { + Values []ProtectionContainerMapping `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationProtectionContainersOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectionContainersWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationProtectionContainers(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationProtectionContainersComplete retrieves all of the results into a single object +func (c ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, id ReplicationProtectionContainerId) (ListByReplicationProtectionContainersCompleteResult, error) { + return c.ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx, id, ProtectionContainerMappingOperationPredicate{}) +} + +// ListByReplicationProtectionContainersCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainersCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectionContainerId, predicate ProtectionContainerMappingOperationPredicate) (resp ListByReplicationProtectionContainersCompleteResult, err error) { + items := make([]ProtectionContainerMapping, 0) + + page, err := c.ListByReplicationProtectionContainers(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationProtectionContainersCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_purge_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_purge_autorest.go new file mode 100644 index 00000000000..5ccd973c9b2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_purge_autorest.go @@ -0,0 +1,78 @@ +package replicationprotectioncontainermappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurgeOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Purge ... +func (c ReplicationProtectionContainerMappingsClient) Purge(ctx context.Context, id ReplicationProtectionContainerMappingId) (result PurgeOperationResponse, err error) { + req, err := c.preparerForPurge(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Purge", nil, "Failure preparing request") + return + } + + result, err = c.senderForPurge(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Purge", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PurgeThenPoll performs Purge then polls until it's completed +func (c ReplicationProtectionContainerMappingsClient) PurgeThenPoll(ctx context.Context, id ReplicationProtectionContainerMappingId) error { + result, err := c.Purge(ctx, id) + if err != nil { + return fmt.Errorf("performing Purge: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Purge: %+v", err) + } + + return nil +} + +// preparerForPurge prepares the Purge request. +func (c ReplicationProtectionContainerMappingsClient) preparerForPurge(ctx context.Context, id ReplicationProtectionContainerMappingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPurge sends the Purge request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainerMappingsClient) senderForPurge(ctx context.Context, req *http.Request) (future PurgeOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_update_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_update_autorest.go new file mode 100644 index 00000000000..786e443c0f7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/method_update_autorest.go @@ -0,0 +1,79 @@ +package replicationprotectioncontainermappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ReplicationProtectionContainerMappingsClient) Update(ctx context.Context, id ReplicationProtectionContainerMappingId, input UpdateProtectionContainerMappingInput) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainermappings.ReplicationProtectionContainerMappingsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationProtectionContainerMappingsClient) UpdateThenPoll(ctx context.Context, id ReplicationProtectionContainerMappingId, input UpdateProtectionContainerMappingInput) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ReplicationProtectionContainerMappingsClient) preparerForUpdate(ctx context.Context, id ReplicationProtectionContainerMappingId, input UpdateProtectionContainerMappingInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainerMappingsClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2acontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2acontainermappinginput.go new file mode 100644 index 00000000000..f8472547d4f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2acontainermappinginput.go @@ -0,0 +1,43 @@ +package replicationprotectioncontainermappings + +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 _ ReplicationProviderSpecificContainerMappingInput = A2AContainerMappingInput{} + +type A2AContainerMappingInput struct { + AgentAutoUpdateStatus *AgentAutoUpdateStatus `json:"agentAutoUpdateStatus,omitempty"` + AutomationAccountArmId *string `json:"automationAccountArmId,omitempty"` + AutomationAccountAuthenticationType *AutomationAccountAuthenticationType `json:"automationAccountAuthenticationType,omitempty"` + + // Fields inherited from ReplicationProviderSpecificContainerMappingInput +} + +var _ json.Marshaler = A2AContainerMappingInput{} + +func (s A2AContainerMappingInput) MarshalJSON() ([]byte, error) { + type wrapper A2AContainerMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AContainerMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AContainerMappingInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AContainerMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2aprotectioncontainermappingdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2aprotectioncontainermappingdetails.go new file mode 100644 index 00000000000..7d5038331df --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2aprotectioncontainermappingdetails.go @@ -0,0 +1,45 @@ +package replicationprotectioncontainermappings + +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 _ ProtectionContainerMappingProviderSpecificDetails = A2AProtectionContainerMappingDetails{} + +type A2AProtectionContainerMappingDetails struct { + AgentAutoUpdateStatus *AgentAutoUpdateStatus `json:"agentAutoUpdateStatus,omitempty"` + AutomationAccountArmId *string `json:"automationAccountArmId,omitempty"` + AutomationAccountAuthenticationType *AutomationAccountAuthenticationType `json:"automationAccountAuthenticationType,omitempty"` + JobScheduleName *string `json:"jobScheduleName,omitempty"` + ScheduleName *string `json:"scheduleName,omitempty"` + + // Fields inherited from ProtectionContainerMappingProviderSpecificDetails +} + +var _ json.Marshaler = A2AProtectionContainerMappingDetails{} + +func (s A2AProtectionContainerMappingDetails) MarshalJSON() ([]byte, error) { + type wrapper A2AProtectionContainerMappingDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AProtectionContainerMappingDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AProtectionContainerMappingDetails: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AProtectionContainerMappingDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2aupdatecontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2aupdatecontainermappinginput.go new file mode 100644 index 00000000000..e3734760574 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_a2aupdatecontainermappinginput.go @@ -0,0 +1,43 @@ +package replicationprotectioncontainermappings + +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 _ ReplicationProviderSpecificUpdateContainerMappingInput = A2AUpdateContainerMappingInput{} + +type A2AUpdateContainerMappingInput struct { + AgentAutoUpdateStatus *AgentAutoUpdateStatus `json:"agentAutoUpdateStatus,omitempty"` + AutomationAccountArmId *string `json:"automationAccountArmId,omitempty"` + AutomationAccountAuthenticationType *AutomationAccountAuthenticationType `json:"automationAccountAuthenticationType,omitempty"` + + // Fields inherited from ReplicationProviderSpecificUpdateContainerMappingInput +} + +var _ json.Marshaler = A2AUpdateContainerMappingInput{} + +func (s A2AUpdateContainerMappingInput) MarshalJSON() ([]byte, error) { + type wrapper A2AUpdateContainerMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AUpdateContainerMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AUpdateContainerMappingInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AUpdateContainerMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_createprotectioncontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_createprotectioncontainermappinginput.go new file mode 100644 index 00000000000..49e1a32d873 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_createprotectioncontainermappinginput.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainermappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateProtectionContainerMappingInput struct { + Properties *CreateProtectionContainerMappingInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_createprotectioncontainermappinginputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_createprotectioncontainermappinginputproperties.go new file mode 100644 index 00000000000..9c1938b0fed --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_createprotectioncontainermappinginputproperties.go @@ -0,0 +1,42 @@ +package replicationprotectioncontainermappings + +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 CreateProtectionContainerMappingInputProperties struct { + PolicyId *string `json:"policyId,omitempty"` + ProviderSpecificInput ReplicationProviderSpecificContainerMappingInput `json:"providerSpecificInput"` + TargetProtectionContainerId *string `json:"targetProtectionContainerId,omitempty"` +} + +var _ json.Unmarshaler = &CreateProtectionContainerMappingInputProperties{} + +func (s *CreateProtectionContainerMappingInputProperties) UnmarshalJSON(bytes []byte) error { + type alias CreateProtectionContainerMappingInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into CreateProtectionContainerMappingInputProperties: %+v", err) + } + + s.PolicyId = decoded.PolicyId + s.TargetProtectionContainerId = decoded.TargetProtectionContainerId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CreateProtectionContainerMappingInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificInput"]; ok { + impl, err := unmarshalReplicationProviderSpecificContainerMappingInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificInput' for 'CreateProtectionContainerMappingInputProperties': %+v", err) + } + s.ProviderSpecificInput = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_healtherror.go new file mode 100644 index 00000000000..a4c7339daba --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationprotectioncontainermappings + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_inmagercmprotectioncontainermappingdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_inmagercmprotectioncontainermappingdetails.go new file mode 100644 index 00000000000..37be76a4162 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_inmagercmprotectioncontainermappingdetails.go @@ -0,0 +1,41 @@ +package replicationprotectioncontainermappings + +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 _ ProtectionContainerMappingProviderSpecificDetails = InMageRcmProtectionContainerMappingDetails{} + +type InMageRcmProtectionContainerMappingDetails struct { + EnableAgentAutoUpgrade *string `json:"enableAgentAutoUpgrade,omitempty"` + + // Fields inherited from ProtectionContainerMappingProviderSpecificDetails +} + +var _ json.Marshaler = InMageRcmProtectionContainerMappingDetails{} + +func (s InMageRcmProtectionContainerMappingDetails) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmProtectionContainerMappingDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmProtectionContainerMappingDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmProtectionContainerMappingDetails: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmProtectionContainerMappingDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_inmagercmupdatecontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_inmagercmupdatecontainermappinginput.go new file mode 100644 index 00000000000..1ae5b455516 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_inmagercmupdatecontainermappinginput.go @@ -0,0 +1,41 @@ +package replicationprotectioncontainermappings + +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 _ ReplicationProviderSpecificUpdateContainerMappingInput = InMageRcmUpdateContainerMappingInput{} + +type InMageRcmUpdateContainerMappingInput struct { + EnableAgentAutoUpgrade string `json:"enableAgentAutoUpgrade"` + + // Fields inherited from ReplicationProviderSpecificUpdateContainerMappingInput +} + +var _ json.Marshaler = InMageRcmUpdateContainerMappingInput{} + +func (s InMageRcmUpdateContainerMappingInput) MarshalJSON() ([]byte, error) { + type wrapper InMageRcmUpdateContainerMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling InMageRcmUpdateContainerMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling InMageRcmUpdateContainerMappingInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling InMageRcmUpdateContainerMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_innerhealtherror.go new file mode 100644 index 00000000000..20d411ae371 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationprotectioncontainermappings + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermapping.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermapping.go new file mode 100644 index 00000000000..6fcec0153e7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermapping.go @@ -0,0 +1,12 @@ +package replicationprotectioncontainermappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainerMapping struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProtectionContainerMappingProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermappingproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermappingproperties.go new file mode 100644 index 00000000000..2cf9d980640 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermappingproperties.go @@ -0,0 +1,58 @@ +package replicationprotectioncontainermappings + +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 ProtectionContainerMappingProperties struct { + Health *string `json:"health,omitempty"` + HealthErrorDetails *[]HealthError `json:"healthErrorDetails,omitempty"` + PolicyFriendlyName *string `json:"policyFriendlyName,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + ProviderSpecificDetails ProtectionContainerMappingProviderSpecificDetails `json:"providerSpecificDetails"` + SourceFabricFriendlyName *string `json:"sourceFabricFriendlyName,omitempty"` + SourceProtectionContainerFriendlyName *string `json:"sourceProtectionContainerFriendlyName,omitempty"` + State *string `json:"state,omitempty"` + TargetFabricFriendlyName *string `json:"targetFabricFriendlyName,omitempty"` + TargetProtectionContainerFriendlyName *string `json:"targetProtectionContainerFriendlyName,omitempty"` + TargetProtectionContainerId *string `json:"targetProtectionContainerId,omitempty"` +} + +var _ json.Unmarshaler = &ProtectionContainerMappingProperties{} + +func (s *ProtectionContainerMappingProperties) UnmarshalJSON(bytes []byte) error { + type alias ProtectionContainerMappingProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ProtectionContainerMappingProperties: %+v", err) + } + + s.Health = decoded.Health + s.HealthErrorDetails = decoded.HealthErrorDetails + s.PolicyFriendlyName = decoded.PolicyFriendlyName + s.PolicyId = decoded.PolicyId + s.SourceFabricFriendlyName = decoded.SourceFabricFriendlyName + s.SourceProtectionContainerFriendlyName = decoded.SourceProtectionContainerFriendlyName + s.State = decoded.State + s.TargetFabricFriendlyName = decoded.TargetFabricFriendlyName + s.TargetProtectionContainerFriendlyName = decoded.TargetProtectionContainerFriendlyName + s.TargetProtectionContainerId = decoded.TargetProtectionContainerId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ProtectionContainerMappingProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalProtectionContainerMappingProviderSpecificDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ProtectionContainerMappingProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermappingproviderspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermappingproviderspecificdetails.go new file mode 100644 index 00000000000..3d3b16598fb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_protectioncontainermappingproviderspecificdetails.go @@ -0,0 +1,64 @@ +package replicationprotectioncontainermappings + +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 ProtectionContainerMappingProviderSpecificDetails interface { +} + +func unmarshalProtectionContainerMappingProviderSpecificDetailsImplementation(input []byte) (ProtectionContainerMappingProviderSpecificDetails, 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 ProtectionContainerMappingProviderSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AProtectionContainerMappingDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AProtectionContainerMappingDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmProtectionContainerMappingDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmProtectionContainerMappingDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtProtectionContainerMappingDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtProtectionContainerMappingDetails: %+v", err) + } + return out, nil + } + + type RawProtectionContainerMappingProviderSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionContainerMappingProviderSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_removeprotectioncontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_removeprotectioncontainermappinginput.go new file mode 100644 index 00000000000..ac6d64ca0d6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_removeprotectioncontainermappinginput.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainermappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RemoveProtectionContainerMappingInput struct { + Properties *RemoveProtectionContainerMappingInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_removeprotectioncontainermappinginputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_removeprotectioncontainermappinginputproperties.go new file mode 100644 index 00000000000..cda0927d8cd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_removeprotectioncontainermappinginputproperties.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainermappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RemoveProtectionContainerMappingInputProperties struct { + ProviderSpecificInput *ReplicationProviderContainerUnmappingInput `json:"providerSpecificInput,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationprovidercontainerunmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationprovidercontainerunmappinginput.go new file mode 100644 index 00000000000..862047c52a1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationprovidercontainerunmappinginput.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainermappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProviderContainerUnmappingInput struct { + InstanceType *string `json:"instanceType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationproviderspecificcontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationproviderspecificcontainermappinginput.go new file mode 100644 index 00000000000..29e16c2b2d3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationproviderspecificcontainermappinginput.go @@ -0,0 +1,56 @@ +package replicationprotectioncontainermappings + +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 ReplicationProviderSpecificContainerMappingInput interface { +} + +func unmarshalReplicationProviderSpecificContainerMappingInputImplementation(input []byte) (ReplicationProviderSpecificContainerMappingInput, 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 ReplicationProviderSpecificContainerMappingInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AContainerMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AContainerMappingInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtContainerMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtContainerMappingInput: %+v", err) + } + return out, nil + } + + type RawReplicationProviderSpecificContainerMappingInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawReplicationProviderSpecificContainerMappingInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationproviderspecificupdatecontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationproviderspecificupdatecontainermappinginput.go new file mode 100644 index 00000000000..a9e70d521ef --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_replicationproviderspecificupdatecontainermappinginput.go @@ -0,0 +1,56 @@ +package replicationprotectioncontainermappings + +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 ReplicationProviderSpecificUpdateContainerMappingInput interface { +} + +func unmarshalReplicationProviderSpecificUpdateContainerMappingInputImplementation(input []byte) (ReplicationProviderSpecificUpdateContainerMappingInput, 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 ReplicationProviderSpecificUpdateContainerMappingInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AUpdateContainerMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AUpdateContainerMappingInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out InMageRcmUpdateContainerMappingInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into InMageRcmUpdateContainerMappingInput: %+v", err) + } + return out, nil + } + + type RawReplicationProviderSpecificUpdateContainerMappingInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawReplicationProviderSpecificUpdateContainerMappingInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_updateprotectioncontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_updateprotectioncontainermappinginput.go new file mode 100644 index 00000000000..9c2d7bf172c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_updateprotectioncontainermappinginput.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainermappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateProtectionContainerMappingInput struct { + Properties *UpdateProtectionContainerMappingInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_updateprotectioncontainermappinginputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_updateprotectioncontainermappinginputproperties.go new file mode 100644 index 00000000000..e021c62ed1f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_updateprotectioncontainermappinginputproperties.go @@ -0,0 +1,32 @@ +package replicationprotectioncontainermappings + +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 UpdateProtectionContainerMappingInputProperties struct { + ProviderSpecificInput ReplicationProviderSpecificUpdateContainerMappingInput `json:"providerSpecificInput"` +} + +var _ json.Unmarshaler = &UpdateProtectionContainerMappingInputProperties{} + +func (s *UpdateProtectionContainerMappingInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling UpdateProtectionContainerMappingInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificInput"]; ok { + impl, err := unmarshalReplicationProviderSpecificUpdateContainerMappingInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificInput' for 'UpdateProtectionContainerMappingInputProperties': %+v", err) + } + s.ProviderSpecificInput = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_vmwarecbtcontainermappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_vmwarecbtcontainermappinginput.go new file mode 100644 index 00000000000..d4711386360 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_vmwarecbtcontainermappinginput.go @@ -0,0 +1,46 @@ +package replicationprotectioncontainermappings + +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 _ ReplicationProviderSpecificContainerMappingInput = VMwareCbtContainerMappingInput{} + +type VMwareCbtContainerMappingInput struct { + KeyVaultId *string `json:"keyVaultId,omitempty"` + KeyVaultUri *string `json:"keyVaultUri,omitempty"` + ServiceBusConnectionStringSecretName *string `json:"serviceBusConnectionStringSecretName,omitempty"` + StorageAccountId string `json:"storageAccountId"` + StorageAccountSasSecretName *string `json:"storageAccountSasSecretName,omitempty"` + TargetLocation string `json:"targetLocation"` + + // Fields inherited from ReplicationProviderSpecificContainerMappingInput +} + +var _ json.Marshaler = VMwareCbtContainerMappingInput{} + +func (s VMwareCbtContainerMappingInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtContainerMappingInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtContainerMappingInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtContainerMappingInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtContainerMappingInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_vmwarecbtprotectioncontainermappingdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_vmwarecbtprotectioncontainermappingdetails.go new file mode 100644 index 00000000000..29bd438cf42 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/model_vmwarecbtprotectioncontainermappingdetails.go @@ -0,0 +1,48 @@ +package replicationprotectioncontainermappings + +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 _ ProtectionContainerMappingProviderSpecificDetails = VMwareCbtProtectionContainerMappingDetails{} + +type VMwareCbtProtectionContainerMappingDetails struct { + ExcludedSkus *[]string `json:"excludedSkus,omitempty"` + KeyVaultId *string `json:"keyVaultId,omitempty"` + KeyVaultUri *string `json:"keyVaultUri,omitempty"` + RoleSizeToNicCountMap *map[string]int64 `json:"roleSizeToNicCountMap,omitempty"` + ServiceBusConnectionStringSecretName *string `json:"serviceBusConnectionStringSecretName,omitempty"` + StorageAccountId *string `json:"storageAccountId,omitempty"` + StorageAccountSasSecretName *string `json:"storageAccountSasSecretName,omitempty"` + TargetLocation *string `json:"targetLocation,omitempty"` + + // Fields inherited from ProtectionContainerMappingProviderSpecificDetails +} + +var _ json.Marshaler = VMwareCbtProtectionContainerMappingDetails{} + +func (s VMwareCbtProtectionContainerMappingDetails) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtProtectionContainerMappingDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtProtectionContainerMappingDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtProtectionContainerMappingDetails: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtProtectionContainerMappingDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/predicates.go new file mode 100644 index 00000000000..e13e9e577e2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/predicates.go @@ -0,0 +1,32 @@ +package replicationprotectioncontainermappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainerMappingOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectionContainerMappingOperationPredicate) Matches(input ProtectionContainerMapping) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/version.go new file mode 100644 index 00000000000..2db489a0e5b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainermappings/version.go @@ -0,0 +1,12 @@ +package replicationprotectioncontainermappings + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationprotectioncontainermappings/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/README.md new file mode 100644 index 00000000000..53ebd27dc45 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/README.md @@ -0,0 +1,133 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers` Documentation + +The `replicationprotectioncontainers` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers" +``` + + +### Client Initialization + +```go +client := replicationprotectioncontainers.NewReplicationProtectionContainersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationProtectionContainersClient.Create` + +```go +ctx := context.TODO() +id := replicationprotectioncontainers.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +payload := replicationprotectioncontainers.CreateProtectionContainerInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectionContainersClient.Delete` + +```go +ctx := context.TODO() +id := replicationprotectioncontainers.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectionContainersClient.DiscoverProtectableItem` + +```go +ctx := context.TODO() +id := replicationprotectioncontainers.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +payload := replicationprotectioncontainers.DiscoverProtectableItemRequest{ + // ... +} + + +if err := client.DiscoverProtectableItemThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationProtectionContainersClient.Get` + +```go +ctx := context.TODO() +id := replicationprotectioncontainers.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +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: `ReplicationProtectionContainersClient.List` + +```go +ctx := context.TODO() +id := replicationprotectioncontainers.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationProtectionContainersClient.ListByReplicationFabrics` + +```go +ctx := context.TODO() +id := replicationprotectioncontainers.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +// alternatively `client.ListByReplicationFabrics(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationFabricsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationProtectionContainersClient.SwitchProtection` + +```go +ctx := context.TODO() +id := replicationprotectioncontainers.NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + +payload := replicationprotectioncontainers.SwitchProtectionInput{ + // ... +} + + +if err := client.SwitchProtectionThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/client.go new file mode 100644 index 00000000000..265054738f7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/client.go @@ -0,0 +1,18 @@ +package replicationprotectioncontainers + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectionContainersClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationProtectionContainersClientWithBaseURI(endpoint string) ReplicationProtectionContainersClient { + return ReplicationProtectionContainersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationfabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationfabric.go new file mode 100644 index 00000000000..9d53a7a6d5a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationprotectioncontainers + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationfabric_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationfabric_test.go new file mode 100644 index 00000000000..7115d4e9742 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationfabric_test.go @@ -0,0 +1,327 @@ +package replicationprotectioncontainers + +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 = ReplicationFabricId{} + +func TestNewReplicationFabricID(t *testing.T) { + id := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } +} + +func TestFormatReplicationFabricID(t *testing.T) { + actual := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestParseReplicationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestSegmentsForReplicationFabricId(t *testing.T) { + segments := ReplicationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationFabricId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationprotectioncontainer.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationprotectioncontainer.go new file mode 100644 index 00000000000..e6817c67300 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationprotectioncontainer.go @@ -0,0 +1,153 @@ +package replicationprotectioncontainers + +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 = ReplicationProtectionContainerId{} + +// ReplicationProtectionContainerId is a struct representing the Resource ID for a Replication Protection Container +type ReplicationProtectionContainerId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string +} + +// NewReplicationProtectionContainerID returns a new ReplicationProtectionContainerId struct +func NewReplicationProtectionContainerID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string) ReplicationProtectionContainerId { + return ReplicationProtectionContainerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + } +} + +// ParseReplicationProtectionContainerID parses 'input' into a ReplicationProtectionContainerId +func ParseReplicationProtectionContainerID(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectionContainerIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionContainerId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionContainerIDInsensitively(input string) (*ReplicationProtectionContainerId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionContainerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionContainerId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectionContainerID checks that 'input' can be parsed as a Replication Protection Container ID +func ValidateReplicationProtectionContainerID(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 := ParseReplicationProtectionContainerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Container ID +func (id ReplicationProtectionContainerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Container ID +func (id ReplicationProtectionContainerId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + } +} + +// String returns a human-readable description of this Replication Protection Container ID +func (id ReplicationProtectionContainerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + } + return fmt.Sprintf("Replication Protection Container (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationprotectioncontainer_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationprotectioncontainer_test.go new file mode 100644 index 00000000000..8eab72350c8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_replicationprotectioncontainer_test.go @@ -0,0 +1,372 @@ +package replicationprotectioncontainers + +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 = ReplicationProtectionContainerId{} + +func TestNewReplicationProtectionContainerID(t *testing.T) { + id := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } +} + +func TestFormatReplicationProtectionContainerID(t *testing.T) { + actual := NewReplicationProtectionContainerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectionContainerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestParseReplicationProtectionContainerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionContainerId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Expected: &ReplicationProtectionContainerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionContainerIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + } +} + +func TestSegmentsForReplicationProtectionContainerId(t *testing.T) { + segments := ReplicationProtectionContainerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectionContainerId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_vault.go new file mode 100644 index 00000000000..5456ddf3d20 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_vault.go @@ -0,0 +1,127 @@ +package replicationprotectioncontainers + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_vault_test.go new file mode 100644 index 00000000000..ab45d32efa0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationprotectioncontainers + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_create_autorest.go new file mode 100644 index 00000000000..23a2ed1b02f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationprotectioncontainers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationProtectionContainersClient) Create(ctx context.Context, id ReplicationProtectionContainerId, input CreateProtectionContainerInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationProtectionContainersClient) CreateThenPoll(ctx context.Context, id ReplicationProtectionContainerId, input CreateProtectionContainerInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationProtectionContainersClient) preparerForCreate(ctx context.Context, id ReplicationProtectionContainerId, input CreateProtectionContainerInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainersClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_delete_autorest.go new file mode 100644 index 00000000000..f8c4ecebb4f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationprotectioncontainers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationProtectionContainersClient) Delete(ctx context.Context, id ReplicationProtectionContainerId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationProtectionContainersClient) DeleteThenPoll(ctx context.Context, id ReplicationProtectionContainerId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationProtectionContainersClient) preparerForDelete(ctx context.Context, id ReplicationProtectionContainerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/remove", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainersClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_discoverprotectableitem_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_discoverprotectableitem_autorest.go new file mode 100644 index 00000000000..44841873f17 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_discoverprotectableitem_autorest.go @@ -0,0 +1,79 @@ +package replicationprotectioncontainers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiscoverProtectableItemOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// DiscoverProtectableItem ... +func (c ReplicationProtectionContainersClient) DiscoverProtectableItem(ctx context.Context, id ReplicationProtectionContainerId, input DiscoverProtectableItemRequest) (result DiscoverProtectableItemOperationResponse, err error) { + req, err := c.preparerForDiscoverProtectableItem(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "DiscoverProtectableItem", nil, "Failure preparing request") + return + } + + result, err = c.senderForDiscoverProtectableItem(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "DiscoverProtectableItem", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DiscoverProtectableItemThenPoll performs DiscoverProtectableItem then polls until it's completed +func (c ReplicationProtectionContainersClient) DiscoverProtectableItemThenPoll(ctx context.Context, id ReplicationProtectionContainerId, input DiscoverProtectableItemRequest) error { + result, err := c.DiscoverProtectableItem(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DiscoverProtectableItem: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after DiscoverProtectableItem: %+v", err) + } + + return nil +} + +// preparerForDiscoverProtectableItem prepares the DiscoverProtectableItem request. +func (c ReplicationProtectionContainersClient) preparerForDiscoverProtectableItem(ctx context.Context, id ReplicationProtectionContainerId, input DiscoverProtectableItemRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/discoverProtectableItem", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDiscoverProtectableItem sends the DiscoverProtectableItem request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainersClient) senderForDiscoverProtectableItem(ctx context.Context, req *http.Request) (future DiscoverProtectableItemOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_get_autorest.go new file mode 100644 index 00000000000..2376ff982cb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationprotectioncontainers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ProtectionContainer +} + +// Get ... +func (c ReplicationProtectionContainersClient) Get(ctx context.Context, id ReplicationProtectionContainerId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationProtectionContainersClient) preparerForGet(ctx context.Context, id ReplicationProtectionContainerId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionContainersClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_list_autorest.go new file mode 100644 index 00000000000..1c9d997ca03 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationprotectioncontainers + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionContainer + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ProtectionContainer +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationProtectionContainersClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationProtectionContainersClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectionContainers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationProtectionContainersClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionContainersClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ProtectionContainer `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationProtectionContainersClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ProtectionContainerOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectionContainersClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate ProtectionContainerOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ProtectionContainer, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_listbyreplicationfabrics_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_listbyreplicationfabrics_autorest.go new file mode 100644 index 00000000000..78c67e0dfc0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_listbyreplicationfabrics_autorest.go @@ -0,0 +1,186 @@ +package replicationprotectioncontainers + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationFabricsOperationResponse struct { + HttpResponse *http.Response + Model *[]ProtectionContainer + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationFabricsOperationResponse, error) +} + +type ListByReplicationFabricsCompleteResult struct { + Items []ProtectionContainer +} + +func (r ListByReplicationFabricsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationFabricsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationFabricsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationFabrics ... +func (c ReplicationProtectionContainersClient) ListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (resp ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabrics(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationFabrics(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationFabrics prepares the ListByReplicationFabrics request. +func (c ReplicationProtectionContainersClient) preparerForListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectionContainers", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationFabricsWithNextLink prepares the ListByReplicationFabrics request with the given nextLink token. +func (c ReplicationProtectionContainersClient) preparerForListByReplicationFabricsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationFabrics handles the response to the ListByReplicationFabrics request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionContainersClient) responderForListByReplicationFabrics(resp *http.Response) (result ListByReplicationFabricsOperationResponse, err error) { + type page struct { + Values []ProtectionContainer `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabricsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "ListByReplicationFabrics", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationFabrics(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "ListByReplicationFabrics", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationFabricsComplete retrieves all of the results into a single object +func (c ReplicationProtectionContainersClient) ListByReplicationFabricsComplete(ctx context.Context, id ReplicationFabricId) (ListByReplicationFabricsCompleteResult, error) { + return c.ListByReplicationFabricsCompleteMatchingPredicate(ctx, id, ProtectionContainerOperationPredicate{}) +} + +// ListByReplicationFabricsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectionContainersClient) ListByReplicationFabricsCompleteMatchingPredicate(ctx context.Context, id ReplicationFabricId, predicate ProtectionContainerOperationPredicate) (resp ListByReplicationFabricsCompleteResult, err error) { + items := make([]ProtectionContainer, 0) + + page, err := c.ListByReplicationFabrics(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationFabricsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_switchprotection_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_switchprotection_autorest.go new file mode 100644 index 00000000000..87e3cd927f5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/method_switchprotection_autorest.go @@ -0,0 +1,79 @@ +package replicationprotectioncontainers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SwitchProtectionOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// SwitchProtection ... +func (c ReplicationProtectionContainersClient) SwitchProtection(ctx context.Context, id ReplicationProtectionContainerId, input SwitchProtectionInput) (result SwitchProtectionOperationResponse, err error) { + req, err := c.preparerForSwitchProtection(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "SwitchProtection", nil, "Failure preparing request") + return + } + + result, err = c.senderForSwitchProtection(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectioncontainers.ReplicationProtectionContainersClient", "SwitchProtection", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// SwitchProtectionThenPoll performs SwitchProtection then polls until it's completed +func (c ReplicationProtectionContainersClient) SwitchProtectionThenPoll(ctx context.Context, id ReplicationProtectionContainerId, input SwitchProtectionInput) error { + result, err := c.SwitchProtection(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SwitchProtection: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after SwitchProtection: %+v", err) + } + + return nil +} + +// preparerForSwitchProtection prepares the SwitchProtection request. +func (c ReplicationProtectionContainersClient) preparerForSwitchProtection(ctx context.Context, id ReplicationProtectionContainerId, input SwitchProtectionInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/switchprotection", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForSwitchProtection sends the SwitchProtection request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationProtectionContainersClient) senderForSwitchProtection(ctx context.Context, req *http.Request) (future SwitchProtectionOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2acontainercreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2acontainercreationinput.go new file mode 100644 index 00000000000..266ed59b59f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2acontainercreationinput.go @@ -0,0 +1,40 @@ +package replicationprotectioncontainers + +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 _ ReplicationProviderSpecificContainerCreationInput = A2AContainerCreationInput{} + +type A2AContainerCreationInput struct { + + // Fields inherited from ReplicationProviderSpecificContainerCreationInput +} + +var _ json.Marshaler = A2AContainerCreationInput{} + +func (s A2AContainerCreationInput) MarshalJSON() ([]byte, error) { + type wrapper A2AContainerCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AContainerCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AContainerCreationInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AContainerCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2acrossclustermigrationcontainercreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2acrossclustermigrationcontainercreationinput.go new file mode 100644 index 00000000000..d5d6094ea4e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2acrossclustermigrationcontainercreationinput.go @@ -0,0 +1,40 @@ +package replicationprotectioncontainers + +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 _ ReplicationProviderSpecificContainerCreationInput = A2ACrossClusterMigrationContainerCreationInput{} + +type A2ACrossClusterMigrationContainerCreationInput struct { + + // Fields inherited from ReplicationProviderSpecificContainerCreationInput +} + +var _ json.Marshaler = A2ACrossClusterMigrationContainerCreationInput{} + +func (s A2ACrossClusterMigrationContainerCreationInput) MarshalJSON() ([]byte, error) { + type wrapper A2ACrossClusterMigrationContainerCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ACrossClusterMigrationContainerCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ACrossClusterMigrationContainerCreationInput: %+v", err) + } + decoded["instanceType"] = "A2ACrossClusterMigration" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ACrossClusterMigrationContainerCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2aswitchprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2aswitchprotectioninput.go new file mode 100644 index 00000000000..a2d5ecbeefb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2aswitchprotectioninput.go @@ -0,0 +1,53 @@ +package replicationprotectioncontainers + +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 _ SwitchProtectionProviderSpecificInput = A2ASwitchProtectionInput{} + +type A2ASwitchProtectionInput struct { + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + RecoveryAvailabilitySetId *string `json:"recoveryAvailabilitySetId,omitempty"` + RecoveryAvailabilityZone *string `json:"recoveryAvailabilityZone,omitempty"` + RecoveryBootDiagStorageAccountId *string `json:"recoveryBootDiagStorageAccountId,omitempty"` + RecoveryCapacityReservationGroupId *string `json:"recoveryCapacityReservationGroupId,omitempty"` + RecoveryCloudServiceId *string `json:"recoveryCloudServiceId,omitempty"` + RecoveryContainerId *string `json:"recoveryContainerId,omitempty"` + RecoveryProximityPlacementGroupId *string `json:"recoveryProximityPlacementGroupId,omitempty"` + RecoveryResourceGroupId *string `json:"recoveryResourceGroupId,omitempty"` + RecoveryVirtualMachineScaleSetId *string `json:"recoveryVirtualMachineScaleSetId,omitempty"` + VMDisks *[]A2AVMDiskInputDetails `json:"vmDisks,omitempty"` + VMManagedDisks *[]A2AVMManagedDiskInputDetails `json:"vmManagedDisks,omitempty"` + + // Fields inherited from SwitchProtectionProviderSpecificInput +} + +var _ json.Marshaler = A2ASwitchProtectionInput{} + +func (s A2ASwitchProtectionInput) MarshalJSON() ([]byte, error) { + type wrapper A2ASwitchProtectionInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ASwitchProtectionInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ASwitchProtectionInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ASwitchProtectionInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2avmdiskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2avmdiskinputdetails.go new file mode 100644 index 00000000000..1e0784c90fc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2avmdiskinputdetails.go @@ -0,0 +1,10 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AVMDiskInputDetails struct { + DiskUri string `json:"diskUri"` + PrimaryStagingAzureStorageAccountId string `json:"primaryStagingAzureStorageAccountId"` + RecoveryAzureStorageAccountId string `json:"recoveryAzureStorageAccountId"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2avmmanageddiskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2avmmanageddiskinputdetails.go new file mode 100644 index 00000000000..6c0c988393d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_a2avmmanageddiskinputdetails.go @@ -0,0 +1,14 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2AVMManagedDiskInputDetails struct { + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + DiskId string `json:"diskId"` + PrimaryStagingAzureStorageAccountId string `json:"primaryStagingAzureStorageAccountId"` + RecoveryDiskEncryptionSetId *string `json:"recoveryDiskEncryptionSetId,omitempty"` + RecoveryReplicaDiskAccountType *string `json:"recoveryReplicaDiskAccountType,omitempty"` + RecoveryResourceGroupId string `json:"recoveryResourceGroupId"` + RecoveryTargetDiskAccountType *string `json:"recoveryTargetDiskAccountType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_createprotectioncontainerinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_createprotectioncontainerinput.go new file mode 100644 index 00000000000..55175403c81 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_createprotectioncontainerinput.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateProtectionContainerInput struct { + Properties *CreateProtectionContainerInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_createprotectioncontainerinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_createprotectioncontainerinputproperties.go new file mode 100644 index 00000000000..c3322f96a09 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_createprotectioncontainerinputproperties.go @@ -0,0 +1,41 @@ +package replicationprotectioncontainers + +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 CreateProtectionContainerInputProperties struct { + ProviderSpecificInput *[]ReplicationProviderSpecificContainerCreationInput `json:"providerSpecificInput,omitempty"` +} + +var _ json.Unmarshaler = &CreateProtectionContainerInputProperties{} + +func (s *CreateProtectionContainerInputProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CreateProtectionContainerInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificInput"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ProviderSpecificInput into list []json.RawMessage: %+v", err) + } + + output := make([]ReplicationProviderSpecificContainerCreationInput, 0) + for i, val := range listTemp { + impl, err := unmarshalReplicationProviderSpecificContainerCreationInputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ProviderSpecificInput' for 'CreateProtectionContainerInputProperties': %+v", i, err) + } + output = append(output, impl) + } + s.ProviderSpecificInput = &output + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_discoverprotectableitemrequest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_discoverprotectableitemrequest.go new file mode 100644 index 00000000000..ceca9005e59 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_discoverprotectableitemrequest.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiscoverProtectableItemRequest struct { + Properties *DiscoverProtectableItemRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_discoverprotectableitemrequestproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_discoverprotectableitemrequestproperties.go new file mode 100644 index 00000000000..fee5502a3c7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_discoverprotectableitemrequestproperties.go @@ -0,0 +1,10 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiscoverProtectableItemRequestProperties struct { + FriendlyName *string `json:"friendlyName,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + OsType *string `json:"osType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_diskencryptioninfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_diskencryptioninfo.go new file mode 100644 index 00000000000..997e7018bf6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_diskencryptioninfo.go @@ -0,0 +1,9 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionInfo struct { + DiskEncryptionKeyInfo *DiskEncryptionKeyInfo `json:"diskEncryptionKeyInfo,omitempty"` + KeyEncryptionKeyInfo *KeyEncryptionKeyInfo `json:"keyEncryptionKeyInfo,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_diskencryptionkeyinfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_diskencryptionkeyinfo.go new file mode 100644 index 00000000000..e67e3239790 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_diskencryptionkeyinfo.go @@ -0,0 +1,9 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionKeyInfo struct { + KeyVaultResourceArmId *string `json:"keyVaultResourceArmId,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_keyencryptionkeyinfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_keyencryptionkeyinfo.go new file mode 100644 index 00000000000..e5eb025e741 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_keyencryptionkeyinfo.go @@ -0,0 +1,9 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyEncryptionKeyInfo struct { + KeyIdentifier *string `json:"keyIdentifier,omitempty"` + KeyVaultResourceArmId *string `json:"keyVaultResourceArmId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainer.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainer.go new file mode 100644 index 00000000000..0236469ade2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainer.go @@ -0,0 +1,12 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainer struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProtectionContainerProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainerfabricspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainerfabricspecificdetails.go new file mode 100644 index 00000000000..ccda06f411a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainerfabricspecificdetails.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainerFabricSpecificDetails struct { + InstanceType *string `json:"instanceType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainerproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainerproperties.go new file mode 100644 index 00000000000..baa48fb4dcd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_protectioncontainerproperties.go @@ -0,0 +1,14 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainerProperties struct { + FabricFriendlyName *string `json:"fabricFriendlyName,omitempty"` + FabricSpecificDetails *ProtectionContainerFabricSpecificDetails `json:"fabricSpecificDetails,omitempty"` + FabricType *string `json:"fabricType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PairingStatus *string `json:"pairingStatus,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + Role *string `json:"role,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_replicationproviderspecificcontainercreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_replicationproviderspecificcontainercreationinput.go new file mode 100644 index 00000000000..24d6b16f358 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_replicationproviderspecificcontainercreationinput.go @@ -0,0 +1,64 @@ +package replicationprotectioncontainers + +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 ReplicationProviderSpecificContainerCreationInput interface { +} + +func unmarshalReplicationProviderSpecificContainerCreationInputImplementation(input []byte) (ReplicationProviderSpecificContainerCreationInput, 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 ReplicationProviderSpecificContainerCreationInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AContainerCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AContainerCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "A2ACrossClusterMigration") { + var out A2ACrossClusterMigrationContainerCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ACrossClusterMigrationContainerCreationInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "VMwareCbt") { + var out VMwareCbtContainerCreationInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMwareCbtContainerCreationInput: %+v", err) + } + return out, nil + } + + type RawReplicationProviderSpecificContainerCreationInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawReplicationProviderSpecificContainerCreationInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectioninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectioninput.go new file mode 100644 index 00000000000..ebb469d6c10 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectioninput.go @@ -0,0 +1,8 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SwitchProtectionInput struct { + Properties *SwitchProtectionInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectioninputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectioninputproperties.go new file mode 100644 index 00000000000..9ddc61f5e27 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectioninputproperties.go @@ -0,0 +1,40 @@ +package replicationprotectioncontainers + +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 SwitchProtectionInputProperties struct { + ProviderSpecificDetails SwitchProtectionProviderSpecificInput `json:"providerSpecificDetails"` + ReplicationProtectedItemName *string `json:"replicationProtectedItemName,omitempty"` +} + +var _ json.Unmarshaler = &SwitchProtectionInputProperties{} + +func (s *SwitchProtectionInputProperties) UnmarshalJSON(bytes []byte) error { + type alias SwitchProtectionInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SwitchProtectionInputProperties: %+v", err) + } + + s.ReplicationProtectedItemName = decoded.ReplicationProtectedItemName + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SwitchProtectionInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalSwitchProtectionProviderSpecificInputImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'SwitchProtectionInputProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectionproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectionproviderspecificinput.go new file mode 100644 index 00000000000..005fbfabbbe --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_switchprotectionproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationprotectioncontainers + +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 SwitchProtectionProviderSpecificInput interface { +} + +func unmarshalSwitchProtectionProviderSpecificInputImplementation(input []byte) (SwitchProtectionProviderSpecificInput, 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 SwitchProtectionProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2ASwitchProtectionInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ASwitchProtectionInput: %+v", err) + } + return out, nil + } + + type RawSwitchProtectionProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawSwitchProtectionProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_vmwarecbtcontainercreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_vmwarecbtcontainercreationinput.go new file mode 100644 index 00000000000..2db1f2ac651 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/model_vmwarecbtcontainercreationinput.go @@ -0,0 +1,40 @@ +package replicationprotectioncontainers + +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 _ ReplicationProviderSpecificContainerCreationInput = VMwareCbtContainerCreationInput{} + +type VMwareCbtContainerCreationInput struct { + + // Fields inherited from ReplicationProviderSpecificContainerCreationInput +} + +var _ json.Marshaler = VMwareCbtContainerCreationInput{} + +func (s VMwareCbtContainerCreationInput) MarshalJSON() ([]byte, error) { + type wrapper VMwareCbtContainerCreationInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMwareCbtContainerCreationInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMwareCbtContainerCreationInput: %+v", err) + } + decoded["instanceType"] = "VMwareCbt" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMwareCbtContainerCreationInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/predicates.go new file mode 100644 index 00000000000..10d3d956e23 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/predicates.go @@ -0,0 +1,32 @@ +package replicationprotectioncontainers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionContainerOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ProtectionContainerOperationPredicate) Matches(input ProtectionContainer) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/version.go new file mode 100644 index 00000000000..656655d0b22 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectioncontainers/version.go @@ -0,0 +1,12 @@ +package replicationprotectioncontainers + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationprotectioncontainers/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/README.md new file mode 100644 index 00000000000..047c7601ae3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents` Documentation + +The `replicationprotectionintents` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents" +``` + + +### Client Initialization + +```go +client := replicationprotectionintents.NewReplicationProtectionIntentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationProtectionIntentsClient.Create` + +```go +ctx := context.TODO() +id := replicationprotectionintents.NewReplicationProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationProtectionIntentValue") + +payload := replicationprotectionintents.CreateProtectionIntentInput{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ReplicationProtectionIntentsClient.Get` + +```go +ctx := context.TODO() +id := replicationprotectionintents.NewReplicationProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationProtectionIntentValue") + +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: `ReplicationProtectionIntentsClient.List` + +```go +ctx := context.TODO() +id := replicationprotectionintents.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// alternatively `client.List(ctx, id, replicationprotectionintents.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, replicationprotectionintents.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/client.go new file mode 100644 index 00000000000..326973654d4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/client.go @@ -0,0 +1,18 @@ +package replicationprotectionintents + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectionIntentsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationProtectionIntentsClientWithBaseURI(endpoint string) ReplicationProtectionIntentsClient { + return ReplicationProtectionIntentsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/constants.go new file mode 100644 index 00000000000..b7ad5720788 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/constants.go @@ -0,0 +1,149 @@ +package replicationprotectionintents + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2ARecoveryAvailabilityType string + +const ( + A2ARecoveryAvailabilityTypeAvailabilitySet A2ARecoveryAvailabilityType = "AvailabilitySet" + A2ARecoveryAvailabilityTypeAvailabilityZone A2ARecoveryAvailabilityType = "AvailabilityZone" + A2ARecoveryAvailabilityTypeSingle A2ARecoveryAvailabilityType = "Single" +) + +func PossibleValuesForA2ARecoveryAvailabilityType() []string { + return []string{ + string(A2ARecoveryAvailabilityTypeAvailabilitySet), + string(A2ARecoveryAvailabilityTypeAvailabilityZone), + string(A2ARecoveryAvailabilityTypeSingle), + } +} + +func parseA2ARecoveryAvailabilityType(input string) (*A2ARecoveryAvailabilityType, error) { + vals := map[string]A2ARecoveryAvailabilityType{ + "availabilityset": A2ARecoveryAvailabilityTypeAvailabilitySet, + "availabilityzone": A2ARecoveryAvailabilityTypeAvailabilityZone, + "single": A2ARecoveryAvailabilityTypeSingle, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := A2ARecoveryAvailabilityType(input) + return &out, nil +} + +type AgentAutoUpdateStatus string + +const ( + AgentAutoUpdateStatusDisabled AgentAutoUpdateStatus = "Disabled" + AgentAutoUpdateStatusEnabled AgentAutoUpdateStatus = "Enabled" +) + +func PossibleValuesForAgentAutoUpdateStatus() []string { + return []string{ + string(AgentAutoUpdateStatusDisabled), + string(AgentAutoUpdateStatusEnabled), + } +} + +func parseAgentAutoUpdateStatus(input string) (*AgentAutoUpdateStatus, error) { + vals := map[string]AgentAutoUpdateStatus{ + "disabled": AgentAutoUpdateStatusDisabled, + "enabled": AgentAutoUpdateStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AgentAutoUpdateStatus(input) + return &out, nil +} + +type AutoProtectionOfDataDisk string + +const ( + AutoProtectionOfDataDiskDisabled AutoProtectionOfDataDisk = "Disabled" + AutoProtectionOfDataDiskEnabled AutoProtectionOfDataDisk = "Enabled" +) + +func PossibleValuesForAutoProtectionOfDataDisk() []string { + return []string{ + string(AutoProtectionOfDataDiskDisabled), + string(AutoProtectionOfDataDiskEnabled), + } +} + +func parseAutoProtectionOfDataDisk(input string) (*AutoProtectionOfDataDisk, error) { + vals := map[string]AutoProtectionOfDataDisk{ + "disabled": AutoProtectionOfDataDiskDisabled, + "enabled": AutoProtectionOfDataDiskEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoProtectionOfDataDisk(input) + return &out, nil +} + +type AutomationAccountAuthenticationType string + +const ( + AutomationAccountAuthenticationTypeRunAsAccount AutomationAccountAuthenticationType = "RunAsAccount" + AutomationAccountAuthenticationTypeSystemAssignedIdentity AutomationAccountAuthenticationType = "SystemAssignedIdentity" +) + +func PossibleValuesForAutomationAccountAuthenticationType() []string { + return []string{ + string(AutomationAccountAuthenticationTypeRunAsAccount), + string(AutomationAccountAuthenticationTypeSystemAssignedIdentity), + } +} + +func parseAutomationAccountAuthenticationType(input string) (*AutomationAccountAuthenticationType, error) { + vals := map[string]AutomationAccountAuthenticationType{ + "runasaccount": AutomationAccountAuthenticationTypeRunAsAccount, + "systemassignedidentity": AutomationAccountAuthenticationTypeSystemAssignedIdentity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationAccountAuthenticationType(input) + return &out, nil +} + +type SetMultiVMSyncStatus string + +const ( + SetMultiVMSyncStatusDisable SetMultiVMSyncStatus = "Disable" + SetMultiVMSyncStatusEnable SetMultiVMSyncStatus = "Enable" +) + +func PossibleValuesForSetMultiVMSyncStatus() []string { + return []string{ + string(SetMultiVMSyncStatusDisable), + string(SetMultiVMSyncStatusEnable), + } +} + +func parseSetMultiVMSyncStatus(input string) (*SetMultiVMSyncStatus, error) { + vals := map[string]SetMultiVMSyncStatus{ + "disable": SetMultiVMSyncStatusDisable, + "enable": SetMultiVMSyncStatusEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SetMultiVMSyncStatus(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_replicationprotectionintent.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_replicationprotectionintent.go new file mode 100644 index 00000000000..4226cf8ad17 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_replicationprotectionintent.go @@ -0,0 +1,140 @@ +package replicationprotectionintents + +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 = ReplicationProtectionIntentId{} + +// ReplicationProtectionIntentId is a struct representing the Resource ID for a Replication Protection Intent +type ReplicationProtectionIntentId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationProtectionIntentName string +} + +// NewReplicationProtectionIntentID returns a new ReplicationProtectionIntentId struct +func NewReplicationProtectionIntentID(subscriptionId string, resourceGroupName string, vaultName string, replicationProtectionIntentName string) ReplicationProtectionIntentId { + return ReplicationProtectionIntentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationProtectionIntentName: replicationProtectionIntentName, + } +} + +// ParseReplicationProtectionIntentID parses 'input' into a ReplicationProtectionIntentId +func ParseReplicationProtectionIntentID(input string) (*ReplicationProtectionIntentId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionIntentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionIntentId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionIntentName, ok = parsed.Parsed["replicationProtectionIntentName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionIntentName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectionIntentIDInsensitively parses 'input' case-insensitively into a ReplicationProtectionIntentId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectionIntentIDInsensitively(input string) (*ReplicationProtectionIntentId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectionIntentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectionIntentId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionIntentName, ok = parsed.Parsed["replicationProtectionIntentName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionIntentName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectionIntentID checks that 'input' can be parsed as a Replication Protection Intent ID +func ValidateReplicationProtectionIntentID(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 := ParseReplicationProtectionIntentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protection Intent ID +func (id ReplicationProtectionIntentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationProtectionIntents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationProtectionIntentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protection Intent ID +func (id ReplicationProtectionIntentId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationProtectionIntents", "replicationProtectionIntents", "replicationProtectionIntents"), + resourceids.UserSpecifiedSegment("replicationProtectionIntentName", "replicationProtectionIntentValue"), + } +} + +// String returns a human-readable description of this Replication Protection Intent ID +func (id ReplicationProtectionIntentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Protection Intent Name: %q", id.ReplicationProtectionIntentName), + } + return fmt.Sprintf("Replication Protection Intent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_replicationprotectionintent_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_replicationprotectionintent_test.go new file mode 100644 index 00000000000..45498e75769 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_replicationprotectionintent_test.go @@ -0,0 +1,327 @@ +package replicationprotectionintents + +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 = ReplicationProtectionIntentId{} + +func TestNewReplicationProtectionIntentID(t *testing.T) { + id := NewReplicationProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationProtectionIntentValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationProtectionIntentName != "replicationProtectionIntentValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionIntentName'", id.ReplicationProtectionIntentName, "replicationProtectionIntentValue") + } +} + +func TestFormatReplicationProtectionIntentID(t *testing.T) { + actual := NewReplicationProtectionIntentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationProtectionIntentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationProtectionIntents/replicationProtectionIntentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectionIntentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionIntentId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationProtectionIntents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationProtectionIntents/replicationProtectionIntentValue", + Expected: &ReplicationProtectionIntentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationProtectionIntentName: "replicationProtectionIntentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationProtectionIntents/replicationProtectionIntentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionIntentID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationProtectionIntentName != v.Expected.ReplicationProtectionIntentName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionIntentName", v.Expected.ReplicationProtectionIntentName, actual.ReplicationProtectionIntentName) + } + + } +} + +func TestParseReplicationProtectionIntentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectionIntentId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationProtectionIntents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnPrOtEcTiOnInTeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationProtectionIntents/replicationProtectionIntentValue", + Expected: &ReplicationProtectionIntentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationProtectionIntentName: "replicationProtectionIntentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationProtectionIntents/replicationProtectionIntentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnPrOtEcTiOnInTeNtS/rEpLiCaTiOnPrOtEcTiOnInTeNtVaLuE", + Expected: &ReplicationProtectionIntentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationProtectionIntentName: "rEpLiCaTiOnPrOtEcTiOnInTeNtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnPrOtEcTiOnInTeNtS/rEpLiCaTiOnPrOtEcTiOnInTeNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectionIntentIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationProtectionIntentName != v.Expected.ReplicationProtectionIntentName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionIntentName", v.Expected.ReplicationProtectionIntentName, actual.ReplicationProtectionIntentName) + } + + } +} + +func TestSegmentsForReplicationProtectionIntentId(t *testing.T) { + segments := ReplicationProtectionIntentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectionIntentId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_vault.go new file mode 100644 index 00000000000..c0c5d5d1b7f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_vault.go @@ -0,0 +1,127 @@ +package replicationprotectionintents + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_vault_test.go new file mode 100644 index 00000000000..cd3503f3efe --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationprotectionintents + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_create_autorest.go new file mode 100644 index 00000000000..dd98cf6daa1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_create_autorest.go @@ -0,0 +1,69 @@ +package replicationprotectionintents + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + Model *ReplicationProtectionIntent +} + +// Create ... +func (c ReplicationProtectionIntentsClient) Create(ctx context.Context, id ReplicationProtectionIntentId, input CreateProtectionIntentInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "Create", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "Create", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreate prepares the Create request. +func (c ReplicationProtectionIntentsClient) preparerForCreate(ctx context.Context, id ReplicationProtectionIntentId, input CreateProtectionIntentInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreate handles the response to the Create request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionIntentsClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_get_autorest.go new file mode 100644 index 00000000000..87f979e8a36 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationprotectionintents + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ReplicationProtectionIntent +} + +// Get ... +func (c ReplicationProtectionIntentsClient) Get(ctx context.Context, id ReplicationProtectionIntentId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationProtectionIntentsClient) preparerForGet(ctx context.Context, id ReplicationProtectionIntentId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionIntentsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_list_autorest.go new file mode 100644 index 00000000000..d3480ed16aa --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/method_list_autorest.go @@ -0,0 +1,220 @@ +package replicationprotectionintents + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]ReplicationProtectionIntent + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []ReplicationProtectionIntent +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + SkipToken *string + TakeToken *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.SkipToken != nil { + out["skipToken"] = *o.SkipToken + } + + if o.TakeToken != nil { + out["takeToken"] = *o.TakeToken + } + + return out +} + +// List ... +func (c ReplicationProtectionIntentsClient) List(ctx context.Context, id VaultId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationProtectionIntentsClient) preparerForList(ctx context.Context, id VaultId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationProtectionIntents", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationProtectionIntentsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationProtectionIntentsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []ReplicationProtectionIntent `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationprotectionintents.ReplicationProtectionIntentsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationProtectionIntentsClient) ListComplete(ctx context.Context, id VaultId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ReplicationProtectionIntentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationProtectionIntentsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, options ListOperationOptions, predicate ReplicationProtectionIntentOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]ReplicationProtectionIntent, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2acreateprotectionintentinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2acreateprotectionintentinput.go new file mode 100644 index 00000000000..d559110e101 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2acreateprotectionintentinput.go @@ -0,0 +1,143 @@ +package replicationprotectionintents + +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 _ CreateProtectionIntentProviderSpecificDetails = A2ACreateProtectionIntentInput{} + +type A2ACreateProtectionIntentInput struct { + AgentAutoUpdateStatus *AgentAutoUpdateStatus `json:"agentAutoUpdateStatus,omitempty"` + AutoProtectionOfDataDisk *AutoProtectionOfDataDisk `json:"autoProtectionOfDataDisk,omitempty"` + AutomationAccountArmId *string `json:"automationAccountArmId,omitempty"` + AutomationAccountAuthenticationType *AutomationAccountAuthenticationType `json:"automationAccountAuthenticationType,omitempty"` + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + FabricObjectId string `json:"fabricObjectId"` + MultiVMGroupId *string `json:"multiVmGroupId,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + PrimaryLocation string `json:"primaryLocation"` + PrimaryStagingStorageAccountCustomInput StorageAccountCustomDetails `json:"primaryStagingStorageAccountCustomInput"` + ProtectionProfileCustomInput ProtectionProfileCustomDetails `json:"protectionProfileCustomInput"` + RecoveryAvailabilitySetCustomInput RecoveryAvailabilitySetCustomDetails `json:"recoveryAvailabilitySetCustomInput"` + RecoveryAvailabilityType A2ARecoveryAvailabilityType `json:"recoveryAvailabilityType"` + RecoveryAvailabilityZone *string `json:"recoveryAvailabilityZone,omitempty"` + RecoveryBootDiagStorageAccount StorageAccountCustomDetails `json:"recoveryBootDiagStorageAccount"` + RecoveryLocation string `json:"recoveryLocation"` + RecoveryProximityPlacementGroupCustomInput RecoveryProximityPlacementGroupCustomDetails `json:"recoveryProximityPlacementGroupCustomInput"` + RecoveryResourceGroupId string `json:"recoveryResourceGroupId"` + RecoverySubscriptionId string `json:"recoverySubscriptionId"` + RecoveryVirtualNetworkCustomInput RecoveryVirtualNetworkCustomDetails `json:"recoveryVirtualNetworkCustomInput"` + VMDisks *[]A2AProtectionIntentDiskInputDetails `json:"vmDisks,omitempty"` + VMManagedDisks *[]A2AProtectionIntentManagedDiskInputDetails `json:"vmManagedDisks,omitempty"` + + // Fields inherited from CreateProtectionIntentProviderSpecificDetails +} + +var _ json.Marshaler = A2ACreateProtectionIntentInput{} + +func (s A2ACreateProtectionIntentInput) MarshalJSON() ([]byte, error) { + type wrapper A2ACreateProtectionIntentInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2ACreateProtectionIntentInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2ACreateProtectionIntentInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2ACreateProtectionIntentInput: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &A2ACreateProtectionIntentInput{} + +func (s *A2ACreateProtectionIntentInput) UnmarshalJSON(bytes []byte) error { + type alias A2ACreateProtectionIntentInput + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into A2ACreateProtectionIntentInput: %+v", err) + } + + s.AgentAutoUpdateStatus = decoded.AgentAutoUpdateStatus + s.AutoProtectionOfDataDisk = decoded.AutoProtectionOfDataDisk + s.AutomationAccountArmId = decoded.AutomationAccountArmId + s.AutomationAccountAuthenticationType = decoded.AutomationAccountAuthenticationType + s.DiskEncryptionInfo = decoded.DiskEncryptionInfo + s.FabricObjectId = decoded.FabricObjectId + s.MultiVMGroupId = decoded.MultiVMGroupId + s.MultiVMGroupName = decoded.MultiVMGroupName + s.PrimaryLocation = decoded.PrimaryLocation + s.RecoveryAvailabilityType = decoded.RecoveryAvailabilityType + s.RecoveryAvailabilityZone = decoded.RecoveryAvailabilityZone + s.RecoveryLocation = decoded.RecoveryLocation + s.RecoveryResourceGroupId = decoded.RecoveryResourceGroupId + s.RecoverySubscriptionId = decoded.RecoverySubscriptionId + s.VMDisks = decoded.VMDisks + s.VMManagedDisks = decoded.VMManagedDisks + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling A2ACreateProtectionIntentInput into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["primaryStagingStorageAccountCustomInput"]; ok { + impl, err := unmarshalStorageAccountCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'PrimaryStagingStorageAccountCustomInput' for 'A2ACreateProtectionIntentInput': %+v", err) + } + s.PrimaryStagingStorageAccountCustomInput = impl + } + + if v, ok := temp["protectionProfileCustomInput"]; ok { + impl, err := unmarshalProtectionProfileCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProtectionProfileCustomInput' for 'A2ACreateProtectionIntentInput': %+v", err) + } + s.ProtectionProfileCustomInput = impl + } + + if v, ok := temp["recoveryAvailabilitySetCustomInput"]; ok { + impl, err := unmarshalRecoveryAvailabilitySetCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryAvailabilitySetCustomInput' for 'A2ACreateProtectionIntentInput': %+v", err) + } + s.RecoveryAvailabilitySetCustomInput = impl + } + + if v, ok := temp["recoveryBootDiagStorageAccount"]; ok { + impl, err := unmarshalStorageAccountCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryBootDiagStorageAccount' for 'A2ACreateProtectionIntentInput': %+v", err) + } + s.RecoveryBootDiagStorageAccount = impl + } + + if v, ok := temp["recoveryProximityPlacementGroupCustomInput"]; ok { + impl, err := unmarshalRecoveryProximityPlacementGroupCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryProximityPlacementGroupCustomInput' for 'A2ACreateProtectionIntentInput': %+v", err) + } + s.RecoveryProximityPlacementGroupCustomInput = impl + } + + if v, ok := temp["recoveryVirtualNetworkCustomInput"]; ok { + impl, err := unmarshalRecoveryVirtualNetworkCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryVirtualNetworkCustomInput' for 'A2ACreateProtectionIntentInput': %+v", err) + } + s.RecoveryVirtualNetworkCustomInput = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2aprotectionintentdiskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2aprotectionintentdiskinputdetails.go new file mode 100644 index 00000000000..3e73bb8e6f8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2aprotectionintentdiskinputdetails.go @@ -0,0 +1,49 @@ +package replicationprotectionintents + +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 A2AProtectionIntentDiskInputDetails struct { + DiskUri string `json:"diskUri"` + PrimaryStagingStorageAccountCustomInput StorageAccountCustomDetails `json:"primaryStagingStorageAccountCustomInput"` + RecoveryAzureStorageAccountCustomInput StorageAccountCustomDetails `json:"recoveryAzureStorageAccountCustomInput"` +} + +var _ json.Unmarshaler = &A2AProtectionIntentDiskInputDetails{} + +func (s *A2AProtectionIntentDiskInputDetails) UnmarshalJSON(bytes []byte) error { + type alias A2AProtectionIntentDiskInputDetails + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into A2AProtectionIntentDiskInputDetails: %+v", err) + } + + s.DiskUri = decoded.DiskUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling A2AProtectionIntentDiskInputDetails into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["primaryStagingStorageAccountCustomInput"]; ok { + impl, err := unmarshalStorageAccountCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'PrimaryStagingStorageAccountCustomInput' for 'A2AProtectionIntentDiskInputDetails': %+v", err) + } + s.PrimaryStagingStorageAccountCustomInput = impl + } + + if v, ok := temp["recoveryAzureStorageAccountCustomInput"]; ok { + impl, err := unmarshalStorageAccountCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryAzureStorageAccountCustomInput' for 'A2AProtectionIntentDiskInputDetails': %+v", err) + } + s.RecoveryAzureStorageAccountCustomInput = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2aprotectionintentmanageddiskinputdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2aprotectionintentmanageddiskinputdetails.go new file mode 100644 index 00000000000..fdc740a14fb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2aprotectionintentmanageddiskinputdetails.go @@ -0,0 +1,57 @@ +package replicationprotectionintents + +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 A2AProtectionIntentManagedDiskInputDetails struct { + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + DiskId string `json:"diskId"` + PrimaryStagingStorageAccountCustomInput StorageAccountCustomDetails `json:"primaryStagingStorageAccountCustomInput"` + RecoveryDiskEncryptionSetId *string `json:"recoveryDiskEncryptionSetId,omitempty"` + RecoveryReplicaDiskAccountType *string `json:"recoveryReplicaDiskAccountType,omitempty"` + RecoveryResourceGroupCustomInput RecoveryResourceGroupCustomDetails `json:"recoveryResourceGroupCustomInput"` + RecoveryTargetDiskAccountType *string `json:"recoveryTargetDiskAccountType,omitempty"` +} + +var _ json.Unmarshaler = &A2AProtectionIntentManagedDiskInputDetails{} + +func (s *A2AProtectionIntentManagedDiskInputDetails) UnmarshalJSON(bytes []byte) error { + type alias A2AProtectionIntentManagedDiskInputDetails + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into A2AProtectionIntentManagedDiskInputDetails: %+v", err) + } + + s.DiskEncryptionInfo = decoded.DiskEncryptionInfo + s.DiskId = decoded.DiskId + s.RecoveryDiskEncryptionSetId = decoded.RecoveryDiskEncryptionSetId + s.RecoveryReplicaDiskAccountType = decoded.RecoveryReplicaDiskAccountType + s.RecoveryTargetDiskAccountType = decoded.RecoveryTargetDiskAccountType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling A2AProtectionIntentManagedDiskInputDetails into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["primaryStagingStorageAccountCustomInput"]; ok { + impl, err := unmarshalStorageAccountCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'PrimaryStagingStorageAccountCustomInput' for 'A2AProtectionIntentManagedDiskInputDetails': %+v", err) + } + s.PrimaryStagingStorageAccountCustomInput = impl + } + + if v, ok := temp["recoveryResourceGroupCustomInput"]; ok { + impl, err := unmarshalRecoveryResourceGroupCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryResourceGroupCustomInput' for 'A2AProtectionIntentManagedDiskInputDetails': %+v", err) + } + s.RecoveryResourceGroupCustomInput = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2areplicationintentdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2areplicationintentdetails.go new file mode 100644 index 00000000000..9605642ee8d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_a2areplicationintentdetails.go @@ -0,0 +1,143 @@ +package replicationprotectionintents + +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 _ ReplicationProtectionIntentProviderSpecificSettings = A2AReplicationIntentDetails{} + +type A2AReplicationIntentDetails struct { + AgentAutoUpdateStatus *AgentAutoUpdateStatus `json:"agentAutoUpdateStatus,omitempty"` + AutoProtectionOfDataDisk *AutoProtectionOfDataDisk `json:"autoProtectionOfDataDisk,omitempty"` + AutomationAccountArmId *string `json:"automationAccountArmId,omitempty"` + AutomationAccountAuthenticationType *AutomationAccountAuthenticationType `json:"automationAccountAuthenticationType,omitempty"` + DiskEncryptionInfo *DiskEncryptionInfo `json:"diskEncryptionInfo,omitempty"` + FabricObjectId *string `json:"fabricObjectId,omitempty"` + MultiVMGroupId *string `json:"multiVmGroupId,omitempty"` + MultiVMGroupName *string `json:"multiVmGroupName,omitempty"` + PrimaryLocation *string `json:"primaryLocation,omitempty"` + PrimaryStagingStorageAccount StorageAccountCustomDetails `json:"primaryStagingStorageAccount"` + ProtectionProfile ProtectionProfileCustomDetails `json:"protectionProfile"` + RecoveryAvailabilitySet RecoveryAvailabilitySetCustomDetails `json:"recoveryAvailabilitySet"` + RecoveryAvailabilityType string `json:"recoveryAvailabilityType"` + RecoveryAvailabilityZone *string `json:"recoveryAvailabilityZone,omitempty"` + RecoveryBootDiagStorageAccount StorageAccountCustomDetails `json:"recoveryBootDiagStorageAccount"` + RecoveryLocation *string `json:"recoveryLocation,omitempty"` + RecoveryProximityPlacementGroup RecoveryProximityPlacementGroupCustomDetails `json:"recoveryProximityPlacementGroup"` + RecoveryResourceGroupId *string `json:"recoveryResourceGroupId,omitempty"` + RecoverySubscriptionId *string `json:"recoverySubscriptionId,omitempty"` + RecoveryVirtualNetwork RecoveryVirtualNetworkCustomDetails `json:"recoveryVirtualNetwork"` + VMDisks *[]A2AProtectionIntentDiskInputDetails `json:"vmDisks,omitempty"` + VMManagedDisks *[]A2AProtectionIntentManagedDiskInputDetails `json:"vmManagedDisks,omitempty"` + + // Fields inherited from ReplicationProtectionIntentProviderSpecificSettings +} + +var _ json.Marshaler = A2AReplicationIntentDetails{} + +func (s A2AReplicationIntentDetails) MarshalJSON() ([]byte, error) { + type wrapper A2AReplicationIntentDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling A2AReplicationIntentDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling A2AReplicationIntentDetails: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling A2AReplicationIntentDetails: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &A2AReplicationIntentDetails{} + +func (s *A2AReplicationIntentDetails) UnmarshalJSON(bytes []byte) error { + type alias A2AReplicationIntentDetails + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into A2AReplicationIntentDetails: %+v", err) + } + + s.AgentAutoUpdateStatus = decoded.AgentAutoUpdateStatus + s.AutoProtectionOfDataDisk = decoded.AutoProtectionOfDataDisk + s.AutomationAccountArmId = decoded.AutomationAccountArmId + s.AutomationAccountAuthenticationType = decoded.AutomationAccountAuthenticationType + s.DiskEncryptionInfo = decoded.DiskEncryptionInfo + s.FabricObjectId = decoded.FabricObjectId + s.MultiVMGroupId = decoded.MultiVMGroupId + s.MultiVMGroupName = decoded.MultiVMGroupName + s.PrimaryLocation = decoded.PrimaryLocation + s.RecoveryAvailabilityType = decoded.RecoveryAvailabilityType + s.RecoveryAvailabilityZone = decoded.RecoveryAvailabilityZone + s.RecoveryLocation = decoded.RecoveryLocation + s.RecoveryResourceGroupId = decoded.RecoveryResourceGroupId + s.RecoverySubscriptionId = decoded.RecoverySubscriptionId + s.VMDisks = decoded.VMDisks + s.VMManagedDisks = decoded.VMManagedDisks + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling A2AReplicationIntentDetails into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["primaryStagingStorageAccount"]; ok { + impl, err := unmarshalStorageAccountCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'PrimaryStagingStorageAccount' for 'A2AReplicationIntentDetails': %+v", err) + } + s.PrimaryStagingStorageAccount = impl + } + + if v, ok := temp["protectionProfile"]; ok { + impl, err := unmarshalProtectionProfileCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProtectionProfile' for 'A2AReplicationIntentDetails': %+v", err) + } + s.ProtectionProfile = impl + } + + if v, ok := temp["recoveryAvailabilitySet"]; ok { + impl, err := unmarshalRecoveryAvailabilitySetCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryAvailabilitySet' for 'A2AReplicationIntentDetails': %+v", err) + } + s.RecoveryAvailabilitySet = impl + } + + if v, ok := temp["recoveryBootDiagStorageAccount"]; ok { + impl, err := unmarshalStorageAccountCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryBootDiagStorageAccount' for 'A2AReplicationIntentDetails': %+v", err) + } + s.RecoveryBootDiagStorageAccount = impl + } + + if v, ok := temp["recoveryProximityPlacementGroup"]; ok { + impl, err := unmarshalRecoveryProximityPlacementGroupCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryProximityPlacementGroup' for 'A2AReplicationIntentDetails': %+v", err) + } + s.RecoveryProximityPlacementGroup = impl + } + + if v, ok := temp["recoveryVirtualNetwork"]; ok { + impl, err := unmarshalRecoveryVirtualNetworkCustomDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RecoveryVirtualNetwork' for 'A2AReplicationIntentDetails': %+v", err) + } + s.RecoveryVirtualNetwork = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentinput.go new file mode 100644 index 00000000000..043880b900a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentinput.go @@ -0,0 +1,8 @@ +package replicationprotectionintents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateProtectionIntentInput struct { + Properties *CreateProtectionIntentProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentproperties.go new file mode 100644 index 00000000000..82abb10ea69 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentproperties.go @@ -0,0 +1,32 @@ +package replicationprotectionintents + +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 CreateProtectionIntentProperties struct { + ProviderSpecificDetails CreateProtectionIntentProviderSpecificDetails `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &CreateProtectionIntentProperties{} + +func (s *CreateProtectionIntentProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CreateProtectionIntentProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalCreateProtectionIntentProviderSpecificDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'CreateProtectionIntentProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentproviderspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentproviderspecificdetails.go new file mode 100644 index 00000000000..5cd729852d6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_createprotectionintentproviderspecificdetails.go @@ -0,0 +1,48 @@ +package replicationprotectionintents + +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 CreateProtectionIntentProviderSpecificDetails interface { +} + +func unmarshalCreateProtectionIntentProviderSpecificDetailsImplementation(input []byte) (CreateProtectionIntentProviderSpecificDetails, 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 CreateProtectionIntentProviderSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2ACreateProtectionIntentInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2ACreateProtectionIntentInput: %+v", err) + } + return out, nil + } + + type RawCreateProtectionIntentProviderSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawCreateProtectionIntentProviderSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_diskencryptioninfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_diskencryptioninfo.go new file mode 100644 index 00000000000..bbe499d7f6b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_diskencryptioninfo.go @@ -0,0 +1,9 @@ +package replicationprotectionintents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionInfo struct { + DiskEncryptionKeyInfo *DiskEncryptionKeyInfo `json:"diskEncryptionKeyInfo,omitempty"` + KeyEncryptionKeyInfo *KeyEncryptionKeyInfo `json:"keyEncryptionKeyInfo,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_diskencryptionkeyinfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_diskencryptionkeyinfo.go new file mode 100644 index 00000000000..1043673141e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_diskencryptionkeyinfo.go @@ -0,0 +1,9 @@ +package replicationprotectionintents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionKeyInfo struct { + KeyVaultResourceArmId *string `json:"keyVaultResourceArmId,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingprotectionprofile.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingprotectionprofile.go new file mode 100644 index 00000000000..dbee810013d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingprotectionprofile.go @@ -0,0 +1,41 @@ +package replicationprotectionintents + +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 _ ProtectionProfileCustomDetails = ExistingProtectionProfile{} + +type ExistingProtectionProfile struct { + ProtectionProfileId string `json:"protectionProfileId"` + + // Fields inherited from ProtectionProfileCustomDetails +} + +var _ json.Marshaler = ExistingProtectionProfile{} + +func (s ExistingProtectionProfile) MarshalJSON() ([]byte, error) { + type wrapper ExistingProtectionProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ExistingProtectionProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ExistingProtectionProfile: %+v", err) + } + decoded["resourceType"] = "Existing" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ExistingProtectionProfile: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryavailabilityset.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryavailabilityset.go new file mode 100644 index 00000000000..aa58d2d31a6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryavailabilityset.go @@ -0,0 +1,41 @@ +package replicationprotectionintents + +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 _ RecoveryAvailabilitySetCustomDetails = ExistingRecoveryAvailabilitySet{} + +type ExistingRecoveryAvailabilitySet struct { + RecoveryAvailabilitySetId *string `json:"recoveryAvailabilitySetId,omitempty"` + + // Fields inherited from RecoveryAvailabilitySetCustomDetails +} + +var _ json.Marshaler = ExistingRecoveryAvailabilitySet{} + +func (s ExistingRecoveryAvailabilitySet) MarshalJSON() ([]byte, error) { + type wrapper ExistingRecoveryAvailabilitySet + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ExistingRecoveryAvailabilitySet: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ExistingRecoveryAvailabilitySet: %+v", err) + } + decoded["resourceType"] = "Existing" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ExistingRecoveryAvailabilitySet: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryproximityplacementgroup.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryproximityplacementgroup.go new file mode 100644 index 00000000000..e09469c79bc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryproximityplacementgroup.go @@ -0,0 +1,41 @@ +package replicationprotectionintents + +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 _ RecoveryProximityPlacementGroupCustomDetails = ExistingRecoveryProximityPlacementGroup{} + +type ExistingRecoveryProximityPlacementGroup struct { + RecoveryProximityPlacementGroupId *string `json:"recoveryProximityPlacementGroupId,omitempty"` + + // Fields inherited from RecoveryProximityPlacementGroupCustomDetails +} + +var _ json.Marshaler = ExistingRecoveryProximityPlacementGroup{} + +func (s ExistingRecoveryProximityPlacementGroup) MarshalJSON() ([]byte, error) { + type wrapper ExistingRecoveryProximityPlacementGroup + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ExistingRecoveryProximityPlacementGroup: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ExistingRecoveryProximityPlacementGroup: %+v", err) + } + decoded["resourceType"] = "Existing" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ExistingRecoveryProximityPlacementGroup: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryrecoveryresourcegroup.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryrecoveryresourcegroup.go new file mode 100644 index 00000000000..05d6e88d647 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryrecoveryresourcegroup.go @@ -0,0 +1,41 @@ +package replicationprotectionintents + +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 _ RecoveryResourceGroupCustomDetails = ExistingRecoveryRecoveryResourceGroup{} + +type ExistingRecoveryRecoveryResourceGroup struct { + RecoveryResourceGroupId *string `json:"recoveryResourceGroupId,omitempty"` + + // Fields inherited from RecoveryResourceGroupCustomDetails +} + +var _ json.Marshaler = ExistingRecoveryRecoveryResourceGroup{} + +func (s ExistingRecoveryRecoveryResourceGroup) MarshalJSON() ([]byte, error) { + type wrapper ExistingRecoveryRecoveryResourceGroup + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ExistingRecoveryRecoveryResourceGroup: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ExistingRecoveryRecoveryResourceGroup: %+v", err) + } + decoded["resourceType"] = "Existing" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ExistingRecoveryRecoveryResourceGroup: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryvirtualnetwork.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryvirtualnetwork.go new file mode 100644 index 00000000000..a8524773f2d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingrecoveryvirtualnetwork.go @@ -0,0 +1,42 @@ +package replicationprotectionintents + +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 _ RecoveryVirtualNetworkCustomDetails = ExistingRecoveryVirtualNetwork{} + +type ExistingRecoveryVirtualNetwork struct { + RecoverySubnetName *string `json:"recoverySubnetName,omitempty"` + RecoveryVirtualNetworkId string `json:"recoveryVirtualNetworkId"` + + // Fields inherited from RecoveryVirtualNetworkCustomDetails +} + +var _ json.Marshaler = ExistingRecoveryVirtualNetwork{} + +func (s ExistingRecoveryVirtualNetwork) MarshalJSON() ([]byte, error) { + type wrapper ExistingRecoveryVirtualNetwork + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ExistingRecoveryVirtualNetwork: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ExistingRecoveryVirtualNetwork: %+v", err) + } + decoded["resourceType"] = "Existing" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ExistingRecoveryVirtualNetwork: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingstorageaccount.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingstorageaccount.go new file mode 100644 index 00000000000..4150f1c78d0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_existingstorageaccount.go @@ -0,0 +1,41 @@ +package replicationprotectionintents + +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 _ StorageAccountCustomDetails = ExistingStorageAccount{} + +type ExistingStorageAccount struct { + AzureStorageAccountId string `json:"azureStorageAccountId"` + + // Fields inherited from StorageAccountCustomDetails +} + +var _ json.Marshaler = ExistingStorageAccount{} + +func (s ExistingStorageAccount) MarshalJSON() ([]byte, error) { + type wrapper ExistingStorageAccount + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ExistingStorageAccount: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ExistingStorageAccount: %+v", err) + } + decoded["resourceType"] = "Existing" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ExistingStorageAccount: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_keyencryptionkeyinfo.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_keyencryptionkeyinfo.go new file mode 100644 index 00000000000..b4a8b6e0c54 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_keyencryptionkeyinfo.go @@ -0,0 +1,9 @@ +package replicationprotectionintents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyEncryptionKeyInfo struct { + KeyIdentifier *string `json:"keyIdentifier,omitempty"` + KeyVaultResourceArmId *string `json:"keyVaultResourceArmId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_newprotectionprofile.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_newprotectionprofile.go new file mode 100644 index 00000000000..9763db731fd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_newprotectionprofile.go @@ -0,0 +1,45 @@ +package replicationprotectionintents + +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 _ ProtectionProfileCustomDetails = NewProtectionProfile{} + +type NewProtectionProfile struct { + AppConsistentFrequencyInMinutes *int64 `json:"appConsistentFrequencyInMinutes,omitempty"` + CrashConsistentFrequencyInMinutes *int64 `json:"crashConsistentFrequencyInMinutes,omitempty"` + MultiVMSyncStatus SetMultiVMSyncStatus `json:"multiVmSyncStatus"` + PolicyName string `json:"policyName"` + RecoveryPointHistory *int64 `json:"recoveryPointHistory,omitempty"` + + // Fields inherited from ProtectionProfileCustomDetails +} + +var _ json.Marshaler = NewProtectionProfile{} + +func (s NewProtectionProfile) MarshalJSON() ([]byte, error) { + type wrapper NewProtectionProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NewProtectionProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NewProtectionProfile: %+v", err) + } + decoded["resourceType"] = "New" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NewProtectionProfile: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_newrecoveryvirtualnetwork.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_newrecoveryvirtualnetwork.go new file mode 100644 index 00000000000..37ff485101c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_newrecoveryvirtualnetwork.go @@ -0,0 +1,42 @@ +package replicationprotectionintents + +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 _ RecoveryVirtualNetworkCustomDetails = NewRecoveryVirtualNetwork{} + +type NewRecoveryVirtualNetwork struct { + RecoveryVirtualNetworkName *string `json:"recoveryVirtualNetworkName,omitempty"` + RecoveryVirtualNetworkResourceGroupName *string `json:"recoveryVirtualNetworkResourceGroupName,omitempty"` + + // Fields inherited from RecoveryVirtualNetworkCustomDetails +} + +var _ json.Marshaler = NewRecoveryVirtualNetwork{} + +func (s NewRecoveryVirtualNetwork) MarshalJSON() ([]byte, error) { + type wrapper NewRecoveryVirtualNetwork + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NewRecoveryVirtualNetwork: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NewRecoveryVirtualNetwork: %+v", err) + } + decoded["resourceType"] = "New" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NewRecoveryVirtualNetwork: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_protectionprofilecustomdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_protectionprofilecustomdetails.go new file mode 100644 index 00000000000..45c36e6f317 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_protectionprofilecustomdetails.go @@ -0,0 +1,56 @@ +package replicationprotectionintents + +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 ProtectionProfileCustomDetails interface { +} + +func unmarshalProtectionProfileCustomDetailsImplementation(input []byte) (ProtectionProfileCustomDetails, 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 ProtectionProfileCustomDetails into map[string]interface: %+v", err) + } + + value, ok := temp["resourceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Existing") { + var out ExistingProtectionProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ExistingProtectionProfile: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "New") { + var out NewProtectionProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NewProtectionProfile: %+v", err) + } + return out, nil + } + + type RawProtectionProfileCustomDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawProtectionProfileCustomDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryavailabilitysetcustomdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryavailabilitysetcustomdetails.go new file mode 100644 index 00000000000..39512dee706 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryavailabilitysetcustomdetails.go @@ -0,0 +1,48 @@ +package replicationprotectionintents + +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 RecoveryAvailabilitySetCustomDetails interface { +} + +func unmarshalRecoveryAvailabilitySetCustomDetailsImplementation(input []byte) (RecoveryAvailabilitySetCustomDetails, 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 RecoveryAvailabilitySetCustomDetails into map[string]interface: %+v", err) + } + + value, ok := temp["resourceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Existing") { + var out ExistingRecoveryAvailabilitySet + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ExistingRecoveryAvailabilitySet: %+v", err) + } + return out, nil + } + + type RawRecoveryAvailabilitySetCustomDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryAvailabilitySetCustomDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryproximityplacementgroupcustomdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryproximityplacementgroupcustomdetails.go new file mode 100644 index 00000000000..c626b69a65c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryproximityplacementgroupcustomdetails.go @@ -0,0 +1,48 @@ +package replicationprotectionintents + +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 RecoveryProximityPlacementGroupCustomDetails interface { +} + +func unmarshalRecoveryProximityPlacementGroupCustomDetailsImplementation(input []byte) (RecoveryProximityPlacementGroupCustomDetails, 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 RecoveryProximityPlacementGroupCustomDetails into map[string]interface: %+v", err) + } + + value, ok := temp["resourceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Existing") { + var out ExistingRecoveryProximityPlacementGroup + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ExistingRecoveryProximityPlacementGroup: %+v", err) + } + return out, nil + } + + type RawRecoveryProximityPlacementGroupCustomDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryProximityPlacementGroupCustomDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryresourcegroupcustomdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryresourcegroupcustomdetails.go new file mode 100644 index 00000000000..f5f6b52e830 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryresourcegroupcustomdetails.go @@ -0,0 +1,48 @@ +package replicationprotectionintents + +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 RecoveryResourceGroupCustomDetails interface { +} + +func unmarshalRecoveryResourceGroupCustomDetailsImplementation(input []byte) (RecoveryResourceGroupCustomDetails, 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 RecoveryResourceGroupCustomDetails into map[string]interface: %+v", err) + } + + value, ok := temp["resourceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Existing") { + var out ExistingRecoveryRecoveryResourceGroup + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ExistingRecoveryRecoveryResourceGroup: %+v", err) + } + return out, nil + } + + type RawRecoveryResourceGroupCustomDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryResourceGroupCustomDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryvirtualnetworkcustomdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryvirtualnetworkcustomdetails.go new file mode 100644 index 00000000000..933bb4766f1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_recoveryvirtualnetworkcustomdetails.go @@ -0,0 +1,56 @@ +package replicationprotectionintents + +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 RecoveryVirtualNetworkCustomDetails interface { +} + +func unmarshalRecoveryVirtualNetworkCustomDetailsImplementation(input []byte) (RecoveryVirtualNetworkCustomDetails, 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 RecoveryVirtualNetworkCustomDetails into map[string]interface: %+v", err) + } + + value, ok := temp["resourceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Existing") { + var out ExistingRecoveryVirtualNetwork + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ExistingRecoveryVirtualNetwork: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "New") { + var out NewRecoveryVirtualNetwork + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NewRecoveryVirtualNetwork: %+v", err) + } + return out, nil + } + + type RawRecoveryVirtualNetworkCustomDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryVirtualNetworkCustomDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintent.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintent.go new file mode 100644 index 00000000000..1fbffaaf5ab --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintent.go @@ -0,0 +1,12 @@ +package replicationprotectionintents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectionIntent struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ReplicationProtectionIntentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintentproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintentproperties.go new file mode 100644 index 00000000000..5e15949e0fe --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintentproperties.go @@ -0,0 +1,48 @@ +package replicationprotectionintents + +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 ReplicationProtectionIntentProperties struct { + CreationTimeUTC *string `json:"creationTimeUTC,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IsActive *bool `json:"isActive,omitempty"` + JobId *string `json:"jobId,omitempty"` + JobState *string `json:"jobState,omitempty"` + ProviderSpecificDetails ReplicationProtectionIntentProviderSpecificSettings `json:"providerSpecificDetails"` +} + +var _ json.Unmarshaler = &ReplicationProtectionIntentProperties{} + +func (s *ReplicationProtectionIntentProperties) UnmarshalJSON(bytes []byte) error { + type alias ReplicationProtectionIntentProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ReplicationProtectionIntentProperties: %+v", err) + } + + s.CreationTimeUTC = decoded.CreationTimeUTC + s.FriendlyName = decoded.FriendlyName + s.IsActive = decoded.IsActive + s.JobId = decoded.JobId + s.JobState = decoded.JobState + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ReplicationProtectionIntentProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + impl, err := unmarshalReplicationProtectionIntentProviderSpecificSettingsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ProviderSpecificDetails' for 'ReplicationProtectionIntentProperties': %+v", err) + } + s.ProviderSpecificDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintentproviderspecificsettings.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintentproviderspecificsettings.go new file mode 100644 index 00000000000..789adef4a4c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_replicationprotectionintentproviderspecificsettings.go @@ -0,0 +1,48 @@ +package replicationprotectionintents + +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 ReplicationProtectionIntentProviderSpecificSettings interface { +} + +func unmarshalReplicationProtectionIntentProviderSpecificSettingsImplementation(input []byte) (ReplicationProtectionIntentProviderSpecificSettings, 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 ReplicationProtectionIntentProviderSpecificSettings into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out A2AReplicationIntentDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into A2AReplicationIntentDetails: %+v", err) + } + return out, nil + } + + type RawReplicationProtectionIntentProviderSpecificSettingsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawReplicationProtectionIntentProviderSpecificSettingsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_storageaccountcustomdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_storageaccountcustomdetails.go new file mode 100644 index 00000000000..0f52adbc7f5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/model_storageaccountcustomdetails.go @@ -0,0 +1,48 @@ +package replicationprotectionintents + +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 StorageAccountCustomDetails interface { +} + +func unmarshalStorageAccountCustomDetailsImplementation(input []byte) (StorageAccountCustomDetails, 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 StorageAccountCustomDetails into map[string]interface: %+v", err) + } + + value, ok := temp["resourceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Existing") { + var out ExistingStorageAccount + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ExistingStorageAccount: %+v", err) + } + return out, nil + } + + type RawStorageAccountCustomDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawStorageAccountCustomDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/predicates.go new file mode 100644 index 00000000000..460c9a788a7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/predicates.go @@ -0,0 +1,32 @@ +package replicationprotectionintents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProtectionIntentOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ReplicationProtectionIntentOperationPredicate) Matches(input ReplicationProtectionIntent) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/version.go new file mode 100644 index 00000000000..89d0f7dced6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationprotectionintents/version.go @@ -0,0 +1,12 @@ +package replicationprotectionintents + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationprotectionintents/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/README.md new file mode 100644 index 00000000000..81b32df6c93 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/README.md @@ -0,0 +1,203 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans` Documentation + +The `replicationrecoveryplans` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans" +``` + + +### Client Initialization + +```go +client := replicationrecoveryplans.NewReplicationRecoveryPlansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.Create` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +payload := replicationrecoveryplans.CreateRecoveryPlanInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.Delete` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.FailoverCancel` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +if err := client.FailoverCancelThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.FailoverCommit` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +if err := client.FailoverCommitThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.Get` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +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: `ReplicationRecoveryPlansClient.List` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationRecoveryPlansClient.PlannedFailover` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +payload := replicationrecoveryplans.RecoveryPlanPlannedFailoverInput{ + // ... +} + + +if err := client.PlannedFailoverThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.Reprotect` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +if err := client.ReprotectThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.TestFailover` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +payload := replicationrecoveryplans.RecoveryPlanTestFailoverInput{ + // ... +} + + +if err := client.TestFailoverThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.TestFailoverCleanup` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +payload := replicationrecoveryplans.RecoveryPlanTestFailoverCleanupInput{ + // ... +} + + +if err := client.TestFailoverCleanupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.UnplannedFailover` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +payload := replicationrecoveryplans.RecoveryPlanUnplannedFailoverInput{ + // ... +} + + +if err := client.UnplannedFailoverThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryPlansClient.Update` + +```go +ctx := context.TODO() +id := replicationrecoveryplans.NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + +payload := replicationrecoveryplans.UpdateRecoveryPlanInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/client.go new file mode 100644 index 00000000000..bdf1aa2d8f6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/client.go @@ -0,0 +1,18 @@ +package replicationrecoveryplans + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationRecoveryPlansClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationRecoveryPlansClientWithBaseURI(endpoint string) ReplicationRecoveryPlansClient { + return ReplicationRecoveryPlansClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/constants.go new file mode 100644 index 00000000000..2f084ce76b5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/constants.go @@ -0,0 +1,492 @@ +package replicationrecoveryplans + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type A2ARpRecoveryPointType string + +const ( + A2ARpRecoveryPointTypeLatest A2ARpRecoveryPointType = "Latest" + A2ARpRecoveryPointTypeLatestApplicationConsistent A2ARpRecoveryPointType = "LatestApplicationConsistent" + A2ARpRecoveryPointTypeLatestCrashConsistent A2ARpRecoveryPointType = "LatestCrashConsistent" + A2ARpRecoveryPointTypeLatestProcessed A2ARpRecoveryPointType = "LatestProcessed" +) + +func PossibleValuesForA2ARpRecoveryPointType() []string { + return []string{ + string(A2ARpRecoveryPointTypeLatest), + string(A2ARpRecoveryPointTypeLatestApplicationConsistent), + string(A2ARpRecoveryPointTypeLatestCrashConsistent), + string(A2ARpRecoveryPointTypeLatestProcessed), + } +} + +func parseA2ARpRecoveryPointType(input string) (*A2ARpRecoveryPointType, error) { + vals := map[string]A2ARpRecoveryPointType{ + "latest": A2ARpRecoveryPointTypeLatest, + "latestapplicationconsistent": A2ARpRecoveryPointTypeLatestApplicationConsistent, + "latestcrashconsistent": A2ARpRecoveryPointTypeLatestCrashConsistent, + "latestprocessed": A2ARpRecoveryPointTypeLatestProcessed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := A2ARpRecoveryPointType(input) + return &out, nil +} + +type AlternateLocationRecoveryOption string + +const ( + AlternateLocationRecoveryOptionCreateVMIfNotFound AlternateLocationRecoveryOption = "CreateVmIfNotFound" + AlternateLocationRecoveryOptionNoAction AlternateLocationRecoveryOption = "NoAction" +) + +func PossibleValuesForAlternateLocationRecoveryOption() []string { + return []string{ + string(AlternateLocationRecoveryOptionCreateVMIfNotFound), + string(AlternateLocationRecoveryOptionNoAction), + } +} + +func parseAlternateLocationRecoveryOption(input string) (*AlternateLocationRecoveryOption, error) { + vals := map[string]AlternateLocationRecoveryOption{ + "createvmifnotfound": AlternateLocationRecoveryOptionCreateVMIfNotFound, + "noaction": AlternateLocationRecoveryOptionNoAction, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlternateLocationRecoveryOption(input) + return &out, nil +} + +type DataSyncStatus string + +const ( + DataSyncStatusForDownTime DataSyncStatus = "ForDownTime" + DataSyncStatusForSynchronization DataSyncStatus = "ForSynchronization" +) + +func PossibleValuesForDataSyncStatus() []string { + return []string{ + string(DataSyncStatusForDownTime), + string(DataSyncStatusForSynchronization), + } +} + +func parseDataSyncStatus(input string) (*DataSyncStatus, error) { + vals := map[string]DataSyncStatus{ + "fordowntime": DataSyncStatusForDownTime, + "forsynchronization": DataSyncStatusForSynchronization, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataSyncStatus(input) + return &out, nil +} + +type FailoverDeploymentModel string + +const ( + FailoverDeploymentModelClassic FailoverDeploymentModel = "Classic" + FailoverDeploymentModelNotApplicable FailoverDeploymentModel = "NotApplicable" + FailoverDeploymentModelResourceManager FailoverDeploymentModel = "ResourceManager" +) + +func PossibleValuesForFailoverDeploymentModel() []string { + return []string{ + string(FailoverDeploymentModelClassic), + string(FailoverDeploymentModelNotApplicable), + string(FailoverDeploymentModelResourceManager), + } +} + +func parseFailoverDeploymentModel(input string) (*FailoverDeploymentModel, error) { + vals := map[string]FailoverDeploymentModel{ + "classic": FailoverDeploymentModelClassic, + "notapplicable": FailoverDeploymentModelNotApplicable, + "resourcemanager": FailoverDeploymentModelResourceManager, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FailoverDeploymentModel(input) + return &out, nil +} + +type HyperVReplicaAzureRpRecoveryPointType string + +const ( + HyperVReplicaAzureRpRecoveryPointTypeLatest HyperVReplicaAzureRpRecoveryPointType = "Latest" + HyperVReplicaAzureRpRecoveryPointTypeLatestApplicationConsistent HyperVReplicaAzureRpRecoveryPointType = "LatestApplicationConsistent" + HyperVReplicaAzureRpRecoveryPointTypeLatestProcessed HyperVReplicaAzureRpRecoveryPointType = "LatestProcessed" +) + +func PossibleValuesForHyperVReplicaAzureRpRecoveryPointType() []string { + return []string{ + string(HyperVReplicaAzureRpRecoveryPointTypeLatest), + string(HyperVReplicaAzureRpRecoveryPointTypeLatestApplicationConsistent), + string(HyperVReplicaAzureRpRecoveryPointTypeLatestProcessed), + } +} + +func parseHyperVReplicaAzureRpRecoveryPointType(input string) (*HyperVReplicaAzureRpRecoveryPointType, error) { + vals := map[string]HyperVReplicaAzureRpRecoveryPointType{ + "latest": HyperVReplicaAzureRpRecoveryPointTypeLatest, + "latestapplicationconsistent": HyperVReplicaAzureRpRecoveryPointTypeLatestApplicationConsistent, + "latestprocessed": HyperVReplicaAzureRpRecoveryPointTypeLatestProcessed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HyperVReplicaAzureRpRecoveryPointType(input) + return &out, nil +} + +type InMageRcmFailbackRecoveryPointType string + +const ( + InMageRcmFailbackRecoveryPointTypeApplicationConsistent InMageRcmFailbackRecoveryPointType = "ApplicationConsistent" + InMageRcmFailbackRecoveryPointTypeCrashConsistent InMageRcmFailbackRecoveryPointType = "CrashConsistent" +) + +func PossibleValuesForInMageRcmFailbackRecoveryPointType() []string { + return []string{ + string(InMageRcmFailbackRecoveryPointTypeApplicationConsistent), + string(InMageRcmFailbackRecoveryPointTypeCrashConsistent), + } +} + +func parseInMageRcmFailbackRecoveryPointType(input string) (*InMageRcmFailbackRecoveryPointType, error) { + vals := map[string]InMageRcmFailbackRecoveryPointType{ + "applicationconsistent": InMageRcmFailbackRecoveryPointTypeApplicationConsistent, + "crashconsistent": InMageRcmFailbackRecoveryPointTypeCrashConsistent, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InMageRcmFailbackRecoveryPointType(input) + return &out, nil +} + +type InMageV2RpRecoveryPointType string + +const ( + InMageV2RpRecoveryPointTypeLatest InMageV2RpRecoveryPointType = "Latest" + InMageV2RpRecoveryPointTypeLatestApplicationConsistent InMageV2RpRecoveryPointType = "LatestApplicationConsistent" + InMageV2RpRecoveryPointTypeLatestCrashConsistent InMageV2RpRecoveryPointType = "LatestCrashConsistent" + InMageV2RpRecoveryPointTypeLatestProcessed InMageV2RpRecoveryPointType = "LatestProcessed" +) + +func PossibleValuesForInMageV2RpRecoveryPointType() []string { + return []string{ + string(InMageV2RpRecoveryPointTypeLatest), + string(InMageV2RpRecoveryPointTypeLatestApplicationConsistent), + string(InMageV2RpRecoveryPointTypeLatestCrashConsistent), + string(InMageV2RpRecoveryPointTypeLatestProcessed), + } +} + +func parseInMageV2RpRecoveryPointType(input string) (*InMageV2RpRecoveryPointType, error) { + vals := map[string]InMageV2RpRecoveryPointType{ + "latest": InMageV2RpRecoveryPointTypeLatest, + "latestapplicationconsistent": InMageV2RpRecoveryPointTypeLatestApplicationConsistent, + "latestcrashconsistent": InMageV2RpRecoveryPointTypeLatestCrashConsistent, + "latestprocessed": InMageV2RpRecoveryPointTypeLatestProcessed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InMageV2RpRecoveryPointType(input) + return &out, nil +} + +type MultiVMSyncPointOption string + +const ( + MultiVMSyncPointOptionUseMultiVMSyncRecoveryPoint MultiVMSyncPointOption = "UseMultiVmSyncRecoveryPoint" + MultiVMSyncPointOptionUsePerVMRecoveryPoint MultiVMSyncPointOption = "UsePerVmRecoveryPoint" +) + +func PossibleValuesForMultiVMSyncPointOption() []string { + return []string{ + string(MultiVMSyncPointOptionUseMultiVMSyncRecoveryPoint), + string(MultiVMSyncPointOptionUsePerVMRecoveryPoint), + } +} + +func parseMultiVMSyncPointOption(input string) (*MultiVMSyncPointOption, error) { + vals := map[string]MultiVMSyncPointOption{ + "usemultivmsyncrecoverypoint": MultiVMSyncPointOptionUseMultiVMSyncRecoveryPoint, + "usepervmrecoverypoint": MultiVMSyncPointOptionUsePerVMRecoveryPoint, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MultiVMSyncPointOption(input) + return &out, nil +} + +type PossibleOperationsDirections string + +const ( + PossibleOperationsDirectionsPrimaryToRecovery PossibleOperationsDirections = "PrimaryToRecovery" + PossibleOperationsDirectionsRecoveryToPrimary PossibleOperationsDirections = "RecoveryToPrimary" +) + +func PossibleValuesForPossibleOperationsDirections() []string { + return []string{ + string(PossibleOperationsDirectionsPrimaryToRecovery), + string(PossibleOperationsDirectionsRecoveryToPrimary), + } +} + +func parsePossibleOperationsDirections(input string) (*PossibleOperationsDirections, error) { + vals := map[string]PossibleOperationsDirections{ + "primarytorecovery": PossibleOperationsDirectionsPrimaryToRecovery, + "recoverytoprimary": PossibleOperationsDirectionsRecoveryToPrimary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PossibleOperationsDirections(input) + return &out, nil +} + +type RecoveryPlanActionLocation string + +const ( + RecoveryPlanActionLocationPrimary RecoveryPlanActionLocation = "Primary" + RecoveryPlanActionLocationRecovery RecoveryPlanActionLocation = "Recovery" +) + +func PossibleValuesForRecoveryPlanActionLocation() []string { + return []string{ + string(RecoveryPlanActionLocationPrimary), + string(RecoveryPlanActionLocationRecovery), + } +} + +func parseRecoveryPlanActionLocation(input string) (*RecoveryPlanActionLocation, error) { + vals := map[string]RecoveryPlanActionLocation{ + "primary": RecoveryPlanActionLocationPrimary, + "recovery": RecoveryPlanActionLocationRecovery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPlanActionLocation(input) + return &out, nil +} + +type RecoveryPlanGroupType string + +const ( + RecoveryPlanGroupTypeBoot RecoveryPlanGroupType = "Boot" + RecoveryPlanGroupTypeFailover RecoveryPlanGroupType = "Failover" + RecoveryPlanGroupTypeShutdown RecoveryPlanGroupType = "Shutdown" +) + +func PossibleValuesForRecoveryPlanGroupType() []string { + return []string{ + string(RecoveryPlanGroupTypeBoot), + string(RecoveryPlanGroupTypeFailover), + string(RecoveryPlanGroupTypeShutdown), + } +} + +func parseRecoveryPlanGroupType(input string) (*RecoveryPlanGroupType, error) { + vals := map[string]RecoveryPlanGroupType{ + "boot": RecoveryPlanGroupTypeBoot, + "failover": RecoveryPlanGroupTypeFailover, + "shutdown": RecoveryPlanGroupTypeShutdown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPlanGroupType(input) + return &out, nil +} + +type RecoveryPlanPointType string + +const ( + RecoveryPlanPointTypeLatest RecoveryPlanPointType = "Latest" + RecoveryPlanPointTypeLatestApplicationConsistent RecoveryPlanPointType = "LatestApplicationConsistent" + RecoveryPlanPointTypeLatestCrashConsistent RecoveryPlanPointType = "LatestCrashConsistent" + RecoveryPlanPointTypeLatestProcessed RecoveryPlanPointType = "LatestProcessed" +) + +func PossibleValuesForRecoveryPlanPointType() []string { + return []string{ + string(RecoveryPlanPointTypeLatest), + string(RecoveryPlanPointTypeLatestApplicationConsistent), + string(RecoveryPlanPointTypeLatestCrashConsistent), + string(RecoveryPlanPointTypeLatestProcessed), + } +} + +func parseRecoveryPlanPointType(input string) (*RecoveryPlanPointType, error) { + vals := map[string]RecoveryPlanPointType{ + "latest": RecoveryPlanPointTypeLatest, + "latestapplicationconsistent": RecoveryPlanPointTypeLatestApplicationConsistent, + "latestcrashconsistent": RecoveryPlanPointTypeLatestCrashConsistent, + "latestprocessed": RecoveryPlanPointTypeLatestProcessed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPlanPointType(input) + return &out, nil +} + +type ReplicationProtectedItemOperation string + +const ( + ReplicationProtectedItemOperationCancelFailover ReplicationProtectedItemOperation = "CancelFailover" + ReplicationProtectedItemOperationChangePit ReplicationProtectedItemOperation = "ChangePit" + ReplicationProtectedItemOperationCommit ReplicationProtectedItemOperation = "Commit" + ReplicationProtectedItemOperationCompleteMigration ReplicationProtectedItemOperation = "CompleteMigration" + ReplicationProtectedItemOperationDisableProtection ReplicationProtectedItemOperation = "DisableProtection" + ReplicationProtectedItemOperationFailback ReplicationProtectedItemOperation = "Failback" + ReplicationProtectedItemOperationFinalizeFailback ReplicationProtectedItemOperation = "FinalizeFailback" + ReplicationProtectedItemOperationPlannedFailover ReplicationProtectedItemOperation = "PlannedFailover" + ReplicationProtectedItemOperationRepairReplication ReplicationProtectedItemOperation = "RepairReplication" + ReplicationProtectedItemOperationReverseReplicate ReplicationProtectedItemOperation = "ReverseReplicate" + ReplicationProtectedItemOperationSwitchProtection ReplicationProtectedItemOperation = "SwitchProtection" + ReplicationProtectedItemOperationTestFailover ReplicationProtectedItemOperation = "TestFailover" + ReplicationProtectedItemOperationTestFailoverCleanup ReplicationProtectedItemOperation = "TestFailoverCleanup" + ReplicationProtectedItemOperationUnplannedFailover ReplicationProtectedItemOperation = "UnplannedFailover" +) + +func PossibleValuesForReplicationProtectedItemOperation() []string { + return []string{ + string(ReplicationProtectedItemOperationCancelFailover), + string(ReplicationProtectedItemOperationChangePit), + string(ReplicationProtectedItemOperationCommit), + string(ReplicationProtectedItemOperationCompleteMigration), + string(ReplicationProtectedItemOperationDisableProtection), + string(ReplicationProtectedItemOperationFailback), + string(ReplicationProtectedItemOperationFinalizeFailback), + string(ReplicationProtectedItemOperationPlannedFailover), + string(ReplicationProtectedItemOperationRepairReplication), + string(ReplicationProtectedItemOperationReverseReplicate), + string(ReplicationProtectedItemOperationSwitchProtection), + string(ReplicationProtectedItemOperationTestFailover), + string(ReplicationProtectedItemOperationTestFailoverCleanup), + string(ReplicationProtectedItemOperationUnplannedFailover), + } +} + +func parseReplicationProtectedItemOperation(input string) (*ReplicationProtectedItemOperation, error) { + vals := map[string]ReplicationProtectedItemOperation{ + "cancelfailover": ReplicationProtectedItemOperationCancelFailover, + "changepit": ReplicationProtectedItemOperationChangePit, + "commit": ReplicationProtectedItemOperationCommit, + "completemigration": ReplicationProtectedItemOperationCompleteMigration, + "disableprotection": ReplicationProtectedItemOperationDisableProtection, + "failback": ReplicationProtectedItemOperationFailback, + "finalizefailback": ReplicationProtectedItemOperationFinalizeFailback, + "plannedfailover": ReplicationProtectedItemOperationPlannedFailover, + "repairreplication": ReplicationProtectedItemOperationRepairReplication, + "reversereplicate": ReplicationProtectedItemOperationReverseReplicate, + "switchprotection": ReplicationProtectedItemOperationSwitchProtection, + "testfailover": ReplicationProtectedItemOperationTestFailover, + "testfailovercleanup": ReplicationProtectedItemOperationTestFailoverCleanup, + "unplannedfailover": ReplicationProtectedItemOperationUnplannedFailover, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationProtectedItemOperation(input) + return &out, nil +} + +type RpInMageRecoveryPointType string + +const ( + RpInMageRecoveryPointTypeCustom RpInMageRecoveryPointType = "Custom" + RpInMageRecoveryPointTypeLatestTag RpInMageRecoveryPointType = "LatestTag" + RpInMageRecoveryPointTypeLatestTime RpInMageRecoveryPointType = "LatestTime" +) + +func PossibleValuesForRpInMageRecoveryPointType() []string { + return []string{ + string(RpInMageRecoveryPointTypeCustom), + string(RpInMageRecoveryPointTypeLatestTag), + string(RpInMageRecoveryPointTypeLatestTime), + } +} + +func parseRpInMageRecoveryPointType(input string) (*RpInMageRecoveryPointType, error) { + vals := map[string]RpInMageRecoveryPointType{ + "custom": RpInMageRecoveryPointTypeCustom, + "latesttag": RpInMageRecoveryPointTypeLatestTag, + "latesttime": RpInMageRecoveryPointTypeLatestTime, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RpInMageRecoveryPointType(input) + return &out, nil +} + +type SourceSiteOperations string + +const ( + SourceSiteOperationsNotRequired SourceSiteOperations = "NotRequired" + SourceSiteOperationsRequired SourceSiteOperations = "Required" +) + +func PossibleValuesForSourceSiteOperations() []string { + return []string{ + string(SourceSiteOperationsNotRequired), + string(SourceSiteOperationsRequired), + } +} + +func parseSourceSiteOperations(input string) (*SourceSiteOperations, error) { + vals := map[string]SourceSiteOperations{ + "notrequired": SourceSiteOperationsNotRequired, + "required": SourceSiteOperationsRequired, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceSiteOperations(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_replicationrecoveryplan.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_replicationrecoveryplan.go new file mode 100644 index 00000000000..4973d97e0be --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_replicationrecoveryplan.go @@ -0,0 +1,140 @@ +package replicationrecoveryplans + +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 = ReplicationRecoveryPlanId{} + +// ReplicationRecoveryPlanId is a struct representing the Resource ID for a Replication Recovery Plan +type ReplicationRecoveryPlanId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationRecoveryPlanName string +} + +// NewReplicationRecoveryPlanID returns a new ReplicationRecoveryPlanId struct +func NewReplicationRecoveryPlanID(subscriptionId string, resourceGroupName string, vaultName string, replicationRecoveryPlanName string) ReplicationRecoveryPlanId { + return ReplicationRecoveryPlanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationRecoveryPlanName: replicationRecoveryPlanName, + } +} + +// ParseReplicationRecoveryPlanID parses 'input' into a ReplicationRecoveryPlanId +func ParseReplicationRecoveryPlanID(input string) (*ReplicationRecoveryPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationRecoveryPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationRecoveryPlanId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationRecoveryPlanName, ok = parsed.Parsed["replicationRecoveryPlanName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationRecoveryPlanName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationRecoveryPlanIDInsensitively parses 'input' case-insensitively into a ReplicationRecoveryPlanId +// note: this method should only be used for API response data and not user input +func ParseReplicationRecoveryPlanIDInsensitively(input string) (*ReplicationRecoveryPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationRecoveryPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationRecoveryPlanId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationRecoveryPlanName, ok = parsed.Parsed["replicationRecoveryPlanName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationRecoveryPlanName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationRecoveryPlanID checks that 'input' can be parsed as a Replication Recovery Plan ID +func ValidateReplicationRecoveryPlanID(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 := ParseReplicationRecoveryPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Recovery Plan ID +func (id ReplicationRecoveryPlanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationRecoveryPlans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationRecoveryPlanName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Recovery Plan ID +func (id ReplicationRecoveryPlanId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationRecoveryPlans", "replicationRecoveryPlans", "replicationRecoveryPlans"), + resourceids.UserSpecifiedSegment("replicationRecoveryPlanName", "replicationRecoveryPlanValue"), + } +} + +// String returns a human-readable description of this Replication Recovery Plan ID +func (id ReplicationRecoveryPlanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Recovery Plan Name: %q", id.ReplicationRecoveryPlanName), + } + return fmt.Sprintf("Replication Recovery Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_replicationrecoveryplan_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_replicationrecoveryplan_test.go new file mode 100644 index 00000000000..7c3056df610 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_replicationrecoveryplan_test.go @@ -0,0 +1,327 @@ +package replicationrecoveryplans + +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 = ReplicationRecoveryPlanId{} + +func TestNewReplicationRecoveryPlanID(t *testing.T) { + id := NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationRecoveryPlanName != "replicationRecoveryPlanValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationRecoveryPlanName'", id.ReplicationRecoveryPlanName, "replicationRecoveryPlanValue") + } +} + +func TestFormatReplicationRecoveryPlanID(t *testing.T) { + actual := NewReplicationRecoveryPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationRecoveryPlanValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationRecoveryPlans/replicationRecoveryPlanValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationRecoveryPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationRecoveryPlanId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationRecoveryPlans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationRecoveryPlans/replicationRecoveryPlanValue", + Expected: &ReplicationRecoveryPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationRecoveryPlanName: "replicationRecoveryPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationRecoveryPlans/replicationRecoveryPlanValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationRecoveryPlanID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationRecoveryPlanName != v.Expected.ReplicationRecoveryPlanName { + t.Fatalf("Expected %q but got %q for ReplicationRecoveryPlanName", v.Expected.ReplicationRecoveryPlanName, actual.ReplicationRecoveryPlanName) + } + + } +} + +func TestParseReplicationRecoveryPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationRecoveryPlanId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationRecoveryPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnReCoVeRyPlAnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationRecoveryPlans/replicationRecoveryPlanValue", + Expected: &ReplicationRecoveryPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationRecoveryPlanName: "replicationRecoveryPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationRecoveryPlans/replicationRecoveryPlanValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnReCoVeRyPlAnS/rEpLiCaTiOnReCoVeRyPlAnVaLuE", + Expected: &ReplicationRecoveryPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationRecoveryPlanName: "rEpLiCaTiOnReCoVeRyPlAnVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnReCoVeRyPlAnS/rEpLiCaTiOnReCoVeRyPlAnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationRecoveryPlanIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationRecoveryPlanName != v.Expected.ReplicationRecoveryPlanName { + t.Fatalf("Expected %q but got %q for ReplicationRecoveryPlanName", v.Expected.ReplicationRecoveryPlanName, actual.ReplicationRecoveryPlanName) + } + + } +} + +func TestSegmentsForReplicationRecoveryPlanId(t *testing.T) { + segments := ReplicationRecoveryPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationRecoveryPlanId 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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_vault.go new file mode 100644 index 00000000000..de4a14aa346 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_vault.go @@ -0,0 +1,127 @@ +package replicationrecoveryplans + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_vault_test.go new file mode 100644 index 00000000000..35c5261cd31 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationrecoveryplans + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_create_autorest.go new file mode 100644 index 00000000000..b4a62c6a83b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationRecoveryPlansClient) Create(ctx context.Context, id ReplicationRecoveryPlanId, input CreateRecoveryPlanInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationRecoveryPlansClient) CreateThenPoll(ctx context.Context, id ReplicationRecoveryPlanId, input CreateRecoveryPlanInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationRecoveryPlansClient) preparerForCreate(ctx context.Context, id ReplicationRecoveryPlanId, input CreateRecoveryPlanInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_delete_autorest.go new file mode 100644 index 00000000000..7e0d31be310 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationRecoveryPlansClient) Delete(ctx context.Context, id ReplicationRecoveryPlanId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationRecoveryPlansClient) DeleteThenPoll(ctx context.Context, id ReplicationRecoveryPlanId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationRecoveryPlansClient) preparerForDelete(ctx context.Context, id ReplicationRecoveryPlanId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_failovercancel_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_failovercancel_autorest.go new file mode 100644 index 00000000000..04ce3733b59 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_failovercancel_autorest.go @@ -0,0 +1,78 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverCancelOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// FailoverCancel ... +func (c ReplicationRecoveryPlansClient) FailoverCancel(ctx context.Context, id ReplicationRecoveryPlanId) (result FailoverCancelOperationResponse, err error) { + req, err := c.preparerForFailoverCancel(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "FailoverCancel", nil, "Failure preparing request") + return + } + + result, err = c.senderForFailoverCancel(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "FailoverCancel", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// FailoverCancelThenPoll performs FailoverCancel then polls until it's completed +func (c ReplicationRecoveryPlansClient) FailoverCancelThenPoll(ctx context.Context, id ReplicationRecoveryPlanId) error { + result, err := c.FailoverCancel(ctx, id) + if err != nil { + return fmt.Errorf("performing FailoverCancel: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after FailoverCancel: %+v", err) + } + + return nil +} + +// preparerForFailoverCancel prepares the FailoverCancel request. +func (c ReplicationRecoveryPlansClient) preparerForFailoverCancel(ctx context.Context, id ReplicationRecoveryPlanId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/failoverCancel", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForFailoverCancel sends the FailoverCancel request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForFailoverCancel(ctx context.Context, req *http.Request) (future FailoverCancelOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_failovercommit_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_failovercommit_autorest.go new file mode 100644 index 00000000000..38108670b29 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_failovercommit_autorest.go @@ -0,0 +1,78 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverCommitOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// FailoverCommit ... +func (c ReplicationRecoveryPlansClient) FailoverCommit(ctx context.Context, id ReplicationRecoveryPlanId) (result FailoverCommitOperationResponse, err error) { + req, err := c.preparerForFailoverCommit(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "FailoverCommit", nil, "Failure preparing request") + return + } + + result, err = c.senderForFailoverCommit(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "FailoverCommit", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// FailoverCommitThenPoll performs FailoverCommit then polls until it's completed +func (c ReplicationRecoveryPlansClient) FailoverCommitThenPoll(ctx context.Context, id ReplicationRecoveryPlanId) error { + result, err := c.FailoverCommit(ctx, id) + if err != nil { + return fmt.Errorf("performing FailoverCommit: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after FailoverCommit: %+v", err) + } + + return nil +} + +// preparerForFailoverCommit prepares the FailoverCommit request. +func (c ReplicationRecoveryPlansClient) preparerForFailoverCommit(ctx context.Context, id ReplicationRecoveryPlanId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/failoverCommit", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForFailoverCommit sends the FailoverCommit request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForFailoverCommit(ctx context.Context, req *http.Request) (future FailoverCommitOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_get_autorest.go new file mode 100644 index 00000000000..372816fdff3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationrecoveryplans + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *RecoveryPlan +} + +// Get ... +func (c ReplicationRecoveryPlansClient) Get(ctx context.Context, id ReplicationRecoveryPlanId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationRecoveryPlansClient) preparerForGet(ctx context.Context, id ReplicationRecoveryPlanId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationRecoveryPlansClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_list_autorest.go new file mode 100644 index 00000000000..5eb5725b089 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]RecoveryPlan + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []RecoveryPlan +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationRecoveryPlansClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationRecoveryPlansClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationRecoveryPlans", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationRecoveryPlansClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationRecoveryPlansClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []RecoveryPlan `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationRecoveryPlansClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RecoveryPlanOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationRecoveryPlansClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate RecoveryPlanOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]RecoveryPlan, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_plannedfailover_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_plannedfailover_autorest.go new file mode 100644 index 00000000000..9245753ca7d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_plannedfailover_autorest.go @@ -0,0 +1,79 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PlannedFailoverOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// PlannedFailover ... +func (c ReplicationRecoveryPlansClient) PlannedFailover(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanPlannedFailoverInput) (result PlannedFailoverOperationResponse, err error) { + req, err := c.preparerForPlannedFailover(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "PlannedFailover", nil, "Failure preparing request") + return + } + + result, err = c.senderForPlannedFailover(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "PlannedFailover", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PlannedFailoverThenPoll performs PlannedFailover then polls until it's completed +func (c ReplicationRecoveryPlansClient) PlannedFailoverThenPoll(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanPlannedFailoverInput) error { + result, err := c.PlannedFailover(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PlannedFailover: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after PlannedFailover: %+v", err) + } + + return nil +} + +// preparerForPlannedFailover prepares the PlannedFailover request. +func (c ReplicationRecoveryPlansClient) preparerForPlannedFailover(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanPlannedFailoverInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/plannedFailover", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPlannedFailover sends the PlannedFailover request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForPlannedFailover(ctx context.Context, req *http.Request) (future PlannedFailoverOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_reprotect_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_reprotect_autorest.go new file mode 100644 index 00000000000..56303c64894 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_reprotect_autorest.go @@ -0,0 +1,78 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReprotectOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Reprotect ... +func (c ReplicationRecoveryPlansClient) Reprotect(ctx context.Context, id ReplicationRecoveryPlanId) (result ReprotectOperationResponse, err error) { + req, err := c.preparerForReprotect(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Reprotect", nil, "Failure preparing request") + return + } + + result, err = c.senderForReprotect(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Reprotect", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ReprotectThenPoll performs Reprotect then polls until it's completed +func (c ReplicationRecoveryPlansClient) ReprotectThenPoll(ctx context.Context, id ReplicationRecoveryPlanId) error { + result, err := c.Reprotect(ctx, id) + if err != nil { + return fmt.Errorf("performing Reprotect: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Reprotect: %+v", err) + } + + return nil +} + +// preparerForReprotect prepares the Reprotect request. +func (c ReplicationRecoveryPlansClient) preparerForReprotect(ctx context.Context, id ReplicationRecoveryPlanId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/reProtect", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForReprotect sends the Reprotect request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForReprotect(ctx context.Context, req *http.Request) (future ReprotectOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_testfailover_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_testfailover_autorest.go new file mode 100644 index 00000000000..5f89a53911c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_testfailover_autorest.go @@ -0,0 +1,79 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestFailoverOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// TestFailover ... +func (c ReplicationRecoveryPlansClient) TestFailover(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanTestFailoverInput) (result TestFailoverOperationResponse, err error) { + req, err := c.preparerForTestFailover(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "TestFailover", nil, "Failure preparing request") + return + } + + result, err = c.senderForTestFailover(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "TestFailover", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TestFailoverThenPoll performs TestFailover then polls until it's completed +func (c ReplicationRecoveryPlansClient) TestFailoverThenPoll(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanTestFailoverInput) error { + result, err := c.TestFailover(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestFailover: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after TestFailover: %+v", err) + } + + return nil +} + +// preparerForTestFailover prepares the TestFailover request. +func (c ReplicationRecoveryPlansClient) preparerForTestFailover(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanTestFailoverInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/testFailover", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTestFailover sends the TestFailover request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForTestFailover(ctx context.Context, req *http.Request) (future TestFailoverOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_testfailovercleanup_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_testfailovercleanup_autorest.go new file mode 100644 index 00000000000..800fef73082 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_testfailovercleanup_autorest.go @@ -0,0 +1,79 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TestFailoverCleanupOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// TestFailoverCleanup ... +func (c ReplicationRecoveryPlansClient) TestFailoverCleanup(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanTestFailoverCleanupInput) (result TestFailoverCleanupOperationResponse, err error) { + req, err := c.preparerForTestFailoverCleanup(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "TestFailoverCleanup", nil, "Failure preparing request") + return + } + + result, err = c.senderForTestFailoverCleanup(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "TestFailoverCleanup", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// TestFailoverCleanupThenPoll performs TestFailoverCleanup then polls until it's completed +func (c ReplicationRecoveryPlansClient) TestFailoverCleanupThenPoll(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanTestFailoverCleanupInput) error { + result, err := c.TestFailoverCleanup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestFailoverCleanup: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after TestFailoverCleanup: %+v", err) + } + + return nil +} + +// preparerForTestFailoverCleanup prepares the TestFailoverCleanup request. +func (c ReplicationRecoveryPlansClient) preparerForTestFailoverCleanup(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanTestFailoverCleanupInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/testFailoverCleanup", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForTestFailoverCleanup sends the TestFailoverCleanup request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForTestFailoverCleanup(ctx context.Context, req *http.Request) (future TestFailoverCleanupOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_unplannedfailover_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_unplannedfailover_autorest.go new file mode 100644 index 00000000000..1e1d4098a0b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_unplannedfailover_autorest.go @@ -0,0 +1,79 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnplannedFailoverOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// UnplannedFailover ... +func (c ReplicationRecoveryPlansClient) UnplannedFailover(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanUnplannedFailoverInput) (result UnplannedFailoverOperationResponse, err error) { + req, err := c.preparerForUnplannedFailover(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "UnplannedFailover", nil, "Failure preparing request") + return + } + + result, err = c.senderForUnplannedFailover(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "UnplannedFailover", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UnplannedFailoverThenPoll performs UnplannedFailover then polls until it's completed +func (c ReplicationRecoveryPlansClient) UnplannedFailoverThenPoll(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanUnplannedFailoverInput) error { + result, err := c.UnplannedFailover(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UnplannedFailover: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after UnplannedFailover: %+v", err) + } + + return nil +} + +// preparerForUnplannedFailover prepares the UnplannedFailover request. +func (c ReplicationRecoveryPlansClient) preparerForUnplannedFailover(ctx context.Context, id ReplicationRecoveryPlanId, input RecoveryPlanUnplannedFailoverInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/unplannedFailover", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUnplannedFailover sends the UnplannedFailover request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForUnplannedFailover(ctx context.Context, req *http.Request) (future UnplannedFailoverOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_update_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_update_autorest.go new file mode 100644 index 00000000000..7bf649f8804 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/method_update_autorest.go @@ -0,0 +1,79 @@ +package replicationrecoveryplans + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ReplicationRecoveryPlansClient) Update(ctx context.Context, id ReplicationRecoveryPlanId, input UpdateRecoveryPlanInput) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryplans.ReplicationRecoveryPlansClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationRecoveryPlansClient) UpdateThenPoll(ctx context.Context, id ReplicationRecoveryPlanId, input UpdateRecoveryPlanInput) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ReplicationRecoveryPlansClient) preparerForUpdate(ctx context.Context, id ReplicationRecoveryPlanId, input UpdateRecoveryPlanInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryPlansClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_createrecoveryplaninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_createrecoveryplaninput.go new file mode 100644 index 00000000000..283b7b90f39 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_createrecoveryplaninput.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateRecoveryPlanInput struct { + Properties CreateRecoveryPlanInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_createrecoveryplaninputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_createrecoveryplaninputproperties.go new file mode 100644 index 00000000000..cd2989da2de --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_createrecoveryplaninputproperties.go @@ -0,0 +1,55 @@ +package replicationrecoveryplans + +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 CreateRecoveryPlanInputProperties struct { + FailoverDeploymentModel *FailoverDeploymentModel `json:"failoverDeploymentModel,omitempty"` + Groups []RecoveryPlanGroup `json:"groups"` + PrimaryFabricId string `json:"primaryFabricId"` + ProviderSpecificInput *[]RecoveryPlanProviderSpecificInput `json:"providerSpecificInput,omitempty"` + RecoveryFabricId string `json:"recoveryFabricId"` +} + +var _ json.Unmarshaler = &CreateRecoveryPlanInputProperties{} + +func (s *CreateRecoveryPlanInputProperties) UnmarshalJSON(bytes []byte) error { + type alias CreateRecoveryPlanInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into CreateRecoveryPlanInputProperties: %+v", err) + } + + s.FailoverDeploymentModel = decoded.FailoverDeploymentModel + s.Groups = decoded.Groups + s.PrimaryFabricId = decoded.PrimaryFabricId + s.RecoveryFabricId = decoded.RecoveryFabricId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CreateRecoveryPlanInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificInput"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ProviderSpecificInput into list []json.RawMessage: %+v", err) + } + + output := make([]RecoveryPlanProviderSpecificInput, 0) + for i, val := range listTemp { + impl, err := unmarshalRecoveryPlanProviderSpecificInputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ProviderSpecificInput' for 'CreateRecoveryPlanInputProperties': %+v", i, err) + } + output = append(output, impl) + } + s.ProviderSpecificInput = &output + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_currentscenariodetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_currentscenariodetails.go new file mode 100644 index 00000000000..fbcd02e69f9 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_currentscenariodetails.go @@ -0,0 +1,28 @@ +package replicationrecoveryplans + +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 CurrentScenarioDetails struct { + JobId *string `json:"jobId,omitempty"` + ScenarioName *string `json:"scenarioName,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *CurrentScenarioDetails) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CurrentScenarioDetails) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplan.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplan.go new file mode 100644 index 00000000000..f2f8f5ac73f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplan.go @@ -0,0 +1,12 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlan struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecoveryPlanProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2adetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2adetails.go new file mode 100644 index 00000000000..4c00474efd5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2adetails.go @@ -0,0 +1,46 @@ +package replicationrecoveryplans + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RecoveryPlanProviderSpecificDetails = RecoveryPlanA2ADetails{} + +type RecoveryPlanA2ADetails struct { + PrimaryExtendedLocation *edgezones.Model `json:"primaryExtendedLocation,omitempty"` + PrimaryZone *string `json:"primaryZone,omitempty"` + RecoveryExtendedLocation *edgezones.Model `json:"recoveryExtendedLocation,omitempty"` + RecoveryZone *string `json:"recoveryZone,omitempty"` + + // Fields inherited from RecoveryPlanProviderSpecificDetails +} + +var _ json.Marshaler = RecoveryPlanA2ADetails{} + +func (s RecoveryPlanA2ADetails) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanA2ADetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanA2ADetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanA2ADetails: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanA2ADetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2afailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2afailoverinput.go new file mode 100644 index 00000000000..ed65da3bfd6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2afailoverinput.go @@ -0,0 +1,43 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanProviderSpecificFailoverInput = RecoveryPlanA2AFailoverInput{} + +type RecoveryPlanA2AFailoverInput struct { + CloudServiceCreationOption *string `json:"cloudServiceCreationOption,omitempty"` + MultiVMSyncPointOption *MultiVMSyncPointOption `json:"multiVmSyncPointOption,omitempty"` + RecoveryPointType A2ARpRecoveryPointType `json:"recoveryPointType"` + + // Fields inherited from RecoveryPlanProviderSpecificFailoverInput +} + +var _ json.Marshaler = RecoveryPlanA2AFailoverInput{} + +func (s RecoveryPlanA2AFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanA2AFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanA2AFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanA2AFailoverInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanA2AFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2ainput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2ainput.go new file mode 100644 index 00000000000..ff7269aea88 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplana2ainput.go @@ -0,0 +1,46 @@ +package replicationrecoveryplans + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RecoveryPlanProviderSpecificInput = RecoveryPlanA2AInput{} + +type RecoveryPlanA2AInput struct { + PrimaryExtendedLocation *edgezones.Model `json:"primaryExtendedLocation,omitempty"` + PrimaryZone *string `json:"primaryZone,omitempty"` + RecoveryExtendedLocation *edgezones.Model `json:"recoveryExtendedLocation,omitempty"` + RecoveryZone *string `json:"recoveryZone,omitempty"` + + // Fields inherited from RecoveryPlanProviderSpecificInput +} + +var _ json.Marshaler = RecoveryPlanA2AInput{} + +func (s RecoveryPlanA2AInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanA2AInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanA2AInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanA2AInput: %+v", err) + } + decoded["instanceType"] = "A2A" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanA2AInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanaction.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanaction.go new file mode 100644 index 00000000000..48d149ecce5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanaction.go @@ -0,0 +1,44 @@ +package replicationrecoveryplans + +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 RecoveryPlanAction struct { + ActionName string `json:"actionName"` + CustomDetails RecoveryPlanActionDetails `json:"customDetails"` + FailoverDirections []PossibleOperationsDirections `json:"failoverDirections"` + FailoverTypes []ReplicationProtectedItemOperation `json:"failoverTypes"` +} + +var _ json.Unmarshaler = &RecoveryPlanAction{} + +func (s *RecoveryPlanAction) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPlanAction + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPlanAction: %+v", err) + } + + s.ActionName = decoded.ActionName + s.FailoverDirections = decoded.FailoverDirections + s.FailoverTypes = decoded.FailoverTypes + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPlanAction into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customDetails"]; ok { + impl, err := unmarshalRecoveryPlanActionDetailsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomDetails' for 'RecoveryPlanAction': %+v", err) + } + s.CustomDetails = impl + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanactiondetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanactiondetails.go new file mode 100644 index 00000000000..dc8545d7526 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanactiondetails.go @@ -0,0 +1,64 @@ +package replicationrecoveryplans + +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 RecoveryPlanActionDetails interface { +} + +func unmarshalRecoveryPlanActionDetailsImplementation(input []byte) (RecoveryPlanActionDetails, 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 RecoveryPlanActionDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AutomationRunbookActionDetails") { + var out RecoveryPlanAutomationRunbookActionDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanAutomationRunbookActionDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ManualActionDetails") { + var out RecoveryPlanManualActionDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanManualActionDetails: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ScriptActionDetails") { + var out RecoveryPlanScriptActionDetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanScriptActionDetails: %+v", err) + } + return out, nil + } + + type RawRecoveryPlanActionDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryPlanActionDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanautomationrunbookactiondetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanautomationrunbookactiondetails.go new file mode 100644 index 00000000000..58750909e96 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanautomationrunbookactiondetails.go @@ -0,0 +1,43 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanActionDetails = RecoveryPlanAutomationRunbookActionDetails{} + +type RecoveryPlanAutomationRunbookActionDetails struct { + FabricLocation RecoveryPlanActionLocation `json:"fabricLocation"` + RunbookId *string `json:"runbookId,omitempty"` + Timeout *string `json:"timeout,omitempty"` + + // Fields inherited from RecoveryPlanActionDetails +} + +var _ json.Marshaler = RecoveryPlanAutomationRunbookActionDetails{} + +func (s RecoveryPlanAutomationRunbookActionDetails) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanAutomationRunbookActionDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanAutomationRunbookActionDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanAutomationRunbookActionDetails: %+v", err) + } + decoded["instanceType"] = "AutomationRunbookActionDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanAutomationRunbookActionDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplangroup.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplangroup.go new file mode 100644 index 00000000000..9100cabc9e0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplangroup.go @@ -0,0 +1,11 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanGroup struct { + EndGroupActions *[]RecoveryPlanAction `json:"endGroupActions,omitempty"` + GroupType RecoveryPlanGroupType `json:"groupType"` + ReplicationProtectedItems *[]RecoveryPlanProtectedItem `json:"replicationProtectedItems,omitempty"` + StartGroupActions *[]RecoveryPlanAction `json:"startGroupActions,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanhypervreplicaazurefailbackinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanhypervreplicaazurefailbackinput.go new file mode 100644 index 00000000000..eeda143cee0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanhypervreplicaazurefailbackinput.go @@ -0,0 +1,42 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanProviderSpecificFailoverInput = RecoveryPlanHyperVReplicaAzureFailbackInput{} + +type RecoveryPlanHyperVReplicaAzureFailbackInput struct { + DataSyncOption DataSyncStatus `json:"dataSyncOption"` + RecoveryVMCreationOption AlternateLocationRecoveryOption `json:"recoveryVmCreationOption"` + + // Fields inherited from RecoveryPlanProviderSpecificFailoverInput +} + +var _ json.Marshaler = RecoveryPlanHyperVReplicaAzureFailbackInput{} + +func (s RecoveryPlanHyperVReplicaAzureFailbackInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanHyperVReplicaAzureFailbackInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanHyperVReplicaAzureFailbackInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanHyperVReplicaAzureFailbackInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzureFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanHyperVReplicaAzureFailbackInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanhypervreplicaazurefailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanhypervreplicaazurefailoverinput.go new file mode 100644 index 00000000000..5a0fe3870cc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanhypervreplicaazurefailoverinput.go @@ -0,0 +1,43 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanProviderSpecificFailoverInput = RecoveryPlanHyperVReplicaAzureFailoverInput{} + +type RecoveryPlanHyperVReplicaAzureFailoverInput struct { + PrimaryKekCertificatePfx *string `json:"primaryKekCertificatePfx,omitempty"` + RecoveryPointType *HyperVReplicaAzureRpRecoveryPointType `json:"recoveryPointType,omitempty"` + SecondaryKekCertificatePfx *string `json:"secondaryKekCertificatePfx,omitempty"` + + // Fields inherited from RecoveryPlanProviderSpecificFailoverInput +} + +var _ json.Marshaler = RecoveryPlanHyperVReplicaAzureFailoverInput{} + +func (s RecoveryPlanHyperVReplicaAzureFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanHyperVReplicaAzureFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanHyperVReplicaAzureFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanHyperVReplicaAzureFailoverInput: %+v", err) + } + decoded["instanceType"] = "HyperVReplicaAzure" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanHyperVReplicaAzureFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmageazurev2failoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmageazurev2failoverinput.go new file mode 100644 index 00000000000..a69c322e830 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmageazurev2failoverinput.go @@ -0,0 +1,42 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanProviderSpecificFailoverInput = RecoveryPlanInMageAzureV2FailoverInput{} + +type RecoveryPlanInMageAzureV2FailoverInput struct { + RecoveryPointType InMageV2RpRecoveryPointType `json:"recoveryPointType"` + UseMultiVMSyncPoint *string `json:"useMultiVmSyncPoint,omitempty"` + + // Fields inherited from RecoveryPlanProviderSpecificFailoverInput +} + +var _ json.Marshaler = RecoveryPlanInMageAzureV2FailoverInput{} + +func (s RecoveryPlanInMageAzureV2FailoverInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanInMageAzureV2FailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanInMageAzureV2FailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanInMageAzureV2FailoverInput: %+v", err) + } + decoded["instanceType"] = "InMageAzureV2" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanInMageAzureV2FailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagefailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagefailoverinput.go new file mode 100644 index 00000000000..f9a288c0d63 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagefailoverinput.go @@ -0,0 +1,41 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanProviderSpecificFailoverInput = RecoveryPlanInMageFailoverInput{} + +type RecoveryPlanInMageFailoverInput struct { + RecoveryPointType RpInMageRecoveryPointType `json:"recoveryPointType"` + + // Fields inherited from RecoveryPlanProviderSpecificFailoverInput +} + +var _ json.Marshaler = RecoveryPlanInMageFailoverInput{} + +func (s RecoveryPlanInMageFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanInMageFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanInMageFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanInMageFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanInMageFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagercmfailbackfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagercmfailbackfailoverinput.go new file mode 100644 index 00000000000..cf4ee99187e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagercmfailbackfailoverinput.go @@ -0,0 +1,42 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanProviderSpecificFailoverInput = RecoveryPlanInMageRcmFailbackFailoverInput{} + +type RecoveryPlanInMageRcmFailbackFailoverInput struct { + RecoveryPointType InMageRcmFailbackRecoveryPointType `json:"recoveryPointType"` + UseMultiVMSyncPoint *string `json:"useMultiVmSyncPoint,omitempty"` + + // Fields inherited from RecoveryPlanProviderSpecificFailoverInput +} + +var _ json.Marshaler = RecoveryPlanInMageRcmFailbackFailoverInput{} + +func (s RecoveryPlanInMageRcmFailbackFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanInMageRcmFailbackFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanInMageRcmFailbackFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanInMageRcmFailbackFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMageRcmFailback" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanInMageRcmFailbackFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagercmfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagercmfailoverinput.go new file mode 100644 index 00000000000..eace4ab2d6c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplaninmagercmfailoverinput.go @@ -0,0 +1,42 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanProviderSpecificFailoverInput = RecoveryPlanInMageRcmFailoverInput{} + +type RecoveryPlanInMageRcmFailoverInput struct { + RecoveryPointType RecoveryPlanPointType `json:"recoveryPointType"` + UseMultiVMSyncPoint *string `json:"useMultiVmSyncPoint,omitempty"` + + // Fields inherited from RecoveryPlanProviderSpecificFailoverInput +} + +var _ json.Marshaler = RecoveryPlanInMageRcmFailoverInput{} + +func (s RecoveryPlanInMageRcmFailoverInput) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanInMageRcmFailoverInput + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanInMageRcmFailoverInput: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanInMageRcmFailoverInput: %+v", err) + } + decoded["instanceType"] = "InMageRcm" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanInMageRcmFailoverInput: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanmanualactiondetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanmanualactiondetails.go new file mode 100644 index 00000000000..09234f4e823 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanmanualactiondetails.go @@ -0,0 +1,41 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanActionDetails = RecoveryPlanManualActionDetails{} + +type RecoveryPlanManualActionDetails struct { + Description *string `json:"description,omitempty"` + + // Fields inherited from RecoveryPlanActionDetails +} + +var _ json.Marshaler = RecoveryPlanManualActionDetails{} + +func (s RecoveryPlanManualActionDetails) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanManualActionDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanManualActionDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanManualActionDetails: %+v", err) + } + decoded["instanceType"] = "ManualActionDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanManualActionDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanplannedfailoverinput.go new file mode 100644 index 00000000000..5afa04d9119 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanplannedfailoverinput.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanPlannedFailoverInput struct { + Properties RecoveryPlanPlannedFailoverInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanplannedfailoverinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanplannedfailoverinputproperties.go new file mode 100644 index 00000000000..f4e94fedb5b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanplannedfailoverinputproperties.go @@ -0,0 +1,49 @@ +package replicationrecoveryplans + +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 RecoveryPlanPlannedFailoverInputProperties struct { + FailoverDirection PossibleOperationsDirections `json:"failoverDirection"` + ProviderSpecificDetails *[]RecoveryPlanProviderSpecificFailoverInput `json:"providerSpecificDetails,omitempty"` +} + +var _ json.Unmarshaler = &RecoveryPlanPlannedFailoverInputProperties{} + +func (s *RecoveryPlanPlannedFailoverInputProperties) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPlanPlannedFailoverInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPlanPlannedFailoverInputProperties: %+v", err) + } + + s.FailoverDirection = decoded.FailoverDirection + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPlanPlannedFailoverInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ProviderSpecificDetails into list []json.RawMessage: %+v", err) + } + + output := make([]RecoveryPlanProviderSpecificFailoverInput, 0) + for i, val := range listTemp { + impl, err := unmarshalRecoveryPlanProviderSpecificFailoverInputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ProviderSpecificDetails' for 'RecoveryPlanPlannedFailoverInputProperties': %+v", i, err) + } + output = append(output, impl) + } + s.ProviderSpecificDetails = &output + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproperties.go new file mode 100644 index 00000000000..76d17795541 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproperties.go @@ -0,0 +1,116 @@ +package replicationrecoveryplans + +import ( + "encoding/json" + "fmt" + "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 RecoveryPlanProperties struct { + AllowedOperations *[]string `json:"allowedOperations,omitempty"` + CurrentScenario *CurrentScenarioDetails `json:"currentScenario,omitempty"` + CurrentScenarioStatus *string `json:"currentScenarioStatus,omitempty"` + CurrentScenarioStatusDescription *string `json:"currentScenarioStatusDescription,omitempty"` + FailoverDeploymentModel *string `json:"failoverDeploymentModel,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Groups *[]RecoveryPlanGroup `json:"groups,omitempty"` + LastPlannedFailoverTime *string `json:"lastPlannedFailoverTime,omitempty"` + LastTestFailoverTime *string `json:"lastTestFailoverTime,omitempty"` + LastUnplannedFailoverTime *string `json:"lastUnplannedFailoverTime,omitempty"` + PrimaryFabricFriendlyName *string `json:"primaryFabricFriendlyName,omitempty"` + PrimaryFabricId *string `json:"primaryFabricId,omitempty"` + ProviderSpecificDetails *[]RecoveryPlanProviderSpecificDetails `json:"providerSpecificDetails,omitempty"` + RecoveryFabricFriendlyName *string `json:"recoveryFabricFriendlyName,omitempty"` + RecoveryFabricId *string `json:"recoveryFabricId,omitempty"` + ReplicationProviders *[]string `json:"replicationProviders,omitempty"` +} + +func (o *RecoveryPlanProperties) GetLastPlannedFailoverTimeAsTime() (*time.Time, error) { + if o.LastPlannedFailoverTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastPlannedFailoverTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPlanProperties) SetLastPlannedFailoverTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastPlannedFailoverTime = &formatted +} + +func (o *RecoveryPlanProperties) GetLastTestFailoverTimeAsTime() (*time.Time, error) { + if o.LastTestFailoverTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastTestFailoverTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPlanProperties) SetLastTestFailoverTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastTestFailoverTime = &formatted +} + +func (o *RecoveryPlanProperties) GetLastUnplannedFailoverTimeAsTime() (*time.Time, error) { + if o.LastUnplannedFailoverTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUnplannedFailoverTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPlanProperties) SetLastUnplannedFailoverTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUnplannedFailoverTime = &formatted +} + +var _ json.Unmarshaler = &RecoveryPlanProperties{} + +func (s *RecoveryPlanProperties) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPlanProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPlanProperties: %+v", err) + } + + s.AllowedOperations = decoded.AllowedOperations + s.CurrentScenario = decoded.CurrentScenario + s.CurrentScenarioStatus = decoded.CurrentScenarioStatus + s.CurrentScenarioStatusDescription = decoded.CurrentScenarioStatusDescription + s.FailoverDeploymentModel = decoded.FailoverDeploymentModel + s.FriendlyName = decoded.FriendlyName + s.Groups = decoded.Groups + s.LastPlannedFailoverTime = decoded.LastPlannedFailoverTime + s.LastTestFailoverTime = decoded.LastTestFailoverTime + s.LastUnplannedFailoverTime = decoded.LastUnplannedFailoverTime + s.PrimaryFabricFriendlyName = decoded.PrimaryFabricFriendlyName + s.PrimaryFabricId = decoded.PrimaryFabricId + s.RecoveryFabricFriendlyName = decoded.RecoveryFabricFriendlyName + s.RecoveryFabricId = decoded.RecoveryFabricId + s.ReplicationProviders = decoded.ReplicationProviders + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPlanProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ProviderSpecificDetails into list []json.RawMessage: %+v", err) + } + + output := make([]RecoveryPlanProviderSpecificDetails, 0) + for i, val := range listTemp { + impl, err := unmarshalRecoveryPlanProviderSpecificDetailsImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ProviderSpecificDetails' for 'RecoveryPlanProperties': %+v", i, err) + } + output = append(output, impl) + } + s.ProviderSpecificDetails = &output + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanprotecteditem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanprotecteditem.go new file mode 100644 index 00000000000..e3d9c1e2cbf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanprotecteditem.go @@ -0,0 +1,9 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanProtectedItem struct { + Id *string `json:"id,omitempty"` + VirtualMachineId *string `json:"virtualMachineId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificdetails.go new file mode 100644 index 00000000000..a2a8fbfe3e8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificdetails.go @@ -0,0 +1,48 @@ +package replicationrecoveryplans + +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 RecoveryPlanProviderSpecificDetails interface { +} + +func unmarshalRecoveryPlanProviderSpecificDetailsImplementation(input []byte) (RecoveryPlanProviderSpecificDetails, 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 RecoveryPlanProviderSpecificDetails into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out RecoveryPlanA2ADetails + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanA2ADetails: %+v", err) + } + return out, nil + } + + type RawRecoveryPlanProviderSpecificDetailsImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryPlanProviderSpecificDetailsImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificfailoverinput.go new file mode 100644 index 00000000000..e324c58ad06 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificfailoverinput.go @@ -0,0 +1,96 @@ +package replicationrecoveryplans + +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 RecoveryPlanProviderSpecificFailoverInput interface { +} + +func unmarshalRecoveryPlanProviderSpecificFailoverInputImplementation(input []byte) (RecoveryPlanProviderSpecificFailoverInput, 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 RecoveryPlanProviderSpecificFailoverInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out RecoveryPlanA2AFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanA2AFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzureFailback") { + var out RecoveryPlanHyperVReplicaAzureFailbackInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanHyperVReplicaAzureFailbackInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HyperVReplicaAzure") { + var out RecoveryPlanHyperVReplicaAzureFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanHyperVReplicaAzureFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageAzureV2") { + var out RecoveryPlanInMageAzureV2FailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanInMageAzureV2FailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMage") { + var out RecoveryPlanInMageFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanInMageFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcmFailback") { + var out RecoveryPlanInMageRcmFailbackFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanInMageRcmFailbackFailoverInput: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "InMageRcm") { + var out RecoveryPlanInMageRcmFailoverInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanInMageRcmFailoverInput: %+v", err) + } + return out, nil + } + + type RawRecoveryPlanProviderSpecificFailoverInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryPlanProviderSpecificFailoverInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificinput.go new file mode 100644 index 00000000000..c93de8a8a83 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanproviderspecificinput.go @@ -0,0 +1,48 @@ +package replicationrecoveryplans + +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 RecoveryPlanProviderSpecificInput interface { +} + +func unmarshalRecoveryPlanProviderSpecificInputImplementation(input []byte) (RecoveryPlanProviderSpecificInput, 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 RecoveryPlanProviderSpecificInput into map[string]interface: %+v", err) + } + + value, ok := temp["instanceType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "A2A") { + var out RecoveryPlanA2AInput + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RecoveryPlanA2AInput: %+v", err) + } + return out, nil + } + + type RawRecoveryPlanProviderSpecificInputImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawRecoveryPlanProviderSpecificInputImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanscriptactiondetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanscriptactiondetails.go new file mode 100644 index 00000000000..07855278c4f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanscriptactiondetails.go @@ -0,0 +1,43 @@ +package replicationrecoveryplans + +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 _ RecoveryPlanActionDetails = RecoveryPlanScriptActionDetails{} + +type RecoveryPlanScriptActionDetails struct { + FabricLocation RecoveryPlanActionLocation `json:"fabricLocation"` + Path string `json:"path"` + Timeout *string `json:"timeout,omitempty"` + + // Fields inherited from RecoveryPlanActionDetails +} + +var _ json.Marshaler = RecoveryPlanScriptActionDetails{} + +func (s RecoveryPlanScriptActionDetails) MarshalJSON() ([]byte, error) { + type wrapper RecoveryPlanScriptActionDetails + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RecoveryPlanScriptActionDetails: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RecoveryPlanScriptActionDetails: %+v", err) + } + decoded["instanceType"] = "ScriptActionDetails" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RecoveryPlanScriptActionDetails: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailovercleanupinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailovercleanupinput.go new file mode 100644 index 00000000000..4379adce6cd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailovercleanupinput.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanTestFailoverCleanupInput struct { + Properties RecoveryPlanTestFailoverCleanupInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailovercleanupinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailovercleanupinputproperties.go new file mode 100644 index 00000000000..2b3b65c28c3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailovercleanupinputproperties.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanTestFailoverCleanupInputProperties struct { + Comments *string `json:"comments,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailoverinput.go new file mode 100644 index 00000000000..c5706924b4e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailoverinput.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanTestFailoverInput struct { + Properties RecoveryPlanTestFailoverInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailoverinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailoverinputproperties.go new file mode 100644 index 00000000000..76922b79ed1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplantestfailoverinputproperties.go @@ -0,0 +1,53 @@ +package replicationrecoveryplans + +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 RecoveryPlanTestFailoverInputProperties struct { + FailoverDirection PossibleOperationsDirections `json:"failoverDirection"` + NetworkId *string `json:"networkId,omitempty"` + NetworkType string `json:"networkType"` + ProviderSpecificDetails *[]RecoveryPlanProviderSpecificFailoverInput `json:"providerSpecificDetails,omitempty"` +} + +var _ json.Unmarshaler = &RecoveryPlanTestFailoverInputProperties{} + +func (s *RecoveryPlanTestFailoverInputProperties) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPlanTestFailoverInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPlanTestFailoverInputProperties: %+v", err) + } + + s.FailoverDirection = decoded.FailoverDirection + s.NetworkId = decoded.NetworkId + s.NetworkType = decoded.NetworkType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPlanTestFailoverInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ProviderSpecificDetails into list []json.RawMessage: %+v", err) + } + + output := make([]RecoveryPlanProviderSpecificFailoverInput, 0) + for i, val := range listTemp { + impl, err := unmarshalRecoveryPlanProviderSpecificFailoverInputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ProviderSpecificDetails' for 'RecoveryPlanTestFailoverInputProperties': %+v", i, err) + } + output = append(output, impl) + } + s.ProviderSpecificDetails = &output + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanunplannedfailoverinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanunplannedfailoverinput.go new file mode 100644 index 00000000000..92fc6578c58 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanunplannedfailoverinput.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanUnplannedFailoverInput struct { + Properties RecoveryPlanUnplannedFailoverInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanunplannedfailoverinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanunplannedfailoverinputproperties.go new file mode 100644 index 00000000000..a3337d470e6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_recoveryplanunplannedfailoverinputproperties.go @@ -0,0 +1,51 @@ +package replicationrecoveryplans + +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 RecoveryPlanUnplannedFailoverInputProperties struct { + FailoverDirection PossibleOperationsDirections `json:"failoverDirection"` + ProviderSpecificDetails *[]RecoveryPlanProviderSpecificFailoverInput `json:"providerSpecificDetails,omitempty"` + SourceSiteOperations SourceSiteOperations `json:"sourceSiteOperations"` +} + +var _ json.Unmarshaler = &RecoveryPlanUnplannedFailoverInputProperties{} + +func (s *RecoveryPlanUnplannedFailoverInputProperties) UnmarshalJSON(bytes []byte) error { + type alias RecoveryPlanUnplannedFailoverInputProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RecoveryPlanUnplannedFailoverInputProperties: %+v", err) + } + + s.FailoverDirection = decoded.FailoverDirection + s.SourceSiteOperations = decoded.SourceSiteOperations + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RecoveryPlanUnplannedFailoverInputProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["providerSpecificDetails"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ProviderSpecificDetails into list []json.RawMessage: %+v", err) + } + + output := make([]RecoveryPlanProviderSpecificFailoverInput, 0) + for i, val := range listTemp { + impl, err := unmarshalRecoveryPlanProviderSpecificFailoverInputImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ProviderSpecificDetails' for 'RecoveryPlanUnplannedFailoverInputProperties': %+v", i, err) + } + output = append(output, impl) + } + s.ProviderSpecificDetails = &output + } + return nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_updaterecoveryplaninput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_updaterecoveryplaninput.go new file mode 100644 index 00000000000..f1611672eed --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_updaterecoveryplaninput.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateRecoveryPlanInput struct { + Properties *UpdateRecoveryPlanInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_updaterecoveryplaninputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_updaterecoveryplaninputproperties.go new file mode 100644 index 00000000000..dba269e1ee5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/model_updaterecoveryplaninputproperties.go @@ -0,0 +1,8 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateRecoveryPlanInputProperties struct { + Groups *[]RecoveryPlanGroup `json:"groups,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/predicates.go new file mode 100644 index 00000000000..f52b5d7a104 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/predicates.go @@ -0,0 +1,32 @@ +package replicationrecoveryplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryPlanOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RecoveryPlanOperationPredicate) Matches(input RecoveryPlan) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/version.go new file mode 100644 index 00000000000..1ce383ff760 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryplans/version.go @@ -0,0 +1,12 @@ +package replicationrecoveryplans + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationrecoveryplans/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/README.md new file mode 100644 index 00000000000..bd7ee7305be --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/README.md @@ -0,0 +1,123 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders` Documentation + +The `replicationrecoveryservicesproviders` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders" +``` + + +### Client Initialization + +```go +client := replicationrecoveryservicesproviders.NewReplicationRecoveryServicesProvidersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationRecoveryServicesProvidersClient.Create` + +```go +ctx := context.TODO() +id := replicationrecoveryservicesproviders.NewReplicationRecoveryServicesProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationRecoveryServicesProviderValue") + +payload := replicationrecoveryservicesproviders.AddRecoveryServicesProviderInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryServicesProvidersClient.Delete` + +```go +ctx := context.TODO() +id := replicationrecoveryservicesproviders.NewReplicationRecoveryServicesProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationRecoveryServicesProviderValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryServicesProvidersClient.Get` + +```go +ctx := context.TODO() +id := replicationrecoveryservicesproviders.NewReplicationRecoveryServicesProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationRecoveryServicesProviderValue") + +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: `ReplicationRecoveryServicesProvidersClient.List` + +```go +ctx := context.TODO() +id := replicationrecoveryservicesproviders.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationRecoveryServicesProvidersClient.ListByReplicationFabrics` + +```go +ctx := context.TODO() +id := replicationrecoveryservicesproviders.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +// alternatively `client.ListByReplicationFabrics(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationFabricsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationRecoveryServicesProvidersClient.Purge` + +```go +ctx := context.TODO() +id := replicationrecoveryservicesproviders.NewReplicationRecoveryServicesProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationRecoveryServicesProviderValue") + +if err := client.PurgeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationRecoveryServicesProvidersClient.RefreshProvider` + +```go +ctx := context.TODO() +id := replicationrecoveryservicesproviders.NewReplicationRecoveryServicesProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationRecoveryServicesProviderValue") + +if err := client.RefreshProviderThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/client.go new file mode 100644 index 00000000000..f1a409dfb88 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/client.go @@ -0,0 +1,18 @@ +package replicationrecoveryservicesproviders + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationRecoveryServicesProvidersClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationRecoveryServicesProvidersClientWithBaseURI(endpoint string) ReplicationRecoveryServicesProvidersClient { + return ReplicationRecoveryServicesProvidersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/constants.go new file mode 100644 index 00000000000..01c6bb3fe04 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/constants.go @@ -0,0 +1,71 @@ +package replicationrecoveryservicesproviders + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentVersionStatus string + +const ( + AgentVersionStatusDeprecated AgentVersionStatus = "Deprecated" + AgentVersionStatusNotSupported AgentVersionStatus = "NotSupported" + AgentVersionStatusSecurityUpdateRequired AgentVersionStatus = "SecurityUpdateRequired" + AgentVersionStatusSupported AgentVersionStatus = "Supported" + AgentVersionStatusUpdateRequired AgentVersionStatus = "UpdateRequired" +) + +func PossibleValuesForAgentVersionStatus() []string { + return []string{ + string(AgentVersionStatusDeprecated), + string(AgentVersionStatusNotSupported), + string(AgentVersionStatusSecurityUpdateRequired), + string(AgentVersionStatusSupported), + string(AgentVersionStatusUpdateRequired), + } +} + +func parseAgentVersionStatus(input string) (*AgentVersionStatus, error) { + vals := map[string]AgentVersionStatus{ + "deprecated": AgentVersionStatusDeprecated, + "notsupported": AgentVersionStatusNotSupported, + "securityupdaterequired": AgentVersionStatusSecurityUpdateRequired, + "supported": AgentVersionStatusSupported, + "updaterequired": AgentVersionStatusUpdateRequired, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AgentVersionStatus(input) + return &out, nil +} + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationfabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationfabric.go new file mode 100644 index 00000000000..e41cd0ec056 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationrecoveryservicesproviders + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationfabric_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationfabric_test.go new file mode 100644 index 00000000000..d8d8d3b82ef --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationfabric_test.go @@ -0,0 +1,327 @@ +package replicationrecoveryservicesproviders + +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 = ReplicationFabricId{} + +func TestNewReplicationFabricID(t *testing.T) { + id := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } +} + +func TestFormatReplicationFabricID(t *testing.T) { + actual := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestParseReplicationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestSegmentsForReplicationFabricId(t *testing.T) { + segments := ReplicationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationFabricId 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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationrecoveryservicesprovider.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationrecoveryservicesprovider.go new file mode 100644 index 00000000000..fb6c5b04666 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationrecoveryservicesprovider.go @@ -0,0 +1,153 @@ +package replicationrecoveryservicesproviders + +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 = ReplicationRecoveryServicesProviderId{} + +// ReplicationRecoveryServicesProviderId is a struct representing the Resource ID for a Replication Recovery Services Provider +type ReplicationRecoveryServicesProviderId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationRecoveryServicesProviderName string +} + +// NewReplicationRecoveryServicesProviderID returns a new ReplicationRecoveryServicesProviderId struct +func NewReplicationRecoveryServicesProviderID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationRecoveryServicesProviderName string) ReplicationRecoveryServicesProviderId { + return ReplicationRecoveryServicesProviderId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationRecoveryServicesProviderName: replicationRecoveryServicesProviderName, + } +} + +// ParseReplicationRecoveryServicesProviderID parses 'input' into a ReplicationRecoveryServicesProviderId +func ParseReplicationRecoveryServicesProviderID(input string) (*ReplicationRecoveryServicesProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationRecoveryServicesProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationRecoveryServicesProviderId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationRecoveryServicesProviderName, ok = parsed.Parsed["replicationRecoveryServicesProviderName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationRecoveryServicesProviderName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationRecoveryServicesProviderIDInsensitively parses 'input' case-insensitively into a ReplicationRecoveryServicesProviderId +// note: this method should only be used for API response data and not user input +func ParseReplicationRecoveryServicesProviderIDInsensitively(input string) (*ReplicationRecoveryServicesProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationRecoveryServicesProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationRecoveryServicesProviderId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationRecoveryServicesProviderName, ok = parsed.Parsed["replicationRecoveryServicesProviderName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationRecoveryServicesProviderName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationRecoveryServicesProviderID checks that 'input' can be parsed as a Replication Recovery Services Provider ID +func ValidateReplicationRecoveryServicesProviderID(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 := ParseReplicationRecoveryServicesProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Recovery Services Provider ID +func (id ReplicationRecoveryServicesProviderId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationRecoveryServicesProviders/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationRecoveryServicesProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Recovery Services Provider ID +func (id ReplicationRecoveryServicesProviderId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationRecoveryServicesProviders", "replicationRecoveryServicesProviders", "replicationRecoveryServicesProviders"), + resourceids.UserSpecifiedSegment("replicationRecoveryServicesProviderName", "replicationRecoveryServicesProviderValue"), + } +} + +// String returns a human-readable description of this Replication Recovery Services Provider ID +func (id ReplicationRecoveryServicesProviderId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Recovery Services Provider Name: %q", id.ReplicationRecoveryServicesProviderName), + } + return fmt.Sprintf("Replication Recovery Services Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationrecoveryservicesprovider_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationrecoveryservicesprovider_test.go new file mode 100644 index 00000000000..295eb745e2f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_replicationrecoveryservicesprovider_test.go @@ -0,0 +1,372 @@ +package replicationrecoveryservicesproviders + +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 = ReplicationRecoveryServicesProviderId{} + +func TestNewReplicationRecoveryServicesProviderID(t *testing.T) { + id := NewReplicationRecoveryServicesProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationRecoveryServicesProviderValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationRecoveryServicesProviderName != "replicationRecoveryServicesProviderValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationRecoveryServicesProviderName'", id.ReplicationRecoveryServicesProviderName, "replicationRecoveryServicesProviderValue") + } +} + +func TestFormatReplicationRecoveryServicesProviderID(t *testing.T) { + actual := NewReplicationRecoveryServicesProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationRecoveryServicesProviderValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationRecoveryServicesProviders/replicationRecoveryServicesProviderValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationRecoveryServicesProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationRecoveryServicesProviderId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationRecoveryServicesProviders", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationRecoveryServicesProviders/replicationRecoveryServicesProviderValue", + Expected: &ReplicationRecoveryServicesProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationRecoveryServicesProviderName: "replicationRecoveryServicesProviderValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationRecoveryServicesProviders/replicationRecoveryServicesProviderValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationRecoveryServicesProviderID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationRecoveryServicesProviderName != v.Expected.ReplicationRecoveryServicesProviderName { + t.Fatalf("Expected %q but got %q for ReplicationRecoveryServicesProviderName", v.Expected.ReplicationRecoveryServicesProviderName, actual.ReplicationRecoveryServicesProviderName) + } + + } +} + +func TestParseReplicationRecoveryServicesProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationRecoveryServicesProviderId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationRecoveryServicesProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnReCoVeRySeRvIcEsPrOvIdErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationRecoveryServicesProviders/replicationRecoveryServicesProviderValue", + Expected: &ReplicationRecoveryServicesProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationRecoveryServicesProviderName: "replicationRecoveryServicesProviderValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationRecoveryServicesProviders/replicationRecoveryServicesProviderValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnReCoVeRySeRvIcEsPrOvIdErS/rEpLiCaTiOnReCoVeRySeRvIcEsPrOvIdErVaLuE", + Expected: &ReplicationRecoveryServicesProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationRecoveryServicesProviderName: "rEpLiCaTiOnReCoVeRySeRvIcEsPrOvIdErVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnReCoVeRySeRvIcEsPrOvIdErS/rEpLiCaTiOnReCoVeRySeRvIcEsPrOvIdErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationRecoveryServicesProviderIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationRecoveryServicesProviderName != v.Expected.ReplicationRecoveryServicesProviderName { + t.Fatalf("Expected %q but got %q for ReplicationRecoveryServicesProviderName", v.Expected.ReplicationRecoveryServicesProviderName, actual.ReplicationRecoveryServicesProviderName) + } + + } +} + +func TestSegmentsForReplicationRecoveryServicesProviderId(t *testing.T) { + segments := ReplicationRecoveryServicesProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationRecoveryServicesProviderId 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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_vault.go new file mode 100644 index 00000000000..c0b8fbb4ef4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_vault.go @@ -0,0 +1,127 @@ +package replicationrecoveryservicesproviders + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_vault_test.go new file mode 100644 index 00000000000..ac859d7c0fe --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationrecoveryservicesproviders + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_create_autorest.go new file mode 100644 index 00000000000..c962731b3b5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationrecoveryservicesproviders + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationRecoveryServicesProvidersClient) Create(ctx context.Context, id ReplicationRecoveryServicesProviderId, input AddRecoveryServicesProviderInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationRecoveryServicesProvidersClient) CreateThenPoll(ctx context.Context, id ReplicationRecoveryServicesProviderId, input AddRecoveryServicesProviderInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationRecoveryServicesProvidersClient) preparerForCreate(ctx context.Context, id ReplicationRecoveryServicesProviderId, input AddRecoveryServicesProviderInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryServicesProvidersClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_delete_autorest.go new file mode 100644 index 00000000000..90fe8f3a0a1 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationrecoveryservicesproviders + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationRecoveryServicesProvidersClient) Delete(ctx context.Context, id ReplicationRecoveryServicesProviderId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationRecoveryServicesProvidersClient) DeleteThenPoll(ctx context.Context, id ReplicationRecoveryServicesProviderId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationRecoveryServicesProvidersClient) preparerForDelete(ctx context.Context, id ReplicationRecoveryServicesProviderId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/remove", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryServicesProvidersClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_get_autorest.go new file mode 100644 index 00000000000..0e11f2953de --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationrecoveryservicesproviders + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *RecoveryServicesProvider +} + +// Get ... +func (c ReplicationRecoveryServicesProvidersClient) Get(ctx context.Context, id ReplicationRecoveryServicesProviderId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationRecoveryServicesProvidersClient) preparerForGet(ctx context.Context, id ReplicationRecoveryServicesProviderId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationRecoveryServicesProvidersClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_list_autorest.go new file mode 100644 index 00000000000..f32d2a6944e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationrecoveryservicesproviders + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]RecoveryServicesProvider + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []RecoveryServicesProvider +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationRecoveryServicesProvidersClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationRecoveryServicesProvidersClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationRecoveryServicesProviders", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationRecoveryServicesProvidersClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationRecoveryServicesProvidersClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []RecoveryServicesProvider `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationRecoveryServicesProvidersClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RecoveryServicesProviderOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationRecoveryServicesProvidersClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate RecoveryServicesProviderOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]RecoveryServicesProvider, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_listbyreplicationfabrics_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_listbyreplicationfabrics_autorest.go new file mode 100644 index 00000000000..356f1e78e74 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_listbyreplicationfabrics_autorest.go @@ -0,0 +1,186 @@ +package replicationrecoveryservicesproviders + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationFabricsOperationResponse struct { + HttpResponse *http.Response + Model *[]RecoveryServicesProvider + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationFabricsOperationResponse, error) +} + +type ListByReplicationFabricsCompleteResult struct { + Items []RecoveryServicesProvider +} + +func (r ListByReplicationFabricsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationFabricsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationFabricsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationFabrics ... +func (c ReplicationRecoveryServicesProvidersClient) ListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (resp ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabrics(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationFabrics(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationFabrics prepares the ListByReplicationFabrics request. +func (c ReplicationRecoveryServicesProvidersClient) preparerForListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationRecoveryServicesProviders", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationFabricsWithNextLink prepares the ListByReplicationFabrics request with the given nextLink token. +func (c ReplicationRecoveryServicesProvidersClient) preparerForListByReplicationFabricsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationFabrics handles the response to the ListByReplicationFabrics request. The method always +// closes the http.Response Body. +func (c ReplicationRecoveryServicesProvidersClient) responderForListByReplicationFabrics(resp *http.Response) (result ListByReplicationFabricsOperationResponse, err error) { + type page struct { + Values []RecoveryServicesProvider `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabricsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "ListByReplicationFabrics", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationFabrics(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "ListByReplicationFabrics", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationFabricsComplete retrieves all of the results into a single object +func (c ReplicationRecoveryServicesProvidersClient) ListByReplicationFabricsComplete(ctx context.Context, id ReplicationFabricId) (ListByReplicationFabricsCompleteResult, error) { + return c.ListByReplicationFabricsCompleteMatchingPredicate(ctx, id, RecoveryServicesProviderOperationPredicate{}) +} + +// ListByReplicationFabricsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationRecoveryServicesProvidersClient) ListByReplicationFabricsCompleteMatchingPredicate(ctx context.Context, id ReplicationFabricId, predicate RecoveryServicesProviderOperationPredicate) (resp ListByReplicationFabricsCompleteResult, err error) { + items := make([]RecoveryServicesProvider, 0) + + page, err := c.ListByReplicationFabrics(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationFabricsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_purge_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_purge_autorest.go new file mode 100644 index 00000000000..26139f9b294 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_purge_autorest.go @@ -0,0 +1,78 @@ +package replicationrecoveryservicesproviders + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurgeOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Purge ... +func (c ReplicationRecoveryServicesProvidersClient) Purge(ctx context.Context, id ReplicationRecoveryServicesProviderId) (result PurgeOperationResponse, err error) { + req, err := c.preparerForPurge(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Purge", nil, "Failure preparing request") + return + } + + result, err = c.senderForPurge(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "Purge", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PurgeThenPoll performs Purge then polls until it's completed +func (c ReplicationRecoveryServicesProvidersClient) PurgeThenPoll(ctx context.Context, id ReplicationRecoveryServicesProviderId) error { + result, err := c.Purge(ctx, id) + if err != nil { + return fmt.Errorf("performing Purge: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Purge: %+v", err) + } + + return nil +} + +// preparerForPurge prepares the Purge request. +func (c ReplicationRecoveryServicesProvidersClient) preparerForPurge(ctx context.Context, id ReplicationRecoveryServicesProviderId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPurge sends the Purge request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryServicesProvidersClient) senderForPurge(ctx context.Context, req *http.Request) (future PurgeOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_refreshprovider_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_refreshprovider_autorest.go new file mode 100644 index 00000000000..6660156f4a7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/method_refreshprovider_autorest.go @@ -0,0 +1,78 @@ +package replicationrecoveryservicesproviders + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshProviderOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// RefreshProvider ... +func (c ReplicationRecoveryServicesProvidersClient) RefreshProvider(ctx context.Context, id ReplicationRecoveryServicesProviderId) (result RefreshProviderOperationResponse, err error) { + req, err := c.preparerForRefreshProvider(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "RefreshProvider", nil, "Failure preparing request") + return + } + + result, err = c.senderForRefreshProvider(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationrecoveryservicesproviders.ReplicationRecoveryServicesProvidersClient", "RefreshProvider", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RefreshProviderThenPoll performs RefreshProvider then polls until it's completed +func (c ReplicationRecoveryServicesProvidersClient) RefreshProviderThenPoll(ctx context.Context, id ReplicationRecoveryServicesProviderId) error { + result, err := c.RefreshProvider(ctx, id) + if err != nil { + return fmt.Errorf("performing RefreshProvider: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after RefreshProvider: %+v", err) + } + + return nil +} + +// preparerForRefreshProvider prepares the RefreshProvider request. +func (c ReplicationRecoveryServicesProvidersClient) preparerForRefreshProvider(ctx context.Context, id ReplicationRecoveryServicesProviderId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/refreshProvider", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRefreshProvider sends the RefreshProvider request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationRecoveryServicesProvidersClient) senderForRefreshProvider(ctx context.Context, req *http.Request) (future RefreshProviderOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_addrecoveryservicesproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_addrecoveryservicesproviderinput.go new file mode 100644 index 00000000000..2c945e24875 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_addrecoveryservicesproviderinput.go @@ -0,0 +1,8 @@ +package replicationrecoveryservicesproviders + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddRecoveryServicesProviderInput struct { + Properties AddRecoveryServicesProviderInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_addrecoveryservicesproviderinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_addrecoveryservicesproviderinputproperties.go new file mode 100644 index 00000000000..9562bac2653 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_addrecoveryservicesproviderinputproperties.go @@ -0,0 +1,13 @@ +package replicationrecoveryservicesproviders + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddRecoveryServicesProviderInputProperties struct { + AuthenticationIdentityInput IdentityProviderInput `json:"authenticationIdentityInput"` + BiosId *string `json:"biosId,omitempty"` + DataPlaneAuthenticationIdentityInput *IdentityProviderInput `json:"dataPlaneAuthenticationIdentityInput,omitempty"` + MachineId *string `json:"machineId,omitempty"` + MachineName string `json:"machineName"` + ResourceAccessIdentityInput IdentityProviderInput `json:"resourceAccessIdentityInput"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_healtherror.go new file mode 100644 index 00000000000..b0c92df9ee5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationrecoveryservicesproviders + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_identityproviderdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_identityproviderdetails.go new file mode 100644 index 00000000000..ab5ea5efed4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_identityproviderdetails.go @@ -0,0 +1,12 @@ +package replicationrecoveryservicesproviders + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderDetails struct { + AadAuthority *string `json:"aadAuthority,omitempty"` + ApplicationId *string `json:"applicationId,omitempty"` + Audience *string `json:"audience,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_identityproviderinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_identityproviderinput.go new file mode 100644 index 00000000000..df9e5c5085d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_identityproviderinput.go @@ -0,0 +1,12 @@ +package replicationrecoveryservicesproviders + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderInput struct { + AadAuthority string `json:"aadAuthority"` + ApplicationId string `json:"applicationId"` + Audience string `json:"audience"` + ObjectId string `json:"objectId"` + TenantId string `json:"tenantId"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_innerhealtherror.go new file mode 100644 index 00000000000..3ef08acf21c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationrecoveryservicesproviders + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_recoveryservicesprovider.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_recoveryservicesprovider.go new file mode 100644 index 00000000000..8b870a59529 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_recoveryservicesprovider.go @@ -0,0 +1,12 @@ +package replicationrecoveryservicesproviders + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryServicesProvider struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecoveryServicesProviderProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_recoveryservicesproviderproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_recoveryservicesproviderproperties.go new file mode 100644 index 00000000000..db54434b901 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_recoveryservicesproviderproperties.go @@ -0,0 +1,57 @@ +package replicationrecoveryservicesproviders + +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 RecoveryServicesProviderProperties struct { + AllowedScenarios *[]string `json:"allowedScenarios,omitempty"` + AuthenticationIdentityDetails *IdentityProviderDetails `json:"authenticationIdentityDetails,omitempty"` + BiosId *string `json:"biosId,omitempty"` + ConnectionStatus *string `json:"connectionStatus,omitempty"` + DataPlaneAuthenticationIdentityDetails *IdentityProviderDetails `json:"dataPlaneAuthenticationIdentityDetails,omitempty"` + DraIdentifier *string `json:"draIdentifier,omitempty"` + FabricFriendlyName *string `json:"fabricFriendlyName,omitempty"` + FabricType *string `json:"fabricType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthErrorDetails *[]HealthError `json:"healthErrorDetails,omitempty"` + LastHeartBeat *string `json:"lastHeartBeat,omitempty"` + MachineId *string `json:"machineId,omitempty"` + MachineName *string `json:"machineName,omitempty"` + ProtectedItemCount *int64 `json:"protectedItemCount,omitempty"` + ProviderVersion *string `json:"providerVersion,omitempty"` + ProviderVersionDetails *VersionDetails `json:"providerVersionDetails,omitempty"` + ProviderVersionExpiryDate *string `json:"providerVersionExpiryDate,omitempty"` + ProviderVersionState *string `json:"providerVersionState,omitempty"` + ResourceAccessIdentityDetails *IdentityProviderDetails `json:"resourceAccessIdentityDetails,omitempty"` + ServerVersion *string `json:"serverVersion,omitempty"` +} + +func (o *RecoveryServicesProviderProperties) GetLastHeartBeatAsTime() (*time.Time, error) { + if o.LastHeartBeat == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartBeat, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryServicesProviderProperties) SetLastHeartBeatAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartBeat = &formatted +} + +func (o *RecoveryServicesProviderProperties) GetProviderVersionExpiryDateAsTime() (*time.Time, error) { + if o.ProviderVersionExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProviderVersionExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryServicesProviderProperties) SetProviderVersionExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProviderVersionExpiryDate = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_versiondetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_versiondetails.go new file mode 100644 index 00000000000..9a441abb5ca --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/model_versiondetails.go @@ -0,0 +1,28 @@ +package replicationrecoveryservicesproviders + +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 VersionDetails struct { + ExpiryDate *string `json:"expiryDate,omitempty"` + Status *AgentVersionStatus `json:"status,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *VersionDetails) GetExpiryDateAsTime() (*time.Time, error) { + if o.ExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *VersionDetails) SetExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryDate = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/predicates.go new file mode 100644 index 00000000000..f879431fccb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/predicates.go @@ -0,0 +1,32 @@ +package replicationrecoveryservicesproviders + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoveryServicesProviderOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RecoveryServicesProviderOperationPredicate) Matches(input RecoveryServicesProvider) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/version.go new file mode 100644 index 00000000000..994184780ca --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationrecoveryservicesproviders/version.go @@ -0,0 +1,12 @@ +package replicationrecoveryservicesproviders + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationrecoveryservicesproviders/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/README.md new file mode 100644 index 00000000000..bbbd30470ec --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings` Documentation + +The `replicationstorageclassificationmappings` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings" +``` + + +### Client Initialization + +```go +client := replicationstorageclassificationmappings.NewReplicationStorageClassificationMappingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationStorageClassificationMappingsClient.Create` + +```go +ctx := context.TODO() +id := replicationstorageclassificationmappings.NewReplicationStorageClassificationMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue", "replicationStorageClassificationMappingValue") + +payload := replicationstorageclassificationmappings.StorageClassificationMappingInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationStorageClassificationMappingsClient.Delete` + +```go +ctx := context.TODO() +id := replicationstorageclassificationmappings.NewReplicationStorageClassificationMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue", "replicationStorageClassificationMappingValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationStorageClassificationMappingsClient.Get` + +```go +ctx := context.TODO() +id := replicationstorageclassificationmappings.NewReplicationStorageClassificationMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue", "replicationStorageClassificationMappingValue") + +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: `ReplicationStorageClassificationMappingsClient.List` + +```go +ctx := context.TODO() +id := replicationstorageclassificationmappings.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationStorageClassificationMappingsClient.ListByReplicationStorageClassifications` + +```go +ctx := context.TODO() +id := replicationstorageclassificationmappings.NewReplicationStorageClassificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue") + +// alternatively `client.ListByReplicationStorageClassifications(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationStorageClassificationsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/client.go new file mode 100644 index 00000000000..4392336cb00 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/client.go @@ -0,0 +1,18 @@ +package replicationstorageclassificationmappings + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationStorageClassificationMappingsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationStorageClassificationMappingsClientWithBaseURI(endpoint string) ReplicationStorageClassificationMappingsClient { + return ReplicationStorageClassificationMappingsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassification.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassification.go new file mode 100644 index 00000000000..40f2804ad5f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassification.go @@ -0,0 +1,153 @@ +package replicationstorageclassificationmappings + +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 = ReplicationStorageClassificationId{} + +// ReplicationStorageClassificationId is a struct representing the Resource ID for a Replication Storage Classification +type ReplicationStorageClassificationId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationStorageClassificationName string +} + +// NewReplicationStorageClassificationID returns a new ReplicationStorageClassificationId struct +func NewReplicationStorageClassificationID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationStorageClassificationName string) ReplicationStorageClassificationId { + return ReplicationStorageClassificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationStorageClassificationName: replicationStorageClassificationName, + } +} + +// ParseReplicationStorageClassificationID parses 'input' into a ReplicationStorageClassificationId +func ParseReplicationStorageClassificationID(input string) (*ReplicationStorageClassificationId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationStorageClassificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationStorageClassificationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationName, ok = parsed.Parsed["replicationStorageClassificationName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationStorageClassificationIDInsensitively parses 'input' case-insensitively into a ReplicationStorageClassificationId +// note: this method should only be used for API response data and not user input +func ParseReplicationStorageClassificationIDInsensitively(input string) (*ReplicationStorageClassificationId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationStorageClassificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationStorageClassificationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationName, ok = parsed.Parsed["replicationStorageClassificationName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationStorageClassificationID checks that 'input' can be parsed as a Replication Storage Classification ID +func ValidateReplicationStorageClassificationID(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 := ParseReplicationStorageClassificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Storage Classification ID +func (id ReplicationStorageClassificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationStorageClassifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationStorageClassificationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Storage Classification ID +func (id ReplicationStorageClassificationId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationStorageClassifications", "replicationStorageClassifications", "replicationStorageClassifications"), + resourceids.UserSpecifiedSegment("replicationStorageClassificationName", "replicationStorageClassificationValue"), + } +} + +// String returns a human-readable description of this Replication Storage Classification ID +func (id ReplicationStorageClassificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Storage Classification Name: %q", id.ReplicationStorageClassificationName), + } + return fmt.Sprintf("Replication Storage Classification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassification_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassification_test.go new file mode 100644 index 00000000000..6664b1c4caf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassification_test.go @@ -0,0 +1,372 @@ +package replicationstorageclassificationmappings + +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 = ReplicationStorageClassificationId{} + +func TestNewReplicationStorageClassificationID(t *testing.T) { + id := NewReplicationStorageClassificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationStorageClassificationName != "replicationStorageClassificationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationStorageClassificationName'", id.ReplicationStorageClassificationName, "replicationStorageClassificationValue") + } +} + +func TestFormatReplicationStorageClassificationID(t *testing.T) { + actual := NewReplicationStorageClassificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationStorageClassificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationStorageClassificationId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue", + Expected: &ReplicationStorageClassificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationStorageClassificationName: "replicationStorageClassificationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationStorageClassificationID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationStorageClassificationName != v.Expected.ReplicationStorageClassificationName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationName", v.Expected.ReplicationStorageClassificationName, actual.ReplicationStorageClassificationName) + } + + } +} + +func TestParseReplicationStorageClassificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationStorageClassificationId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue", + Expected: &ReplicationStorageClassificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationStorageClassificationName: "replicationStorageClassificationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe", + Expected: &ReplicationStorageClassificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationStorageClassificationName: "rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationStorageClassificationIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationStorageClassificationName != v.Expected.ReplicationStorageClassificationName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationName", v.Expected.ReplicationStorageClassificationName, actual.ReplicationStorageClassificationName) + } + + } +} + +func TestSegmentsForReplicationStorageClassificationId(t *testing.T) { + segments := ReplicationStorageClassificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationStorageClassificationId 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassificationmapping.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassificationmapping.go new file mode 100644 index 00000000000..35bdea7f953 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassificationmapping.go @@ -0,0 +1,166 @@ +package replicationstorageclassificationmappings + +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 = ReplicationStorageClassificationMappingId{} + +// ReplicationStorageClassificationMappingId is a struct representing the Resource ID for a Replication Storage Classification Mapping +type ReplicationStorageClassificationMappingId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationStorageClassificationName string + ReplicationStorageClassificationMappingName string +} + +// NewReplicationStorageClassificationMappingID returns a new ReplicationStorageClassificationMappingId struct +func NewReplicationStorageClassificationMappingID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationStorageClassificationName string, replicationStorageClassificationMappingName string) ReplicationStorageClassificationMappingId { + return ReplicationStorageClassificationMappingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationStorageClassificationName: replicationStorageClassificationName, + ReplicationStorageClassificationMappingName: replicationStorageClassificationMappingName, + } +} + +// ParseReplicationStorageClassificationMappingID parses 'input' into a ReplicationStorageClassificationMappingId +func ParseReplicationStorageClassificationMappingID(input string) (*ReplicationStorageClassificationMappingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationStorageClassificationMappingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationStorageClassificationMappingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationName, ok = parsed.Parsed["replicationStorageClassificationName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationMappingName, ok = parsed.Parsed["replicationStorageClassificationMappingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationMappingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationStorageClassificationMappingIDInsensitively parses 'input' case-insensitively into a ReplicationStorageClassificationMappingId +// note: this method should only be used for API response data and not user input +func ParseReplicationStorageClassificationMappingIDInsensitively(input string) (*ReplicationStorageClassificationMappingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationStorageClassificationMappingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationStorageClassificationMappingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationName, ok = parsed.Parsed["replicationStorageClassificationName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationMappingName, ok = parsed.Parsed["replicationStorageClassificationMappingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationMappingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationStorageClassificationMappingID checks that 'input' can be parsed as a Replication Storage Classification Mapping ID +func ValidateReplicationStorageClassificationMappingID(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 := ParseReplicationStorageClassificationMappingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Storage Classification Mapping ID +func (id ReplicationStorageClassificationMappingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationStorageClassifications/%s/replicationStorageClassificationMappings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationStorageClassificationName, id.ReplicationStorageClassificationMappingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Storage Classification Mapping ID +func (id ReplicationStorageClassificationMappingId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationStorageClassifications", "replicationStorageClassifications", "replicationStorageClassifications"), + resourceids.UserSpecifiedSegment("replicationStorageClassificationName", "replicationStorageClassificationValue"), + resourceids.StaticSegment("staticReplicationStorageClassificationMappings", "replicationStorageClassificationMappings", "replicationStorageClassificationMappings"), + resourceids.UserSpecifiedSegment("replicationStorageClassificationMappingName", "replicationStorageClassificationMappingValue"), + } +} + +// String returns a human-readable description of this Replication Storage Classification Mapping ID +func (id ReplicationStorageClassificationMappingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Storage Classification Name: %q", id.ReplicationStorageClassificationName), + fmt.Sprintf("Replication Storage Classification Mapping Name: %q", id.ReplicationStorageClassificationMappingName), + } + return fmt.Sprintf("Replication Storage Classification Mapping (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassificationmapping_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassificationmapping_test.go new file mode 100644 index 00000000000..f3d1be794c0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_replicationstorageclassificationmapping_test.go @@ -0,0 +1,417 @@ +package replicationstorageclassificationmappings + +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 = ReplicationStorageClassificationMappingId{} + +func TestNewReplicationStorageClassificationMappingID(t *testing.T) { + id := NewReplicationStorageClassificationMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue", "replicationStorageClassificationMappingValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationStorageClassificationName != "replicationStorageClassificationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationStorageClassificationName'", id.ReplicationStorageClassificationName, "replicationStorageClassificationValue") + } + + if id.ReplicationStorageClassificationMappingName != "replicationStorageClassificationMappingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationStorageClassificationMappingName'", id.ReplicationStorageClassificationMappingName, "replicationStorageClassificationMappingValue") + } +} + +func TestFormatReplicationStorageClassificationMappingID(t *testing.T) { + actual := NewReplicationStorageClassificationMappingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue", "replicationStorageClassificationMappingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/replicationStorageClassificationMappings/replicationStorageClassificationMappingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationStorageClassificationMappingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationStorageClassificationMappingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/replicationStorageClassificationMappings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/replicationStorageClassificationMappings/replicationStorageClassificationMappingValue", + Expected: &ReplicationStorageClassificationMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationStorageClassificationName: "replicationStorageClassificationValue", + ReplicationStorageClassificationMappingName: "replicationStorageClassificationMappingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/replicationStorageClassificationMappings/replicationStorageClassificationMappingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationStorageClassificationMappingID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationStorageClassificationName != v.Expected.ReplicationStorageClassificationName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationName", v.Expected.ReplicationStorageClassificationName, actual.ReplicationStorageClassificationName) + } + + if actual.ReplicationStorageClassificationMappingName != v.Expected.ReplicationStorageClassificationMappingName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationMappingName", v.Expected.ReplicationStorageClassificationMappingName, actual.ReplicationStorageClassificationMappingName) + } + + } +} + +func TestParseReplicationStorageClassificationMappingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationStorageClassificationMappingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/replicationStorageClassificationMappings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNmApPiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/replicationStorageClassificationMappings/replicationStorageClassificationMappingValue", + Expected: &ReplicationStorageClassificationMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationStorageClassificationName: "replicationStorageClassificationValue", + ReplicationStorageClassificationMappingName: "replicationStorageClassificationMappingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/replicationStorageClassificationMappings/replicationStorageClassificationMappingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNmApPiNgS/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNmApPiNgVaLuE", + Expected: &ReplicationStorageClassificationMappingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationStorageClassificationName: "rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe", + ReplicationStorageClassificationMappingName: "rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNmApPiNgVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNmApPiNgS/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNmApPiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationStorageClassificationMappingIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationStorageClassificationName != v.Expected.ReplicationStorageClassificationName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationName", v.Expected.ReplicationStorageClassificationName, actual.ReplicationStorageClassificationName) + } + + if actual.ReplicationStorageClassificationMappingName != v.Expected.ReplicationStorageClassificationMappingName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationMappingName", v.Expected.ReplicationStorageClassificationMappingName, actual.ReplicationStorageClassificationMappingName) + } + + } +} + +func TestSegmentsForReplicationStorageClassificationMappingId(t *testing.T) { + segments := ReplicationStorageClassificationMappingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationStorageClassificationMappingId 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_vault.go new file mode 100644 index 00000000000..3cd9f566f75 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_vault.go @@ -0,0 +1,127 @@ +package replicationstorageclassificationmappings + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_vault_test.go new file mode 100644 index 00000000000..3e5c8e244a6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationstorageclassificationmappings + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_create_autorest.go new file mode 100644 index 00000000000..2ab5557f08c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationstorageclassificationmappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationStorageClassificationMappingsClient) Create(ctx context.Context, id ReplicationStorageClassificationMappingId, input StorageClassificationMappingInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationStorageClassificationMappingsClient) CreateThenPoll(ctx context.Context, id ReplicationStorageClassificationMappingId, input StorageClassificationMappingInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationStorageClassificationMappingsClient) preparerForCreate(ctx context.Context, id ReplicationStorageClassificationMappingId, input StorageClassificationMappingInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationStorageClassificationMappingsClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_delete_autorest.go new file mode 100644 index 00000000000..18c0caf38cc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationstorageclassificationmappings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationStorageClassificationMappingsClient) Delete(ctx context.Context, id ReplicationStorageClassificationMappingId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationStorageClassificationMappingsClient) DeleteThenPoll(ctx context.Context, id ReplicationStorageClassificationMappingId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationStorageClassificationMappingsClient) preparerForDelete(ctx context.Context, id ReplicationStorageClassificationMappingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationStorageClassificationMappingsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_get_autorest.go new file mode 100644 index 00000000000..8a55bc32e2a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationstorageclassificationmappings + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *StorageClassificationMapping +} + +// Get ... +func (c ReplicationStorageClassificationMappingsClient) Get(ctx context.Context, id ReplicationStorageClassificationMappingId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationStorageClassificationMappingsClient) preparerForGet(ctx context.Context, id ReplicationStorageClassificationMappingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationStorageClassificationMappingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_list_autorest.go new file mode 100644 index 00000000000..cead9090583 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationstorageclassificationmappings + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]StorageClassificationMapping + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []StorageClassificationMapping +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationStorageClassificationMappingsClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationStorageClassificationMappingsClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationStorageClassificationMappings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationStorageClassificationMappingsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationStorageClassificationMappingsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []StorageClassificationMapping `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationStorageClassificationMappingsClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, StorageClassificationMappingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationStorageClassificationMappingsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate StorageClassificationMappingOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]StorageClassificationMapping, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_listbyreplicationstorageclassifications_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_listbyreplicationstorageclassifications_autorest.go new file mode 100644 index 00000000000..80295ef047b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/method_listbyreplicationstorageclassifications_autorest.go @@ -0,0 +1,186 @@ +package replicationstorageclassificationmappings + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationStorageClassificationsOperationResponse struct { + HttpResponse *http.Response + Model *[]StorageClassificationMapping + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationStorageClassificationsOperationResponse, error) +} + +type ListByReplicationStorageClassificationsCompleteResult struct { + Items []StorageClassificationMapping +} + +func (r ListByReplicationStorageClassificationsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationStorageClassificationsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationStorageClassificationsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationStorageClassifications ... +func (c ReplicationStorageClassificationMappingsClient) ListByReplicationStorageClassifications(ctx context.Context, id ReplicationStorageClassificationId) (resp ListByReplicationStorageClassificationsOperationResponse, err error) { + req, err := c.preparerForListByReplicationStorageClassifications(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "ListByReplicationStorageClassifications", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "ListByReplicationStorageClassifications", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationStorageClassifications(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "ListByReplicationStorageClassifications", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationStorageClassifications prepares the ListByReplicationStorageClassifications request. +func (c ReplicationStorageClassificationMappingsClient) preparerForListByReplicationStorageClassifications(ctx context.Context, id ReplicationStorageClassificationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationStorageClassificationMappings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationStorageClassificationsWithNextLink prepares the ListByReplicationStorageClassifications request with the given nextLink token. +func (c ReplicationStorageClassificationMappingsClient) preparerForListByReplicationStorageClassificationsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationStorageClassifications handles the response to the ListByReplicationStorageClassifications request. The method always +// closes the http.Response Body. +func (c ReplicationStorageClassificationMappingsClient) responderForListByReplicationStorageClassifications(resp *http.Response) (result ListByReplicationStorageClassificationsOperationResponse, err error) { + type page struct { + Values []StorageClassificationMapping `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationStorageClassificationsOperationResponse, err error) { + req, err := c.preparerForListByReplicationStorageClassificationsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "ListByReplicationStorageClassifications", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "ListByReplicationStorageClassifications", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationStorageClassifications(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassificationmappings.ReplicationStorageClassificationMappingsClient", "ListByReplicationStorageClassifications", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationStorageClassificationsComplete retrieves all of the results into a single object +func (c ReplicationStorageClassificationMappingsClient) ListByReplicationStorageClassificationsComplete(ctx context.Context, id ReplicationStorageClassificationId) (ListByReplicationStorageClassificationsCompleteResult, error) { + return c.ListByReplicationStorageClassificationsCompleteMatchingPredicate(ctx, id, StorageClassificationMappingOperationPredicate{}) +} + +// ListByReplicationStorageClassificationsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationStorageClassificationMappingsClient) ListByReplicationStorageClassificationsCompleteMatchingPredicate(ctx context.Context, id ReplicationStorageClassificationId, predicate StorageClassificationMappingOperationPredicate) (resp ListByReplicationStorageClassificationsCompleteResult, err error) { + items := make([]StorageClassificationMapping, 0) + + page, err := c.ListByReplicationStorageClassifications(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationStorageClassificationsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmapping.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmapping.go new file mode 100644 index 00000000000..70642e74bca --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmapping.go @@ -0,0 +1,12 @@ +package replicationstorageclassificationmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageClassificationMapping struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StorageClassificationMappingProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmappinginput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmappinginput.go new file mode 100644 index 00000000000..158940ea210 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmappinginput.go @@ -0,0 +1,8 @@ +package replicationstorageclassificationmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageClassificationMappingInput struct { + Properties *StorageMappingInputProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmappingproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmappingproperties.go new file mode 100644 index 00000000000..0b0d8c58bea --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storageclassificationmappingproperties.go @@ -0,0 +1,8 @@ +package replicationstorageclassificationmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageClassificationMappingProperties struct { + TargetStorageClassificationId *string `json:"targetStorageClassificationId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storagemappinginputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storagemappinginputproperties.go new file mode 100644 index 00000000000..7dc80064316 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/model_storagemappinginputproperties.go @@ -0,0 +1,8 @@ +package replicationstorageclassificationmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageMappingInputProperties struct { + TargetStorageClassificationId *string `json:"targetStorageClassificationId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/predicates.go new file mode 100644 index 00000000000..46b7f3a60ab --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/predicates.go @@ -0,0 +1,32 @@ +package replicationstorageclassificationmappings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageClassificationMappingOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p StorageClassificationMappingOperationPredicate) Matches(input StorageClassificationMapping) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/version.go new file mode 100644 index 00000000000..60eba51d06b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassificationmappings/version.go @@ -0,0 +1,12 @@ +package replicationstorageclassificationmappings + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationstorageclassificationmappings/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/README.md new file mode 100644 index 00000000000..ec43c6c2e7b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications` Documentation + +The `replicationstorageclassifications` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications" +``` + + +### Client Initialization + +```go +client := replicationstorageclassifications.NewReplicationStorageClassificationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationStorageClassificationsClient.Get` + +```go +ctx := context.TODO() +id := replicationstorageclassifications.NewReplicationStorageClassificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue") + +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: `ReplicationStorageClassificationsClient.List` + +```go +ctx := context.TODO() +id := replicationstorageclassifications.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationStorageClassificationsClient.ListByReplicationFabrics` + +```go +ctx := context.TODO() +id := replicationstorageclassifications.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +// alternatively `client.ListByReplicationFabrics(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationFabricsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/client.go new file mode 100644 index 00000000000..9df23c74282 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/client.go @@ -0,0 +1,18 @@ +package replicationstorageclassifications + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationStorageClassificationsClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationStorageClassificationsClientWithBaseURI(endpoint string) ReplicationStorageClassificationsClient { + return ReplicationStorageClassificationsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationfabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationfabric.go new file mode 100644 index 00000000000..c68e7fe37a4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationstorageclassifications + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationfabric_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationfabric_test.go new file mode 100644 index 00000000000..50eefe28bdc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationfabric_test.go @@ -0,0 +1,327 @@ +package replicationstorageclassifications + +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 = ReplicationFabricId{} + +func TestNewReplicationFabricID(t *testing.T) { + id := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } +} + +func TestFormatReplicationFabricID(t *testing.T) { + actual := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestParseReplicationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestSegmentsForReplicationFabricId(t *testing.T) { + segments := ReplicationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationFabricId 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationstorageclassification.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationstorageclassification.go new file mode 100644 index 00000000000..869777c7650 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationstorageclassification.go @@ -0,0 +1,153 @@ +package replicationstorageclassifications + +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 = ReplicationStorageClassificationId{} + +// ReplicationStorageClassificationId is a struct representing the Resource ID for a Replication Storage Classification +type ReplicationStorageClassificationId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationStorageClassificationName string +} + +// NewReplicationStorageClassificationID returns a new ReplicationStorageClassificationId struct +func NewReplicationStorageClassificationID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationStorageClassificationName string) ReplicationStorageClassificationId { + return ReplicationStorageClassificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationStorageClassificationName: replicationStorageClassificationName, + } +} + +// ParseReplicationStorageClassificationID parses 'input' into a ReplicationStorageClassificationId +func ParseReplicationStorageClassificationID(input string) (*ReplicationStorageClassificationId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationStorageClassificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationStorageClassificationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationName, ok = parsed.Parsed["replicationStorageClassificationName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationStorageClassificationIDInsensitively parses 'input' case-insensitively into a ReplicationStorageClassificationId +// note: this method should only be used for API response data and not user input +func ParseReplicationStorageClassificationIDInsensitively(input string) (*ReplicationStorageClassificationId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationStorageClassificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationStorageClassificationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationStorageClassificationName, ok = parsed.Parsed["replicationStorageClassificationName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationStorageClassificationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationStorageClassificationID checks that 'input' can be parsed as a Replication Storage Classification ID +func ValidateReplicationStorageClassificationID(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 := ParseReplicationStorageClassificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Storage Classification ID +func (id ReplicationStorageClassificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationStorageClassifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationStorageClassificationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Storage Classification ID +func (id ReplicationStorageClassificationId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationStorageClassifications", "replicationStorageClassifications", "replicationStorageClassifications"), + resourceids.UserSpecifiedSegment("replicationStorageClassificationName", "replicationStorageClassificationValue"), + } +} + +// String returns a human-readable description of this Replication Storage Classification ID +func (id ReplicationStorageClassificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Storage Classification Name: %q", id.ReplicationStorageClassificationName), + } + return fmt.Sprintf("Replication Storage Classification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationstorageclassification_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationstorageclassification_test.go new file mode 100644 index 00000000000..3dcd256ad22 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_replicationstorageclassification_test.go @@ -0,0 +1,372 @@ +package replicationstorageclassifications + +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 = ReplicationStorageClassificationId{} + +func TestNewReplicationStorageClassificationID(t *testing.T) { + id := NewReplicationStorageClassificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationStorageClassificationName != "replicationStorageClassificationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationStorageClassificationName'", id.ReplicationStorageClassificationName, "replicationStorageClassificationValue") + } +} + +func TestFormatReplicationStorageClassificationID(t *testing.T) { + actual := NewReplicationStorageClassificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationStorageClassificationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationStorageClassificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationStorageClassificationId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue", + Expected: &ReplicationStorageClassificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationStorageClassificationName: "replicationStorageClassificationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationStorageClassificationID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationStorageClassificationName != v.Expected.ReplicationStorageClassificationName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationName", v.Expected.ReplicationStorageClassificationName, actual.ReplicationStorageClassificationName) + } + + } +} + +func TestParseReplicationStorageClassificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationStorageClassificationId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue", + Expected: &ReplicationStorageClassificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationStorageClassificationName: "replicationStorageClassificationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationStorageClassifications/replicationStorageClassificationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe", + Expected: &ReplicationStorageClassificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationStorageClassificationName: "rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNs/rEpLiCaTiOnStOrAgEcLaSsIfIcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationStorageClassificationIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationStorageClassificationName != v.Expected.ReplicationStorageClassificationName { + t.Fatalf("Expected %q but got %q for ReplicationStorageClassificationName", v.Expected.ReplicationStorageClassificationName, actual.ReplicationStorageClassificationName) + } + + } +} + +func TestSegmentsForReplicationStorageClassificationId(t *testing.T) { + segments := ReplicationStorageClassificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationStorageClassificationId 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_vault.go new file mode 100644 index 00000000000..2015e7df077 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_vault.go @@ -0,0 +1,127 @@ +package replicationstorageclassifications + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_vault_test.go new file mode 100644 index 00000000000..a0f301e52c3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationstorageclassifications + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_get_autorest.go new file mode 100644 index 00000000000..315e9f84881 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationstorageclassifications + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *StorageClassification +} + +// Get ... +func (c ReplicationStorageClassificationsClient) Get(ctx context.Context, id ReplicationStorageClassificationId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationStorageClassificationsClient) preparerForGet(ctx context.Context, id ReplicationStorageClassificationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationStorageClassificationsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_list_autorest.go new file mode 100644 index 00000000000..1ddc83b486f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationstorageclassifications + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]StorageClassification + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []StorageClassification +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationStorageClassificationsClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationStorageClassificationsClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationStorageClassifications", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationStorageClassificationsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationStorageClassificationsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []StorageClassification `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationStorageClassificationsClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, StorageClassificationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationStorageClassificationsClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate StorageClassificationOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]StorageClassification, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_listbyreplicationfabrics_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_listbyreplicationfabrics_autorest.go new file mode 100644 index 00000000000..b92ef72caf7 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/method_listbyreplicationfabrics_autorest.go @@ -0,0 +1,186 @@ +package replicationstorageclassifications + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationFabricsOperationResponse struct { + HttpResponse *http.Response + Model *[]StorageClassification + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationFabricsOperationResponse, error) +} + +type ListByReplicationFabricsCompleteResult struct { + Items []StorageClassification +} + +func (r ListByReplicationFabricsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationFabricsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationFabricsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationFabrics ... +func (c ReplicationStorageClassificationsClient) ListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (resp ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabrics(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationFabrics(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationFabrics prepares the ListByReplicationFabrics request. +func (c ReplicationStorageClassificationsClient) preparerForListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationStorageClassifications", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationFabricsWithNextLink prepares the ListByReplicationFabrics request with the given nextLink token. +func (c ReplicationStorageClassificationsClient) preparerForListByReplicationFabricsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationFabrics handles the response to the ListByReplicationFabrics request. The method always +// closes the http.Response Body. +func (c ReplicationStorageClassificationsClient) responderForListByReplicationFabrics(resp *http.Response) (result ListByReplicationFabricsOperationResponse, err error) { + type page struct { + Values []StorageClassification `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabricsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "ListByReplicationFabrics", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationFabrics(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationstorageclassifications.ReplicationStorageClassificationsClient", "ListByReplicationFabrics", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationFabricsComplete retrieves all of the results into a single object +func (c ReplicationStorageClassificationsClient) ListByReplicationFabricsComplete(ctx context.Context, id ReplicationFabricId) (ListByReplicationFabricsCompleteResult, error) { + return c.ListByReplicationFabricsCompleteMatchingPredicate(ctx, id, StorageClassificationOperationPredicate{}) +} + +// ListByReplicationFabricsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationStorageClassificationsClient) ListByReplicationFabricsCompleteMatchingPredicate(ctx context.Context, id ReplicationFabricId, predicate StorageClassificationOperationPredicate) (resp ListByReplicationFabricsCompleteResult, err error) { + items := make([]StorageClassification, 0) + + page, err := c.ListByReplicationFabrics(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationFabricsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/model_storageclassification.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/model_storageclassification.go new file mode 100644 index 00000000000..dfe018bfb1c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/model_storageclassification.go @@ -0,0 +1,12 @@ +package replicationstorageclassifications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageClassification struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StorageClassificationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/model_storageclassificationproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/model_storageclassificationproperties.go new file mode 100644 index 00000000000..1d077061afd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/model_storageclassificationproperties.go @@ -0,0 +1,8 @@ +package replicationstorageclassifications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageClassificationProperties struct { + FriendlyName *string `json:"friendlyName,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/predicates.go new file mode 100644 index 00000000000..5b1ee94ed56 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/predicates.go @@ -0,0 +1,32 @@ +package replicationstorageclassifications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageClassificationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p StorageClassificationOperationPredicate) Matches(input StorageClassification) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/version.go new file mode 100644 index 00000000000..cb845bdce05 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationstorageclassifications/version.go @@ -0,0 +1,12 @@ +package replicationstorageclassifications + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationstorageclassifications/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/README.md new file mode 100644 index 00000000000..d6333bc69fd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/README.md @@ -0,0 +1,48 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth` Documentation + +The `replicationvaulthealth` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth" +``` + + +### Client Initialization + +```go +client := replicationvaulthealth.NewReplicationVaultHealthClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationVaultHealthClient.Get` + +```go +ctx := context.TODO() +id := replicationvaulthealth.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +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: `ReplicationVaultHealthClient.Refresh` + +```go +ctx := context.TODO() +id := replicationvaulthealth.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +if err := client.RefreshThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/client.go new file mode 100644 index 00000000000..1afc4a3dde4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/client.go @@ -0,0 +1,18 @@ +package replicationvaulthealth + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationVaultHealthClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationVaultHealthClientWithBaseURI(endpoint string) ReplicationVaultHealthClient { + return ReplicationVaultHealthClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/constants.go new file mode 100644 index 00000000000..a0e8e9637a2 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/constants.go @@ -0,0 +1,123 @@ +package replicationvaulthealth + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthErrorCategory string + +const ( + HealthErrorCategoryAgentAutoUpdateArtifactDeleted HealthErrorCategory = "AgentAutoUpdateArtifactDeleted" + HealthErrorCategoryAgentAutoUpdateInfra HealthErrorCategory = "AgentAutoUpdateInfra" + HealthErrorCategoryAgentAutoUpdateRunAsAccount HealthErrorCategory = "AgentAutoUpdateRunAsAccount" + HealthErrorCategoryAgentAutoUpdateRunAsAccountExpired HealthErrorCategory = "AgentAutoUpdateRunAsAccountExpired" + HealthErrorCategoryAgentAutoUpdateRunAsAccountExpiry HealthErrorCategory = "AgentAutoUpdateRunAsAccountExpiry" + HealthErrorCategoryConfiguration HealthErrorCategory = "Configuration" + HealthErrorCategoryFabricInfrastructure HealthErrorCategory = "FabricInfrastructure" + HealthErrorCategoryNone HealthErrorCategory = "None" + HealthErrorCategoryReplication HealthErrorCategory = "Replication" + HealthErrorCategoryTestFailover HealthErrorCategory = "TestFailover" + HealthErrorCategoryVersionExpiry HealthErrorCategory = "VersionExpiry" +) + +func PossibleValuesForHealthErrorCategory() []string { + return []string{ + string(HealthErrorCategoryAgentAutoUpdateArtifactDeleted), + string(HealthErrorCategoryAgentAutoUpdateInfra), + string(HealthErrorCategoryAgentAutoUpdateRunAsAccount), + string(HealthErrorCategoryAgentAutoUpdateRunAsAccountExpired), + string(HealthErrorCategoryAgentAutoUpdateRunAsAccountExpiry), + string(HealthErrorCategoryConfiguration), + string(HealthErrorCategoryFabricInfrastructure), + string(HealthErrorCategoryNone), + string(HealthErrorCategoryReplication), + string(HealthErrorCategoryTestFailover), + string(HealthErrorCategoryVersionExpiry), + } +} + +func parseHealthErrorCategory(input string) (*HealthErrorCategory, error) { + vals := map[string]HealthErrorCategory{ + "agentautoupdateartifactdeleted": HealthErrorCategoryAgentAutoUpdateArtifactDeleted, + "agentautoupdateinfra": HealthErrorCategoryAgentAutoUpdateInfra, + "agentautoupdaterunasaccount": HealthErrorCategoryAgentAutoUpdateRunAsAccount, + "agentautoupdaterunasaccountexpired": HealthErrorCategoryAgentAutoUpdateRunAsAccountExpired, + "agentautoupdaterunasaccountexpiry": HealthErrorCategoryAgentAutoUpdateRunAsAccountExpiry, + "configuration": HealthErrorCategoryConfiguration, + "fabricinfrastructure": HealthErrorCategoryFabricInfrastructure, + "none": HealthErrorCategoryNone, + "replication": HealthErrorCategoryReplication, + "testfailover": HealthErrorCategoryTestFailover, + "versionexpiry": HealthErrorCategoryVersionExpiry, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCategory(input) + return &out, nil +} + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} + +type Severity string + +const ( + SeverityError Severity = "Error" + SeverityInfo Severity = "Info" + SeverityNONE Severity = "NONE" + SeverityWarning Severity = "Warning" +) + +func PossibleValuesForSeverity() []string { + return []string{ + string(SeverityError), + string(SeverityInfo), + string(SeverityNONE), + string(SeverityWarning), + } +} + +func parseSeverity(input string) (*Severity, error) { + vals := map[string]Severity{ + "error": SeverityError, + "info": SeverityInfo, + "none": SeverityNONE, + "warning": SeverityWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Severity(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/id_vault.go new file mode 100644 index 00000000000..9c4651ef47e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/id_vault.go @@ -0,0 +1,127 @@ +package replicationvaulthealth + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/id_vault_test.go new file mode 100644 index 00000000000..ebca03a2d94 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationvaulthealth + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/method_get_autorest.go new file mode 100644 index 00000000000..85ce5cdd0f0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/method_get_autorest.go @@ -0,0 +1,69 @@ +package replicationvaulthealth + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *VaultHealthDetails +} + +// Get ... +func (c ReplicationVaultHealthClient) Get(ctx context.Context, id VaultId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaulthealth.ReplicationVaultHealthClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaulthealth.ReplicationVaultHealthClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaulthealth.ReplicationVaultHealthClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationVaultHealthClient) preparerForGet(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationVaultHealth", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationVaultHealthClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/method_refresh_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/method_refresh_autorest.go new file mode 100644 index 00000000000..8f075fb6851 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/method_refresh_autorest.go @@ -0,0 +1,78 @@ +package replicationvaulthealth + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Refresh ... +func (c ReplicationVaultHealthClient) Refresh(ctx context.Context, id VaultId) (result RefreshOperationResponse, err error) { + req, err := c.preparerForRefresh(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaulthealth.ReplicationVaultHealthClient", "Refresh", nil, "Failure preparing request") + return + } + + result, err = c.senderForRefresh(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaulthealth.ReplicationVaultHealthClient", "Refresh", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RefreshThenPoll performs Refresh then polls until it's completed +func (c ReplicationVaultHealthClient) RefreshThenPoll(ctx context.Context, id VaultId) error { + result, err := c.Refresh(ctx, id) + if err != nil { + return fmt.Errorf("performing Refresh: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Refresh: %+v", err) + } + + return nil +} + +// preparerForRefresh prepares the Refresh request. +func (c ReplicationVaultHealthClient) preparerForRefresh(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationVaultHealth/default/refresh", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRefresh sends the Refresh request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationVaultHealthClient) senderForRefresh(ctx context.Context, req *http.Request) (future RefreshOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_healtherror.go new file mode 100644 index 00000000000..a1cded61cd6 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationvaulthealth + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_healtherrorsummary.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_healtherrorsummary.go new file mode 100644 index 00000000000..7a99b52ddd8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_healtherrorsummary.go @@ -0,0 +1,14 @@ +package replicationvaulthealth + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthErrorSummary struct { + AffectedResourceCorrelationIds *[]string `json:"affectedResourceCorrelationIds,omitempty"` + AffectedResourceSubtype *string `json:"affectedResourceSubtype,omitempty"` + AffectedResourceType *string `json:"affectedResourceType,omitempty"` + Category *HealthErrorCategory `json:"category,omitempty"` + Severity *Severity `json:"severity,omitempty"` + SummaryCode *string `json:"summaryCode,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_innerhealtherror.go new file mode 100644 index 00000000000..f01babb170f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationvaulthealth + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_resourcehealthsummary.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_resourcehealthsummary.go new file mode 100644 index 00000000000..6238fa00867 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_resourcehealthsummary.go @@ -0,0 +1,10 @@ +package replicationvaulthealth + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceHealthSummary struct { + CategorizedResourceCounts *map[string]int64 `json:"categorizedResourceCounts,omitempty"` + Issues *[]HealthErrorSummary `json:"issues,omitempty"` + ResourceCount *int64 `json:"resourceCount,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_vaulthealthdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_vaulthealthdetails.go new file mode 100644 index 00000000000..2c0736a7902 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_vaulthealthdetails.go @@ -0,0 +1,12 @@ +package replicationvaulthealth + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultHealthDetails struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VaultHealthProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_vaulthealthproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_vaulthealthproperties.go new file mode 100644 index 00000000000..d17dd6d82bc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/model_vaulthealthproperties.go @@ -0,0 +1,11 @@ +package replicationvaulthealth + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultHealthProperties struct { + ContainersHealth *ResourceHealthSummary `json:"containersHealth,omitempty"` + FabricsHealth *ResourceHealthSummary `json:"fabricsHealth,omitempty"` + ProtectedItemsHealth *ResourceHealthSummary `json:"protectedItemsHealth,omitempty"` + VaultErrors *[]HealthError `json:"vaultErrors,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/version.go new file mode 100644 index 00000000000..c6354f7cabb --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaulthealth/version.go @@ -0,0 +1,12 @@ +package replicationvaulthealth + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationvaulthealth/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/README.md new file mode 100644 index 00000000000..588d9f2d8f4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting` Documentation + +The `replicationvaultsetting` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting" +``` + + +### Client Initialization + +```go +client := replicationvaultsetting.NewReplicationVaultSettingClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationVaultSettingClient.Create` + +```go +ctx := context.TODO() +id := replicationvaultsetting.NewReplicationVaultSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationVaultSettingValue") + +payload := replicationvaultsetting.VaultSettingCreationInput{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationVaultSettingClient.Get` + +```go +ctx := context.TODO() +id := replicationvaultsetting.NewReplicationVaultSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationVaultSettingValue") + +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: `ReplicationVaultSettingClient.List` + +```go +ctx := context.TODO() +id := replicationvaultsetting.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/client.go new file mode 100644 index 00000000000..d85e6ba8650 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/client.go @@ -0,0 +1,18 @@ +package replicationvaultsetting + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationVaultSettingClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationVaultSettingClientWithBaseURI(endpoint string) ReplicationVaultSettingClient { + return ReplicationVaultSettingClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_replicationvaultsetting.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_replicationvaultsetting.go new file mode 100644 index 00000000000..12fce592075 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_replicationvaultsetting.go @@ -0,0 +1,140 @@ +package replicationvaultsetting + +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 = ReplicationVaultSettingId{} + +// ReplicationVaultSettingId is a struct representing the Resource ID for a Replication Vault Setting +type ReplicationVaultSettingId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationVaultSettingName string +} + +// NewReplicationVaultSettingID returns a new ReplicationVaultSettingId struct +func NewReplicationVaultSettingID(subscriptionId string, resourceGroupName string, vaultName string, replicationVaultSettingName string) ReplicationVaultSettingId { + return ReplicationVaultSettingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationVaultSettingName: replicationVaultSettingName, + } +} + +// ParseReplicationVaultSettingID parses 'input' into a ReplicationVaultSettingId +func ParseReplicationVaultSettingID(input string) (*ReplicationVaultSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationVaultSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationVaultSettingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationVaultSettingName, ok = parsed.Parsed["replicationVaultSettingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationVaultSettingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationVaultSettingIDInsensitively parses 'input' case-insensitively into a ReplicationVaultSettingId +// note: this method should only be used for API response data and not user input +func ParseReplicationVaultSettingIDInsensitively(input string) (*ReplicationVaultSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationVaultSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationVaultSettingId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationVaultSettingName, ok = parsed.Parsed["replicationVaultSettingName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationVaultSettingName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationVaultSettingID checks that 'input' can be parsed as a Replication Vault Setting ID +func ValidateReplicationVaultSettingID(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 := ParseReplicationVaultSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Vault Setting ID +func (id ReplicationVaultSettingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationVaultSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationVaultSettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Vault Setting ID +func (id ReplicationVaultSettingId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationVaultSettings", "replicationVaultSettings", "replicationVaultSettings"), + resourceids.UserSpecifiedSegment("replicationVaultSettingName", "replicationVaultSettingValue"), + } +} + +// String returns a human-readable description of this Replication Vault Setting ID +func (id ReplicationVaultSettingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Vault Setting Name: %q", id.ReplicationVaultSettingName), + } + return fmt.Sprintf("Replication Vault Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_replicationvaultsetting_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_replicationvaultsetting_test.go new file mode 100644 index 00000000000..02a4de5f7ad --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_replicationvaultsetting_test.go @@ -0,0 +1,327 @@ +package replicationvaultsetting + +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 = ReplicationVaultSettingId{} + +func TestNewReplicationVaultSettingID(t *testing.T) { + id := NewReplicationVaultSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationVaultSettingValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationVaultSettingName != "replicationVaultSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationVaultSettingName'", id.ReplicationVaultSettingName, "replicationVaultSettingValue") + } +} + +func TestFormatReplicationVaultSettingID(t *testing.T) { + actual := NewReplicationVaultSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationVaultSettingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationVaultSettings/replicationVaultSettingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationVaultSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationVaultSettingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationVaultSettings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationVaultSettings/replicationVaultSettingValue", + Expected: &ReplicationVaultSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationVaultSettingName: "replicationVaultSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationVaultSettings/replicationVaultSettingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationVaultSettingID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationVaultSettingName != v.Expected.ReplicationVaultSettingName { + t.Fatalf("Expected %q but got %q for ReplicationVaultSettingName", v.Expected.ReplicationVaultSettingName, actual.ReplicationVaultSettingName) + } + + } +} + +func TestParseReplicationVaultSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationVaultSettingId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationVaultSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnVaUlTsEtTiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationVaultSettings/replicationVaultSettingValue", + Expected: &ReplicationVaultSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationVaultSettingName: "replicationVaultSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationVaultSettings/replicationVaultSettingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnVaUlTsEtTiNgS/rEpLiCaTiOnVaUlTsEtTiNgVaLuE", + Expected: &ReplicationVaultSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationVaultSettingName: "rEpLiCaTiOnVaUlTsEtTiNgVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnVaUlTsEtTiNgS/rEpLiCaTiOnVaUlTsEtTiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationVaultSettingIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationVaultSettingName != v.Expected.ReplicationVaultSettingName { + t.Fatalf("Expected %q but got %q for ReplicationVaultSettingName", v.Expected.ReplicationVaultSettingName, actual.ReplicationVaultSettingName) + } + + } +} + +func TestSegmentsForReplicationVaultSettingId(t *testing.T) { + segments := ReplicationVaultSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationVaultSettingId 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/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_vault.go new file mode 100644 index 00000000000..c799274598d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_vault.go @@ -0,0 +1,127 @@ +package replicationvaultsetting + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_vault_test.go new file mode 100644 index 00000000000..7a3126ce131 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationvaultsetting + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_create_autorest.go new file mode 100644 index 00000000000..a14934f53ba --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationvaultsetting + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationVaultSettingClient) Create(ctx context.Context, id ReplicationVaultSettingId, input VaultSettingCreationInput) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationVaultSettingClient) CreateThenPoll(ctx context.Context, id ReplicationVaultSettingId, input VaultSettingCreationInput) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationVaultSettingClient) preparerForCreate(ctx context.Context, id ReplicationVaultSettingId, input VaultSettingCreationInput) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationVaultSettingClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_get_autorest.go new file mode 100644 index 00000000000..e9f944e4022 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationvaultsetting + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *VaultSetting +} + +// Get ... +func (c ReplicationVaultSettingClient) Get(ctx context.Context, id ReplicationVaultSettingId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationVaultSettingClient) preparerForGet(ctx context.Context, id ReplicationVaultSettingId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationVaultSettingClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_list_autorest.go new file mode 100644 index 00000000000..007f76294c4 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationvaultsetting + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]VaultSetting + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []VaultSetting +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationVaultSettingClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationVaultSettingClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationVaultSettings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationVaultSettingClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationVaultSettingClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []VaultSetting `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvaultsetting.ReplicationVaultSettingClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationVaultSettingClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, VaultSettingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationVaultSettingClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate VaultSettingOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]VaultSetting, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsetting.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsetting.go new file mode 100644 index 00000000000..da949586ad3 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsetting.go @@ -0,0 +1,12 @@ +package replicationvaultsetting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultSetting struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VaultSettingProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingcreationinput.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingcreationinput.go new file mode 100644 index 00000000000..ea6dddb61aa --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingcreationinput.go @@ -0,0 +1,8 @@ +package replicationvaultsetting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultSettingCreationInput struct { + Properties VaultSettingCreationInputProperties `json:"properties"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingcreationinputproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingcreationinputproperties.go new file mode 100644 index 00000000000..d7654ac5546 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingcreationinputproperties.go @@ -0,0 +1,9 @@ +package replicationvaultsetting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultSettingCreationInputProperties struct { + MigrationSolutionId *string `json:"migrationSolutionId,omitempty"` + VMwareToAzureProviderType *string `json:"vmwareToAzureProviderType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingproperties.go new file mode 100644 index 00000000000..c90471f30f5 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/model_vaultsettingproperties.go @@ -0,0 +1,9 @@ +package replicationvaultsetting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultSettingProperties struct { + MigrationSolutionId *string `json:"migrationSolutionId,omitempty"` + VMwareToAzureProviderType *string `json:"vmwareToAzureProviderType,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/predicates.go new file mode 100644 index 00000000000..408c4504a31 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/predicates.go @@ -0,0 +1,32 @@ +package replicationvaultsetting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaultSettingOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p VaultSettingOperationPredicate) Matches(input VaultSetting) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/version.go new file mode 100644 index 00000000000..336a57892bf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvaultsetting/version.go @@ -0,0 +1,12 @@ +package replicationvaultsetting + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationvaultsetting/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/README.md new file mode 100644 index 00000000000..6452ecddf40 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters` Documentation + +The `replicationvcenters` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/replicationvcenters" +``` + + +### Client Initialization + +```go +client := replicationvcenters.NewReplicationvCentersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationvCentersClient.Create` + +```go +ctx := context.TODO() +id := replicationvcenters.NewReplicationvCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationvCenterValue") + +payload := replicationvcenters.AddVCenterRequest{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationvCentersClient.Delete` + +```go +ctx := context.TODO() +id := replicationvcenters.NewReplicationvCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationvCenterValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationvCentersClient.Get` + +```go +ctx := context.TODO() +id := replicationvcenters.NewReplicationvCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationvCenterValue") + +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: `ReplicationvCentersClient.List` + +```go +ctx := context.TODO() +id := replicationvcenters.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +// 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: `ReplicationvCentersClient.ListByReplicationFabrics` + +```go +ctx := context.TODO() +id := replicationvcenters.NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + +// alternatively `client.ListByReplicationFabrics(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationFabricsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationvCentersClient.Update` + +```go +ctx := context.TODO() +id := replicationvcenters.NewReplicationvCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationvCenterValue") + +payload := replicationvcenters.UpdateVCenterRequest{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/client.go new file mode 100644 index 00000000000..8bc20ae903c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/client.go @@ -0,0 +1,18 @@ +package replicationvcenters + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationvCentersClient struct { + Client autorest.Client + baseUri string +} + +func NewReplicationvCentersClientWithBaseURI(endpoint string) ReplicationvCentersClient { + return ReplicationvCentersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/constants.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/constants.go new file mode 100644 index 00000000000..0016bf1fa34 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/constants.go @@ -0,0 +1,34 @@ +package replicationvcenters + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthErrorCustomerResolvability string + +const ( + HealthErrorCustomerResolvabilityAllowed HealthErrorCustomerResolvability = "Allowed" + HealthErrorCustomerResolvabilityNotAllowed HealthErrorCustomerResolvability = "NotAllowed" +) + +func PossibleValuesForHealthErrorCustomerResolvability() []string { + return []string{ + string(HealthErrorCustomerResolvabilityAllowed), + string(HealthErrorCustomerResolvabilityNotAllowed), + } +} + +func parseHealthErrorCustomerResolvability(input string) (*HealthErrorCustomerResolvability, error) { + vals := map[string]HealthErrorCustomerResolvability{ + "allowed": HealthErrorCustomerResolvabilityAllowed, + "notallowed": HealthErrorCustomerResolvabilityNotAllowed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthErrorCustomerResolvability(input) + return &out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationfabric.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationfabric.go new file mode 100644 index 00000000000..86e83ff1b09 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationfabric.go @@ -0,0 +1,140 @@ +package replicationvcenters + +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 = ReplicationFabricId{} + +// ReplicationFabricId is a struct representing the Resource ID for a Replication Fabric +type ReplicationFabricId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string +} + +// NewReplicationFabricID returns a new ReplicationFabricId struct +func NewReplicationFabricID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string) ReplicationFabricId { + return ReplicationFabricId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + } +} + +// ParseReplicationFabricID parses 'input' into a ReplicationFabricId +func ParseReplicationFabricID(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationFabricIDInsensitively parses 'input' case-insensitively into a ReplicationFabricId +// note: this method should only be used for API response data and not user input +func ParseReplicationFabricIDInsensitively(input string) (*ReplicationFabricId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationFabricId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationFabricId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationFabricID checks that 'input' can be parsed as a Replication Fabric ID +func ValidateReplicationFabricID(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 := ParseReplicationFabricID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Fabric ID +func (id ReplicationFabricId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Fabric ID +func (id ReplicationFabricId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + } +} + +// String returns a human-readable description of this Replication Fabric ID +func (id ReplicationFabricId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + } + return fmt.Sprintf("Replication Fabric (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationfabric_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationfabric_test.go new file mode 100644 index 00000000000..3628c7df5e0 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationfabric_test.go @@ -0,0 +1,327 @@ +package replicationvcenters + +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 = ReplicationFabricId{} + +func TestNewReplicationFabricID(t *testing.T) { + id := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } +} + +func TestFormatReplicationFabricID(t *testing.T) { + actual := NewReplicationFabricID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationFabricID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestParseReplicationFabricIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationFabricId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Expected: &ReplicationFabricId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationFabricIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + } +} + +func TestSegmentsForReplicationFabricId(t *testing.T) { + segments := ReplicationFabricId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationFabricId 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/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationvcenter.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationvcenter.go new file mode 100644 index 00000000000..b547fc71d79 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationvcenter.go @@ -0,0 +1,153 @@ +package replicationvcenters + +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 = ReplicationvCenterId{} + +// ReplicationvCenterId is a struct representing the Resource ID for a Replicationv Center +type ReplicationvCenterId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationvCenterName string +} + +// NewReplicationvCenterID returns a new ReplicationvCenterId struct +func NewReplicationvCenterID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationvCenterName string) ReplicationvCenterId { + return ReplicationvCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationvCenterName: replicationvCenterName, + } +} + +// ParseReplicationvCenterID parses 'input' into a ReplicationvCenterId +func ParseReplicationvCenterID(input string) (*ReplicationvCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationvCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationvCenterId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationvCenterName, ok = parsed.Parsed["replicationvCenterName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationvCenterName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationvCenterIDInsensitively parses 'input' case-insensitively into a ReplicationvCenterId +// note: this method should only be used for API response data and not user input +func ParseReplicationvCenterIDInsensitively(input string) (*ReplicationvCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationvCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationvCenterId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationvCenterName, ok = parsed.Parsed["replicationvCenterName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationvCenterName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationvCenterID checks that 'input' can be parsed as a Replicationv Center ID +func ValidateReplicationvCenterID(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 := ParseReplicationvCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replicationv Center ID +func (id ReplicationvCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationvCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationvCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replicationv Center ID +func (id ReplicationvCenterId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationvCenters", "replicationvCenters", "replicationvCenters"), + resourceids.UserSpecifiedSegment("replicationvCenterName", "replicationvCenterValue"), + } +} + +// String returns a human-readable description of this Replicationv Center ID +func (id ReplicationvCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replicationv Center Name: %q", id.ReplicationvCenterName), + } + return fmt.Sprintf("Replicationv Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationvcenter_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationvcenter_test.go new file mode 100644 index 00000000000..27ee709f017 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_replicationvcenter_test.go @@ -0,0 +1,372 @@ +package replicationvcenters + +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 = ReplicationvCenterId{} + +func TestNewReplicationvCenterID(t *testing.T) { + id := NewReplicationvCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationvCenterValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationvCenterName != "replicationvCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationvCenterName'", id.ReplicationvCenterName, "replicationvCenterValue") + } +} + +func TestFormatReplicationvCenterID(t *testing.T) { + actual := NewReplicationvCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationvCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationvCenters/replicationvCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationvCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationvCenterId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationvCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationvCenters/replicationvCenterValue", + Expected: &ReplicationvCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationvCenterName: "replicationvCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationvCenters/replicationvCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationvCenterID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationvCenterName != v.Expected.ReplicationvCenterName { + t.Fatalf("Expected %q but got %q for ReplicationvCenterName", v.Expected.ReplicationvCenterName, actual.ReplicationvCenterName) + } + + } +} + +func TestParseReplicationvCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationvCenterId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationvCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnVcEnTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationvCenters/replicationvCenterValue", + Expected: &ReplicationvCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationvCenterName: "replicationvCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationvCenters/replicationvCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnVcEnTeRs/rEpLiCaTiOnVcEnTeRvAlUe", + Expected: &ReplicationvCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationvCenterName: "rEpLiCaTiOnVcEnTeRvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnVcEnTeRs/rEpLiCaTiOnVcEnTeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationvCenterIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationvCenterName != v.Expected.ReplicationvCenterName { + t.Fatalf("Expected %q but got %q for ReplicationvCenterName", v.Expected.ReplicationvCenterName, actual.ReplicationvCenterName) + } + + } +} + +func TestSegmentsForReplicationvCenterId(t *testing.T) { + segments := ReplicationvCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationvCenterId 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/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_vault.go new file mode 100644 index 00000000000..45267e2f762 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_vault.go @@ -0,0 +1,127 @@ +package replicationvcenters + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_vault_test.go new file mode 100644 index 00000000000..2640250ea11 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/id_vault_test.go @@ -0,0 +1,282 @@ +package replicationvcenters + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_create_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_create_autorest.go new file mode 100644 index 00000000000..91ebbe9ceed --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_create_autorest.go @@ -0,0 +1,79 @@ +package replicationvcenters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Create ... +func (c ReplicationvCentersClient) Create(ctx context.Context, id ReplicationvCenterId, input AddVCenterRequest) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Create", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationvCentersClient) CreateThenPoll(ctx context.Context, id ReplicationvCenterId, input AddVCenterRequest) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} + +// preparerForCreate prepares the Create request. +func (c ReplicationvCentersClient) preparerForCreate(ctx context.Context, id ReplicationvCenterId, input AddVCenterRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreate sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationvCentersClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_delete_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_delete_autorest.go new file mode 100644 index 00000000000..3beba254c01 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_delete_autorest.go @@ -0,0 +1,78 @@ +package replicationvcenters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c ReplicationvCentersClient) Delete(ctx context.Context, id ReplicationvCenterId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationvCentersClient) DeleteThenPoll(ctx context.Context, id ReplicationvCenterId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c ReplicationvCentersClient) preparerForDelete(ctx context.Context, id ReplicationvCenterId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationvCentersClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_get_autorest.go new file mode 100644 index 00000000000..688553f5c7b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_get_autorest.go @@ -0,0 +1,68 @@ +package replicationvcenters + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *VCenter +} + +// Get ... +func (c ReplicationvCentersClient) Get(ctx context.Context, id ReplicationvCenterId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ReplicationvCentersClient) preparerForGet(ctx context.Context, id ReplicationvCenterId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ReplicationvCentersClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_list_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_list_autorest.go new file mode 100644 index 00000000000..9f02eba4f14 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_list_autorest.go @@ -0,0 +1,186 @@ +package replicationvcenters + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]VCenter + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []VCenter +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c ReplicationvCentersClient) List(ctx context.Context, id VaultId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c ReplicationvCentersClient) preparerForList(ctx context.Context, id VaultId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationvCenters", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c ReplicationvCentersClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c ReplicationvCentersClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []VCenter `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c ReplicationvCentersClient) ListComplete(ctx context.Context, id VaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, VCenterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationvCentersClient) ListCompleteMatchingPredicate(ctx context.Context, id VaultId, predicate VCenterOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]VCenter, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_listbyreplicationfabrics_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_listbyreplicationfabrics_autorest.go new file mode 100644 index 00000000000..72e79452b4a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_listbyreplicationfabrics_autorest.go @@ -0,0 +1,186 @@ +package replicationvcenters + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationFabricsOperationResponse struct { + HttpResponse *http.Response + Model *[]VCenter + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationFabricsOperationResponse, error) +} + +type ListByReplicationFabricsCompleteResult struct { + Items []VCenter +} + +func (r ListByReplicationFabricsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationFabricsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationFabricsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationFabrics ... +func (c ReplicationvCentersClient) ListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (resp ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabrics(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationFabrics(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "ListByReplicationFabrics", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationFabrics prepares the ListByReplicationFabrics request. +func (c ReplicationvCentersClient) preparerForListByReplicationFabrics(ctx context.Context, id ReplicationFabricId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/replicationvCenters", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationFabricsWithNextLink prepares the ListByReplicationFabrics request with the given nextLink token. +func (c ReplicationvCentersClient) preparerForListByReplicationFabricsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationFabrics handles the response to the ListByReplicationFabrics request. The method always +// closes the http.Response Body. +func (c ReplicationvCentersClient) responderForListByReplicationFabrics(resp *http.Response) (result ListByReplicationFabricsOperationResponse, err error) { + type page struct { + Values []VCenter `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationFabricsOperationResponse, err error) { + req, err := c.preparerForListByReplicationFabricsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "ListByReplicationFabrics", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "ListByReplicationFabrics", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationFabrics(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "ListByReplicationFabrics", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationFabricsComplete retrieves all of the results into a single object +func (c ReplicationvCentersClient) ListByReplicationFabricsComplete(ctx context.Context, id ReplicationFabricId) (ListByReplicationFabricsCompleteResult, error) { + return c.ListByReplicationFabricsCompleteMatchingPredicate(ctx, id, VCenterOperationPredicate{}) +} + +// ListByReplicationFabricsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ReplicationvCentersClient) ListByReplicationFabricsCompleteMatchingPredicate(ctx context.Context, id ReplicationFabricId, predicate VCenterOperationPredicate) (resp ListByReplicationFabricsCompleteResult, err error) { + items := make([]VCenter, 0) + + page, err := c.ListByReplicationFabrics(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationFabricsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_update_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_update_autorest.go new file mode 100644 index 00000000000..b068a03c209 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/method_update_autorest.go @@ -0,0 +1,79 @@ +package replicationvcenters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c ReplicationvCentersClient) Update(ctx context.Context, id ReplicationvCenterId, input UpdateVCenterRequest) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "replicationvcenters.ReplicationvCentersClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationvCentersClient) UpdateThenPoll(ctx context.Context, id ReplicationvCenterId, input UpdateVCenterRequest) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c ReplicationvCentersClient) preparerForUpdate(ctx context.Context, id ReplicationvCenterId, input UpdateVCenterRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c ReplicationvCentersClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_addvcenterrequest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_addvcenterrequest.go new file mode 100644 index 00000000000..8bc14e86c5c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_addvcenterrequest.go @@ -0,0 +1,8 @@ +package replicationvcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddVCenterRequest struct { + Properties *AddVCenterRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_addvcenterrequestproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_addvcenterrequestproperties.go new file mode 100644 index 00000000000..3904def79d8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_addvcenterrequestproperties.go @@ -0,0 +1,12 @@ +package replicationvcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddVCenterRequestProperties struct { + FriendlyName *string `json:"friendlyName,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + Port *string `json:"port,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_healtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_healtherror.go new file mode 100644 index 00000000000..915bd6578cf --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_healtherror.go @@ -0,0 +1,40 @@ +package replicationvcenters + +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 HealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + InnerHealthErrors *[]InnerHealthError `json:"innerHealthErrors,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *HealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_innerhealtherror.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_innerhealtherror.go new file mode 100644 index 00000000000..5ed6fc2fe05 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_innerhealtherror.go @@ -0,0 +1,39 @@ +package replicationvcenters + +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 InnerHealthError struct { + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + CustomerResolvability *HealthErrorCustomerResolvability `json:"customerResolvability,omitempty"` + EntityId *string `json:"entityId,omitempty"` + ErrorCategory *string `json:"errorCategory,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + ErrorLevel *string `json:"errorLevel,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSource *string `json:"errorSource,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + PossibleCauses *string `json:"possibleCauses,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + RecoveryProviderErrorMessage *string `json:"recoveryProviderErrorMessage,omitempty"` + SummaryMessage *string `json:"summaryMessage,omitempty"` +} + +func (o *InnerHealthError) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *InnerHealthError) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_updatevcenterrequest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_updatevcenterrequest.go new file mode 100644 index 00000000000..c9ab295622d --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_updatevcenterrequest.go @@ -0,0 +1,8 @@ +package replicationvcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateVCenterRequest struct { + Properties *UpdateVCenterRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_updatevcenterrequestproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_updatevcenterrequestproperties.go new file mode 100644 index 00000000000..9c02f563369 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_updatevcenterrequestproperties.go @@ -0,0 +1,12 @@ +package replicationvcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateVCenterRequestProperties struct { + FriendlyName *string `json:"friendlyName,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + Port *string `json:"port,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_vcenter.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_vcenter.go new file mode 100644 index 00000000000..5f8c2b26c1e --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_vcenter.go @@ -0,0 +1,12 @@ +package replicationvcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VCenter struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VCenterProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_vcenterproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_vcenterproperties.go new file mode 100644 index 00000000000..9f4d3394f62 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/model_vcenterproperties.go @@ -0,0 +1,36 @@ +package replicationvcenters + +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 VCenterProperties struct { + DiscoveryStatus *string `json:"discoveryStatus,omitempty"` + FabricArmResourceName *string `json:"fabricArmResourceName,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HealthErrors *[]HealthError `json:"healthErrors,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + InfrastructureId *string `json:"infrastructureId,omitempty"` + InternalId *string `json:"internalId,omitempty"` + LastHeartbeat *string `json:"lastHeartbeat,omitempty"` + Port *string `json:"port,omitempty"` + ProcessServerId *string `json:"processServerId,omitempty"` + RunAsAccountId *string `json:"runAsAccountId,omitempty"` +} + +func (o *VCenterProperties) GetLastHeartbeatAsTime() (*time.Time, error) { + if o.LastHeartbeat == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHeartbeat, "2006-01-02T15:04:05Z07:00") +} + +func (o *VCenterProperties) SetLastHeartbeatAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHeartbeat = &formatted +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/predicates.go new file mode 100644 index 00000000000..5c1563c6d10 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/predicates.go @@ -0,0 +1,32 @@ +package replicationvcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VCenterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p VCenterOperationPredicate) Matches(input VCenter) bool { + + 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/recoveryservicessiterecovery/2023-01-01/replicationvcenters/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/version.go new file mode 100644 index 00000000000..356d40f702c --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/replicationvcenters/version.go @@ -0,0 +1,12 @@ +package replicationvcenters + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationvcenters/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/README.md new file mode 100644 index 00000000000..a7b8ef6c812 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems` Documentation + +The `supportedoperatingsystems` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems" +``` + + +### Client Initialization + +```go +client := supportedoperatingsystems.NewSupportedOperatingSystemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SupportedOperatingSystemsClient.Get` + +```go +ctx := context.TODO() +id := supportedoperatingsystems.NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + +read, err := client.Get(ctx, id, supportedoperatingsystems.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/client.go new file mode 100644 index 00000000000..82f77624637 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/client.go @@ -0,0 +1,18 @@ +package supportedoperatingsystems + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedOperatingSystemsClient struct { + Client autorest.Client + baseUri string +} + +func NewSupportedOperatingSystemsClientWithBaseURI(endpoint string) SupportedOperatingSystemsClient { + return SupportedOperatingSystemsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/id_vault.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/id_vault.go new file mode 100644 index 00000000000..b8947186027 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/id_vault.go @@ -0,0 +1,127 @@ +package supportedoperatingsystems + +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 = VaultId{} + +// VaultId is a struct representing the Resource ID for a Vault +type VaultId struct { + SubscriptionId string + ResourceGroupName string + VaultName string +} + +// NewVaultID returns a new VaultId struct +func NewVaultID(subscriptionId string, resourceGroupName string, vaultName string) VaultId { + return VaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + } +} + +// ParseVaultID parses 'input' into a VaultId +func ParseVaultID(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVaultIDInsensitively parses 'input' case-insensitively into a VaultId +// note: this method should only be used for API response data and not user input +func ParseVaultIDInsensitively(input string) (*VaultId, error) { + parser := resourceids.NewParserFromResourceIdType(VaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VaultId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVaultID checks that 'input' can be parsed as a Vault ID +func ValidateVaultID(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 := ParseVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vault ID +func (id VaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vault ID +func (id VaultId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + } +} + +// String returns a human-readable description of this Vault ID +func (id VaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + } + return fmt.Sprintf("Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/id_vault_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/id_vault_test.go new file mode 100644 index 00000000000..df2b8f97ace --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/id_vault_test.go @@ -0,0 +1,282 @@ +package supportedoperatingsystems + +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 = VaultId{} + +func TestNewVaultID(t *testing.T) { + id := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } +} + +func TestFormatVaultID(t *testing.T) { + actual := NewVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestParseVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VaultId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Expected: &VaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVaultIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + } +} + +func TestSegmentsForVaultId(t *testing.T) { + segments := VaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VaultId 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/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/method_get_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/method_get_autorest.go new file mode 100644 index 00000000000..0fef60a6766 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/method_get_autorest.go @@ -0,0 +1,98 @@ +package supportedoperatingsystems + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *SupportedOperatingSystems +} + +type GetOperationOptions struct { + InstanceType *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o GetOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.InstanceType != nil { + out["instanceType"] = *o.InstanceType + } + + return out +} + +// Get ... +func (c SupportedOperatingSystemsClient) Get(ctx context.Context, id VaultId, options GetOperationOptions) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "supportedoperatingsystems.SupportedOperatingSystemsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "supportedoperatingsystems.SupportedOperatingSystemsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "supportedoperatingsystems.SupportedOperatingSystemsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c SupportedOperatingSystemsClient) preparerForGet(ctx context.Context, id VaultId, options GetOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/replicationSupportedOperatingSystems", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c SupportedOperatingSystemsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_osversionwrapper.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_osversionwrapper.go new file mode 100644 index 00000000000..af334b23ea8 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_osversionwrapper.go @@ -0,0 +1,9 @@ +package supportedoperatingsystems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSVersionWrapper struct { + ServicePack *string `json:"servicePack,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedoperatingsystems.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedoperatingsystems.go new file mode 100644 index 00000000000..2d7bee64192 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedoperatingsystems.go @@ -0,0 +1,12 @@ +package supportedoperatingsystems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedOperatingSystems struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SupportedOSProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosdetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosdetails.go new file mode 100644 index 00000000000..b89ec6cfe3a --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosdetails.go @@ -0,0 +1,10 @@ +package supportedoperatingsystems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedOSDetails struct { + OsName *string `json:"osName,omitempty"` + OsType *string `json:"osType,omitempty"` + OsVersions *[]OSVersionWrapper `json:"osVersions,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosproperties.go new file mode 100644 index 00000000000..ee9acfc9a81 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosproperties.go @@ -0,0 +1,8 @@ +package supportedoperatingsystems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedOSProperties struct { + SupportedOsList *[]SupportedOSProperty `json:"supportedOsList,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosproperty.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosproperty.go new file mode 100644 index 00000000000..e9f60b43c0b --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/model_supportedosproperty.go @@ -0,0 +1,9 @@ +package supportedoperatingsystems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedOSProperty struct { + InstanceType *string `json:"instanceType,omitempty"` + SupportedOs *[]SupportedOSDetails `json:"supportedOs,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/version.go new file mode 100644 index 00000000000..d0b171916fd --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/supportedoperatingsystems/version.go @@ -0,0 +1,12 @@ +package supportedoperatingsystems + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/supportedoperatingsystems/%s", defaultApiVersion) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/README.md b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/README.md new file mode 100644 index 00000000000..80a59a39975 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes` Documentation + +The `targetcomputesizes` SDK allows for interaction with the Azure Resource Manager Service `recoveryservicessiterecovery` (API Version `2023-01-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/recoveryservicessiterecovery/2023-01-01/targetcomputesizes" +``` + + +### Client Initialization + +```go +client := targetcomputesizes.NewTargetComputeSizesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TargetComputeSizesClient.ListByReplicationProtectedItems` + +```go +ctx := context.TODO() +id := targetcomputesizes.NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + +// alternatively `client.ListByReplicationProtectedItems(ctx, id)` can be used to do batched pagination +items, err := client.ListByReplicationProtectedItemsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/client.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/client.go new file mode 100644 index 00000000000..d44a5bf9bfc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/client.go @@ -0,0 +1,18 @@ +package targetcomputesizes + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetComputeSizesClient struct { + Client autorest.Client + baseUri string +} + +func NewTargetComputeSizesClientWithBaseURI(endpoint string) TargetComputeSizesClient { + return TargetComputeSizesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/id_replicationprotecteditem.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/id_replicationprotecteditem.go new file mode 100644 index 00000000000..686c2e85748 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/id_replicationprotecteditem.go @@ -0,0 +1,166 @@ +package targetcomputesizes + +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 = ReplicationProtectedItemId{} + +// ReplicationProtectedItemId is a struct representing the Resource ID for a Replication Protected Item +type ReplicationProtectedItemId struct { + SubscriptionId string + ResourceGroupName string + VaultName string + ReplicationFabricName string + ReplicationProtectionContainerName string + ReplicationProtectedItemName string +} + +// NewReplicationProtectedItemID returns a new ReplicationProtectedItemId struct +func NewReplicationProtectedItemID(subscriptionId string, resourceGroupName string, vaultName string, replicationFabricName string, replicationProtectionContainerName string, replicationProtectedItemName string) ReplicationProtectedItemId { + return ReplicationProtectedItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VaultName: vaultName, + ReplicationFabricName: replicationFabricName, + ReplicationProtectionContainerName: replicationProtectionContainerName, + ReplicationProtectedItemName: replicationProtectedItemName, + } +} + +// ParseReplicationProtectedItemID parses 'input' into a ReplicationProtectedItemId +func ParseReplicationProtectedItemID(input string) (*ReplicationProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectedItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseReplicationProtectedItemIDInsensitively parses 'input' case-insensitively into a ReplicationProtectedItemId +// note: this method should only be used for API response data and not user input +func ParseReplicationProtectedItemIDInsensitively(input string) (*ReplicationProtectedItemId, error) { + parser := resourceids.NewParserFromResourceIdType(ReplicationProtectedItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ReplicationProtectedItemId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { + return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + } + + if id.ReplicationFabricName, ok = parsed.Parsed["replicationFabricName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationFabricName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectionContainerName, ok = parsed.Parsed["replicationProtectionContainerName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectionContainerName' was not found in the resource id %q", input) + } + + if id.ReplicationProtectedItemName, ok = parsed.Parsed["replicationProtectedItemName"]; !ok { + return nil, fmt.Errorf("the segment 'replicationProtectedItemName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateReplicationProtectedItemID checks that 'input' can be parsed as a Replication Protected Item ID +func ValidateReplicationProtectedItemID(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 := ParseReplicationProtectedItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Protected Item ID +func (id ReplicationProtectedItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.RecoveryServices/vaults/%s/replicationFabrics/%s/replicationProtectionContainers/%s/replicationProtectedItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VaultName, id.ReplicationFabricName, id.ReplicationProtectionContainerName, id.ReplicationProtectedItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Protected Item ID +func (id ReplicationProtectedItemId) 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("staticMicrosoftRecoveryServices", "Microsoft.RecoveryServices", "Microsoft.RecoveryServices"), + resourceids.StaticSegment("staticVaults", "vaults", "vaults"), + resourceids.UserSpecifiedSegment("vaultName", "vaultValue"), + resourceids.StaticSegment("staticReplicationFabrics", "replicationFabrics", "replicationFabrics"), + resourceids.UserSpecifiedSegment("replicationFabricName", "replicationFabricValue"), + resourceids.StaticSegment("staticReplicationProtectionContainers", "replicationProtectionContainers", "replicationProtectionContainers"), + resourceids.UserSpecifiedSegment("replicationProtectionContainerName", "replicationProtectionContainerValue"), + resourceids.StaticSegment("staticReplicationProtectedItems", "replicationProtectedItems", "replicationProtectedItems"), + resourceids.UserSpecifiedSegment("replicationProtectedItemName", "replicationProtectedItemValue"), + } +} + +// String returns a human-readable description of this Replication Protected Item ID +func (id ReplicationProtectedItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Vault Name: %q", id.VaultName), + fmt.Sprintf("Replication Fabric Name: %q", id.ReplicationFabricName), + fmt.Sprintf("Replication Protection Container Name: %q", id.ReplicationProtectionContainerName), + fmt.Sprintf("Replication Protected Item Name: %q", id.ReplicationProtectedItemName), + } + return fmt.Sprintf("Replication Protected Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/id_replicationprotecteditem_test.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/id_replicationprotecteditem_test.go new file mode 100644 index 00000000000..7269b50237f --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/id_replicationprotecteditem_test.go @@ -0,0 +1,417 @@ +package targetcomputesizes + +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 = ReplicationProtectedItemId{} + +func TestNewReplicationProtectedItemID(t *testing.T) { + id := NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue") + + 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.VaultName != "vaultValue" { + t.Fatalf("Expected %q but got %q for Segment 'VaultName'", id.VaultName, "vaultValue") + } + + if id.ReplicationFabricName != "replicationFabricValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationFabricName'", id.ReplicationFabricName, "replicationFabricValue") + } + + if id.ReplicationProtectionContainerName != "replicationProtectionContainerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectionContainerName'", id.ReplicationProtectionContainerName, "replicationProtectionContainerValue") + } + + if id.ReplicationProtectedItemName != "replicationProtectedItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationProtectedItemName'", id.ReplicationProtectedItemName, "replicationProtectedItemValue") + } +} + +func TestFormatReplicationProtectedItemID(t *testing.T) { + actual := NewReplicationProtectedItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "vaultValue", "replicationFabricValue", "replicationProtectionContainerValue", "replicationProtectedItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationProtectedItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectedItemID(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + } +} + +func TestParseReplicationProtectedItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationProtectedItemId + }{ + { + // 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.RecoveryServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VaultName: "vaultValue", + ReplicationFabricName: "replicationFabricValue", + ReplicationProtectionContainerName: "replicationProtectionContainerValue", + ReplicationProtectedItemName: "replicationProtectedItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.RecoveryServices/vaults/vaultValue/replicationFabrics/replicationFabricValue/replicationProtectionContainers/replicationProtectionContainerValue/replicationProtectedItems/replicationProtectedItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + Expected: &ReplicationProtectedItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VaultName: "vAuLtVaLuE", + ReplicationFabricName: "rEpLiCaTiOnFaBrIcVaLuE", + ReplicationProtectionContainerName: "rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe", + ReplicationProtectedItemName: "rEpLiCaTiOnPrOtEcTeDiTeMvAlUe", + }, + }, + { + // 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.rEcOvErYsErViCeS/vAuLtS/vAuLtVaLuE/rEpLiCaTiOnFaBrIcS/rEpLiCaTiOnFaBrIcVaLuE/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRs/rEpLiCaTiOnPrOtEcTiOnCoNtAiNeRvAlUe/rEpLiCaTiOnPrOtEcTeDiTeMs/rEpLiCaTiOnPrOtEcTeDiTeMvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationProtectedItemIDInsensitively(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.VaultName != v.Expected.VaultName { + t.Fatalf("Expected %q but got %q for VaultName", v.Expected.VaultName, actual.VaultName) + } + + if actual.ReplicationFabricName != v.Expected.ReplicationFabricName { + t.Fatalf("Expected %q but got %q for ReplicationFabricName", v.Expected.ReplicationFabricName, actual.ReplicationFabricName) + } + + if actual.ReplicationProtectionContainerName != v.Expected.ReplicationProtectionContainerName { + t.Fatalf("Expected %q but got %q for ReplicationProtectionContainerName", v.Expected.ReplicationProtectionContainerName, actual.ReplicationProtectionContainerName) + } + + if actual.ReplicationProtectedItemName != v.Expected.ReplicationProtectedItemName { + t.Fatalf("Expected %q but got %q for ReplicationProtectedItemName", v.Expected.ReplicationProtectedItemName, actual.ReplicationProtectedItemName) + } + + } +} + +func TestSegmentsForReplicationProtectedItemId(t *testing.T) { + segments := ReplicationProtectedItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationProtectedItemId 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/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/method_listbyreplicationprotecteditems_autorest.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/method_listbyreplicationprotecteditems_autorest.go new file mode 100644 index 00000000000..6c619bd76ce --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/method_listbyreplicationprotecteditems_autorest.go @@ -0,0 +1,186 @@ +package targetcomputesizes + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByReplicationProtectedItemsOperationResponse struct { + HttpResponse *http.Response + Model *[]TargetComputeSize + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByReplicationProtectedItemsOperationResponse, error) +} + +type ListByReplicationProtectedItemsCompleteResult struct { + Items []TargetComputeSize +} + +func (r ListByReplicationProtectedItemsOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByReplicationProtectedItemsOperationResponse) LoadMore(ctx context.Context) (resp ListByReplicationProtectedItemsOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByReplicationProtectedItems ... +func (c TargetComputeSizesClient) ListByReplicationProtectedItems(ctx context.Context, id ReplicationProtectedItemId) (resp ListByReplicationProtectedItemsOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectedItems(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "targetcomputesizes.TargetComputeSizesClient", "ListByReplicationProtectedItems", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "targetcomputesizes.TargetComputeSizesClient", "ListByReplicationProtectedItems", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByReplicationProtectedItems(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "targetcomputesizes.TargetComputeSizesClient", "ListByReplicationProtectedItems", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByReplicationProtectedItems prepares the ListByReplicationProtectedItems request. +func (c TargetComputeSizesClient) preparerForListByReplicationProtectedItems(ctx context.Context, id ReplicationProtectedItemId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/targetComputeSizes", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByReplicationProtectedItemsWithNextLink prepares the ListByReplicationProtectedItems request with the given nextLink token. +func (c TargetComputeSizesClient) preparerForListByReplicationProtectedItemsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByReplicationProtectedItems handles the response to the ListByReplicationProtectedItems request. The method always +// closes the http.Response Body. +func (c TargetComputeSizesClient) responderForListByReplicationProtectedItems(resp *http.Response) (result ListByReplicationProtectedItemsOperationResponse, err error) { + type page struct { + Values []TargetComputeSize `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByReplicationProtectedItemsOperationResponse, err error) { + req, err := c.preparerForListByReplicationProtectedItemsWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "targetcomputesizes.TargetComputeSizesClient", "ListByReplicationProtectedItems", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "targetcomputesizes.TargetComputeSizesClient", "ListByReplicationProtectedItems", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByReplicationProtectedItems(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "targetcomputesizes.TargetComputeSizesClient", "ListByReplicationProtectedItems", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByReplicationProtectedItemsComplete retrieves all of the results into a single object +func (c TargetComputeSizesClient) ListByReplicationProtectedItemsComplete(ctx context.Context, id ReplicationProtectedItemId) (ListByReplicationProtectedItemsCompleteResult, error) { + return c.ListByReplicationProtectedItemsCompleteMatchingPredicate(ctx, id, TargetComputeSizeOperationPredicate{}) +} + +// ListByReplicationProtectedItemsCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c TargetComputeSizesClient) ListByReplicationProtectedItemsCompleteMatchingPredicate(ctx context.Context, id ReplicationProtectedItemId, predicate TargetComputeSizeOperationPredicate) (resp ListByReplicationProtectedItemsCompleteResult, err error) { + items := make([]TargetComputeSize, 0) + + page, err := c.ListByReplicationProtectedItems(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByReplicationProtectedItemsCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_computesizeerrordetails.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_computesizeerrordetails.go new file mode 100644 index 00000000000..f16abf36733 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_computesizeerrordetails.go @@ -0,0 +1,9 @@ +package targetcomputesizes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ComputeSizeErrorDetails struct { + Message *string `json:"message,omitempty"` + Severity *string `json:"severity,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_targetcomputesize.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_targetcomputesize.go new file mode 100644 index 00000000000..532ef19b568 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_targetcomputesize.go @@ -0,0 +1,11 @@ +package targetcomputesizes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetComputeSize struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TargetComputeSizeProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_targetcomputesizeproperties.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_targetcomputesizeproperties.go new file mode 100644 index 00000000000..474a614fb31 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/model_targetcomputesizeproperties.go @@ -0,0 +1,17 @@ +package targetcomputesizes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetComputeSizeProperties struct { + CpuCoresCount *int64 `json:"cpuCoresCount,omitempty"` + Errors *[]ComputeSizeErrorDetails `json:"errors,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HighIopsSupported *string `json:"highIopsSupported,omitempty"` + HyperVGenerations *[]string `json:"hyperVGenerations,omitempty"` + MaxDataDiskCount *int64 `json:"maxDataDiskCount,omitempty"` + MaxNicsCount *int64 `json:"maxNicsCount,omitempty"` + MemoryInGB *float64 `json:"memoryInGB,omitempty"` + Name *string `json:"name,omitempty"` + VCPUsAvailable *int64 `json:"vCPUsAvailable,omitempty"` +} diff --git a/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/predicates.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/predicates.go new file mode 100644 index 00000000000..2ce6ae5b3fc --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/predicates.go @@ -0,0 +1,27 @@ +package targetcomputesizes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetComputeSizeOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TargetComputeSizeOperationPredicate) Matches(input TargetComputeSize) 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/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/version.go b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/version.go new file mode 100644 index 00000000000..e8a09fb6e89 --- /dev/null +++ b/resource-manager/recoveryservicessiterecovery/2023-01-01/targetcomputesizes/version.go @@ -0,0 +1,12 @@ +package targetcomputesizes + +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-01-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/targetcomputesizes/%s", defaultApiVersion) +} diff --git a/resource-manager/redis/2021-06-01/client.go b/resource-manager/redis/2021-06-01/client.go deleted file mode 100644 index e1e60e12782..00000000000 --- a/resource-manager/redis/2021-06-01/client.go +++ /dev/null @@ -1,47 +0,0 @@ -package v2021_06_01 - -import ( - "github.com/Azure/go-autorest/autorest" - "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/firewallrules" - "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/patchschedules" - "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/privateendpointconnections" - "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/privatelinkresources" - "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/redis" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type Client struct { - FirewallRules *firewallrules.FirewallRulesClient - PatchSchedules *patchschedules.PatchSchedulesClient - PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient - PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient - Redis *redis.RedisClient -} - -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - firewallRulesClient := firewallrules.NewFirewallRulesClientWithBaseURI(endpoint) - configureAuthFunc(&firewallRulesClient.Client) - - patchSchedulesClient := patchschedules.NewPatchSchedulesClientWithBaseURI(endpoint) - configureAuthFunc(&patchSchedulesClient.Client) - - privateEndpointConnectionsClient := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(endpoint) - configureAuthFunc(&privateEndpointConnectionsClient.Client) - - privateLinkResourcesClient := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(endpoint) - configureAuthFunc(&privateLinkResourcesClient.Client) - - redisClient := redis.NewRedisClientWithBaseURI(endpoint) - configureAuthFunc(&redisClient.Client) - - return Client{ - FirewallRules: &firewallRulesClient, - PatchSchedules: &patchSchedulesClient, - PrivateEndpointConnections: &privateEndpointConnectionsClient, - PrivateLinkResources: &privateLinkResourcesClient, - Redis: &redisClient, - } -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/README.md b/resource-manager/redis/2021-06-01/firewallrules/README.md deleted file mode 100644 index 37a67eda686..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/README.md +++ /dev/null @@ -1,90 +0,0 @@ - -## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/firewallrules` Documentation - -The `firewallrules` SDK allows for interaction with the Azure Resource Manager Service `redis` (API Version `2021-06-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/redis/2021-06-01/firewallrules" -``` - - -### Client Initialization - -```go -client := firewallrules.NewFirewallRulesClientWithBaseURI("https://management.azure.com") -client.Client.Authorizer = authorizer -``` - - -### Example Usage: `FirewallRulesClient.CreateOrUpdate` - -```go -ctx := context.TODO() -id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - -payload := firewallrules.RedisFirewallRule{ - // ... -} - - -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: `FirewallRulesClient.Delete` - -```go -ctx := context.TODO() -id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - -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: `FirewallRulesClient.Get` - -```go -ctx := context.TODO() -id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - -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: `FirewallRulesClient.List` - -```go -ctx := context.TODO() -id := firewallrules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -// 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/redis/2021-06-01/firewallrules/id_firewallrule.go b/resource-manager/redis/2021-06-01/firewallrules/id_firewallrule.go deleted file mode 100644 index a33f18efe73..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/id_firewallrule.go +++ /dev/null @@ -1,140 +0,0 @@ -package firewallrules - -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 = FirewallRuleId{} - -// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule -type FirewallRuleId struct { - SubscriptionId string - ResourceGroupName string - RedisName string - FirewallRuleName string -} - -// NewFirewallRuleID returns a new FirewallRuleId struct -func NewFirewallRuleID(subscriptionId string, resourceGroupName string, redisName string, firewallRuleName string) FirewallRuleId { - return FirewallRuleId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - FirewallRuleName: firewallRuleName, - } -} - -// ParseFirewallRuleID parses 'input' into a FirewallRuleId -func ParseFirewallRuleID(input string) (*FirewallRuleId, error) { - parser := resourceids.NewParserFromResourceIdType(FirewallRuleId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := FirewallRuleId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.FirewallRuleName, ok = parsed.Parsed["firewallRuleName"]; !ok { - return nil, fmt.Errorf("the segment 'firewallRuleName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseFirewallRuleIDInsensitively parses 'input' case-insensitively into a FirewallRuleId -// note: this method should only be used for API response data and not user input -func ParseFirewallRuleIDInsensitively(input string) (*FirewallRuleId, error) { - parser := resourceids.NewParserFromResourceIdType(FirewallRuleId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := FirewallRuleId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.FirewallRuleName, ok = parsed.Parsed["firewallRuleName"]; !ok { - return nil, fmt.Errorf("the segment 'firewallRuleName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateFirewallRuleID checks that 'input' can be parsed as a Firewall Rule ID -func ValidateFirewallRuleID(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 := ParseFirewallRuleID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Firewall Rule ID -func (id FirewallRuleId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/firewallRules/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.FirewallRuleName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Firewall Rule ID -func (id FirewallRuleId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), - resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleValue"), - } -} - -// String returns a human-readable description of this Firewall Rule ID -func (id FirewallRuleId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), - } - return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/id_firewallrule_test.go b/resource-manager/redis/2021-06-01/firewallrules/id_firewallrule_test.go deleted file mode 100644 index 60f853aab4b..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/id_firewallrule_test.go +++ /dev/null @@ -1,327 +0,0 @@ -package firewallrules - -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 = FirewallRuleId{} - -func TestNewFirewallRuleID(t *testing.T) { - id := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } - - if id.FirewallRuleName != "firewallRuleValue" { - t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleValue") - } -} - -func TestFormatFirewallRuleID(t *testing.T) { - actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseFirewallRuleID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *FirewallRuleId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue", - Expected: &FirewallRuleId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - FirewallRuleName: "firewallRuleValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseFirewallRuleID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.FirewallRuleName != v.Expected.FirewallRuleName { - t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) - } - - } -} - -func TestParseFirewallRuleIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *FirewallRuleId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/fIrEwAlLrUlEs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue", - Expected: &FirewallRuleId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - FirewallRuleName: "firewallRuleValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe", - Expected: &FirewallRuleId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - FirewallRuleName: "fIrEwAlLrUlEvAlUe", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseFirewallRuleIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.FirewallRuleName != v.Expected.FirewallRuleName { - t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) - } - - } -} - -func TestSegmentsForFirewallRuleId(t *testing.T) { - segments := FirewallRuleId{}.Segments() - if len(segments) == 0 { - t.Fatalf("FirewallRuleId 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/redis/2021-06-01/firewallrules/id_redi.go b/resource-manager/redis/2021-06-01/firewallrules/id_redi.go deleted file mode 100644 index 61dd49ae910..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/id_redi.go +++ /dev/null @@ -1,127 +0,0 @@ -package firewallrules - -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 = RediId{} - -// RediId is a struct representing the Resource ID for a Redi -type RediId struct { - SubscriptionId string - ResourceGroupName string - RedisName string -} - -// NewRediID returns a new RediId struct -func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { - return RediId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - } -} - -// ParseRediID parses 'input' into a RediId -func ParseRediID(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId -// note: this method should only be used for API response data and not user input -func ParseRediIDInsensitively(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateRediID checks that 'input' can be parsed as a Redi ID -func ValidateRediID(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 := ParseRediID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Redi ID -func (id RediId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Redi ID -func (id RediId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - } -} - -// String returns a human-readable description of this Redi ID -func (id RediId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - } - return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/id_redi_test.go b/resource-manager/redis/2021-06-01/firewallrules/id_redi_test.go deleted file mode 100644 index 89dccc7c63c..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/id_redi_test.go +++ /dev/null @@ -1,282 +0,0 @@ -package firewallrules - -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 = RediId{} - -func TestNewRediID(t *testing.T) { - id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } -} - -func TestFormatRediID(t *testing.T) { - actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseRediID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestParseRediIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestSegmentsForRediId(t *testing.T) { - segments := RediId{}.Segments() - if len(segments) == 0 { - t.Fatalf("RediId 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/redis/2021-06-01/firewallrules/method_createorupdate_autorest.go b/resource-manager/redis/2021-06-01/firewallrules/method_createorupdate_autorest.go deleted file mode 100644 index d904df8e948..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/method_createorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package firewallrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *RedisFirewallRule -} - -// CreateOrUpdate ... -func (c FirewallRulesClient) CreateOrUpdate(ctx context.Context, id FirewallRuleId, input RedisFirewallRule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c FirewallRulesClient) preparerForCreateOrUpdate(ctx context.Context, id FirewallRuleId, input RedisFirewallRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c FirewallRulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/method_delete_autorest.go b/resource-manager/redis/2021-06-01/firewallrules/method_delete_autorest.go deleted file mode 100644 index c250306a893..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package firewallrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c FirewallRulesClient) Delete(ctx context.Context, id FirewallRuleId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c FirewallRulesClient) preparerForDelete(ctx context.Context, id FirewallRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c FirewallRulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/method_get_autorest.go b/resource-manager/redis/2021-06-01/firewallrules/method_get_autorest.go deleted file mode 100644 index 6224dad211e..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package firewallrules - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *RedisFirewallRule -} - -// Get ... -func (c FirewallRulesClient) Get(ctx context.Context, id FirewallRuleId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c FirewallRulesClient) preparerForGet(ctx context.Context, id FirewallRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c FirewallRulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/method_list_autorest.go b/resource-manager/redis/2021-06-01/firewallrules/method_list_autorest.go deleted file mode 100644 index ad115f23a3d..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/method_list_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package firewallrules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]RedisFirewallRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []RedisFirewallRule -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c FirewallRulesClient) List(ctx context.Context, id RediId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c FirewallRulesClient) preparerForList(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/firewallRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c FirewallRulesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c FirewallRulesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []RedisFirewallRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "firewallrules.FirewallRulesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c FirewallRulesClient) ListComplete(ctx context.Context, id RediId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, RedisFirewallRuleOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c FirewallRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisFirewallRuleOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]RedisFirewallRule, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/model_redisfirewallrule.go b/resource-manager/redis/2021-06-01/firewallrules/model_redisfirewallrule.go deleted file mode 100644 index 3188f87b41b..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/model_redisfirewallrule.go +++ /dev/null @@ -1,11 +0,0 @@ -package firewallrules - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisFirewallRule struct { - Id *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Properties RedisFirewallRuleProperties `json:"properties"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/model_redisfirewallruleproperties.go b/resource-manager/redis/2021-06-01/firewallrules/model_redisfirewallruleproperties.go deleted file mode 100644 index 66e289c35ff..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/model_redisfirewallruleproperties.go +++ /dev/null @@ -1,9 +0,0 @@ -package firewallrules - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisFirewallRuleProperties struct { - EndIP string `json:"endIP"` - StartIP string `json:"startIP"` -} diff --git a/resource-manager/redis/2021-06-01/firewallrules/predicates.go b/resource-manager/redis/2021-06-01/firewallrules/predicates.go deleted file mode 100644 index 71db32242ab..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/predicates.go +++ /dev/null @@ -1,27 +0,0 @@ -package firewallrules - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisFirewallRuleOperationPredicate struct { - Id *string - Name *string - Type *string -} - -func (p RedisFirewallRuleOperationPredicate) Matches(input RedisFirewallRule) 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/redis/2021-06-01/firewallrules/version.go b/resource-manager/redis/2021-06-01/firewallrules/version.go deleted file mode 100644 index 75a8730ee27..00000000000 --- a/resource-manager/redis/2021-06-01/firewallrules/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package firewallrules - -import "fmt" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -const defaultApiVersion = "2021-06-01" - -func userAgent() string { - return fmt.Sprintf("hashicorp/go-azure-sdk/firewallrules/%s", defaultApiVersion) -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/README.md b/resource-manager/redis/2021-06-01/patchschedules/README.md deleted file mode 100644 index 756597b6314..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/README.md +++ /dev/null @@ -1,90 +0,0 @@ - -## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/patchschedules` Documentation - -The `patchschedules` SDK allows for interaction with the Azure Resource Manager Service `redis` (API Version `2021-06-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/redis/2021-06-01/patchschedules" -``` - - -### Client Initialization - -```go -client := patchschedules.NewPatchSchedulesClientWithBaseURI("https://management.azure.com") -client.Client.Authorizer = authorizer -``` - - -### Example Usage: `PatchSchedulesClient.CreateOrUpdate` - -```go -ctx := context.TODO() -id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := patchschedules.RedisPatchSchedule{ - // ... -} - - -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: `PatchSchedulesClient.Delete` - -```go -ctx := context.TODO() -id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -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: `PatchSchedulesClient.Get` - -```go -ctx := context.TODO() -id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -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: `PatchSchedulesClient.ListByRedisResource` - -```go -ctx := context.TODO() -id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -// alternatively `client.ListByRedisResource(ctx, id)` can be used to do batched pagination -items, err := client.ListByRedisResourceComplete(ctx, id) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` diff --git a/resource-manager/redis/2021-06-01/patchschedules/client.go b/resource-manager/redis/2021-06-01/patchschedules/client.go deleted file mode 100644 index 9950c44d3c0..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/client.go +++ /dev/null @@ -1,18 +0,0 @@ -package patchschedules - -import "github.com/Azure/go-autorest/autorest" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PatchSchedulesClient struct { - Client autorest.Client - baseUri string -} - -func NewPatchSchedulesClientWithBaseURI(endpoint string) PatchSchedulesClient { - return PatchSchedulesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, - } -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/constants.go b/resource-manager/redis/2021-06-01/patchschedules/constants.go deleted file mode 100644 index 1bbfa711c2f..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/constants.go +++ /dev/null @@ -1,55 +0,0 @@ -package patchschedules - -import "strings" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DayOfWeek string - -const ( - DayOfWeekEveryday DayOfWeek = "Everyday" - DayOfWeekFriday DayOfWeek = "Friday" - DayOfWeekMonday DayOfWeek = "Monday" - DayOfWeekSaturday DayOfWeek = "Saturday" - DayOfWeekSunday DayOfWeek = "Sunday" - DayOfWeekThursday DayOfWeek = "Thursday" - DayOfWeekTuesday DayOfWeek = "Tuesday" - DayOfWeekWednesday DayOfWeek = "Wednesday" - DayOfWeekWeekend DayOfWeek = "Weekend" -) - -func PossibleValuesForDayOfWeek() []string { - return []string{ - string(DayOfWeekEveryday), - string(DayOfWeekFriday), - string(DayOfWeekMonday), - string(DayOfWeekSaturday), - string(DayOfWeekSunday), - string(DayOfWeekThursday), - string(DayOfWeekTuesday), - string(DayOfWeekWednesday), - string(DayOfWeekWeekend), - } -} - -func parseDayOfWeek(input string) (*DayOfWeek, error) { - vals := map[string]DayOfWeek{ - "everyday": DayOfWeekEveryday, - "friday": DayOfWeekFriday, - "monday": DayOfWeekMonday, - "saturday": DayOfWeekSaturday, - "sunday": DayOfWeekSunday, - "thursday": DayOfWeekThursday, - "tuesday": DayOfWeekTuesday, - "wednesday": DayOfWeekWednesday, - "weekend": DayOfWeekWeekend, - } - 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 -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/id_redi.go b/resource-manager/redis/2021-06-01/patchschedules/id_redi.go deleted file mode 100644 index edc6e4baa50..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/id_redi.go +++ /dev/null @@ -1,127 +0,0 @@ -package patchschedules - -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 = RediId{} - -// RediId is a struct representing the Resource ID for a Redi -type RediId struct { - SubscriptionId string - ResourceGroupName string - RedisName string -} - -// NewRediID returns a new RediId struct -func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { - return RediId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - } -} - -// ParseRediID parses 'input' into a RediId -func ParseRediID(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId -// note: this method should only be used for API response data and not user input -func ParseRediIDInsensitively(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateRediID checks that 'input' can be parsed as a Redi ID -func ValidateRediID(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 := ParseRediID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Redi ID -func (id RediId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Redi ID -func (id RediId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - } -} - -// String returns a human-readable description of this Redi ID -func (id RediId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - } - return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/id_redi_test.go b/resource-manager/redis/2021-06-01/patchschedules/id_redi_test.go deleted file mode 100644 index 2fa5df7e3d4..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/id_redi_test.go +++ /dev/null @@ -1,282 +0,0 @@ -package patchschedules - -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 = RediId{} - -func TestNewRediID(t *testing.T) { - id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } -} - -func TestFormatRediID(t *testing.T) { - actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseRediID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestParseRediIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestSegmentsForRediId(t *testing.T) { - segments := RediId{}.Segments() - if len(segments) == 0 { - t.Fatalf("RediId 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/redis/2021-06-01/patchschedules/method_createorupdate_autorest.go b/resource-manager/redis/2021-06-01/patchschedules/method_createorupdate_autorest.go deleted file mode 100644 index 804d3c7d0e4..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/method_createorupdate_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package patchschedules - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *RedisPatchSchedule -} - -// CreateOrUpdate ... -func (c PatchSchedulesClient) CreateOrUpdate(ctx context.Context, id RediId, input RedisPatchSchedule) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c PatchSchedulesClient) preparerForCreateOrUpdate(ctx context.Context, id RediId, input RedisPatchSchedule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules/default", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always -// closes the http.Response Body. -func (c PatchSchedulesClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/method_delete_autorest.go b/resource-manager/redis/2021-06-01/patchschedules/method_delete_autorest.go deleted file mode 100644 index f51c9818c15..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/method_delete_autorest.go +++ /dev/null @@ -1,67 +0,0 @@ -package patchschedules - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c PatchSchedulesClient) Delete(ctx context.Context, id RediId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c PatchSchedulesClient) preparerForDelete(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules/default", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c PatchSchedulesClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/method_get_autorest.go b/resource-manager/redis/2021-06-01/patchschedules/method_get_autorest.go deleted file mode 100644 index 77a94c710c5..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/method_get_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package patchschedules - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *RedisPatchSchedule -} - -// Get ... -func (c PatchSchedulesClient) Get(ctx context.Context, id RediId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c PatchSchedulesClient) preparerForGet(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules/default", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c PatchSchedulesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/method_listbyredisresource_autorest.go b/resource-manager/redis/2021-06-01/patchschedules/method_listbyredisresource_autorest.go deleted file mode 100644 index c1549023b72..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/method_listbyredisresource_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package patchschedules - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByRedisResourceOperationResponse struct { - HttpResponse *http.Response - Model *[]RedisPatchSchedule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByRedisResourceOperationResponse, error) -} - -type ListByRedisResourceCompleteResult struct { - Items []RedisPatchSchedule -} - -func (r ListByRedisResourceOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByRedisResourceOperationResponse) LoadMore(ctx context.Context) (resp ListByRedisResourceOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByRedisResource ... -func (c PatchSchedulesClient) ListByRedisResource(ctx context.Context, id RediId) (resp ListByRedisResourceOperationResponse, err error) { - req, err := c.preparerForListByRedisResource(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "ListByRedisResource", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "ListByRedisResource", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByRedisResource(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "ListByRedisResource", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByRedisResource prepares the ListByRedisResource request. -func (c PatchSchedulesClient) preparerForListByRedisResource(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByRedisResourceWithNextLink prepares the ListByRedisResource request with the given nextLink token. -func (c PatchSchedulesClient) preparerForListByRedisResourceWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByRedisResource handles the response to the ListByRedisResource request. The method always -// closes the http.Response Body. -func (c PatchSchedulesClient) responderForListByRedisResource(resp *http.Response) (result ListByRedisResourceOperationResponse, err error) { - type page struct { - Values []RedisPatchSchedule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByRedisResourceOperationResponse, err error) { - req, err := c.preparerForListByRedisResourceWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "ListByRedisResource", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "ListByRedisResource", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByRedisResource(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "patchschedules.PatchSchedulesClient", "ListByRedisResource", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByRedisResourceComplete retrieves all of the results into a single object -func (c PatchSchedulesClient) ListByRedisResourceComplete(ctx context.Context, id RediId) (ListByRedisResourceCompleteResult, error) { - return c.ListByRedisResourceCompleteMatchingPredicate(ctx, id, RedisPatchScheduleOperationPredicate{}) -} - -// ListByRedisResourceCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c PatchSchedulesClient) ListByRedisResourceCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisPatchScheduleOperationPredicate) (resp ListByRedisResourceCompleteResult, err error) { - items := make([]RedisPatchSchedule, 0) - - page, err := c.ListByRedisResource(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByRedisResourceCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/model_redispatchschedule.go b/resource-manager/redis/2021-06-01/patchschedules/model_redispatchschedule.go deleted file mode 100644 index a1b9d61c768..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/model_redispatchschedule.go +++ /dev/null @@ -1,12 +0,0 @@ -package patchschedules - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisPatchSchedule struct { - Id *string `json:"id,omitempty"` - Location *string `json:"location,omitempty"` - Name *string `json:"name,omitempty"` - Properties ScheduleEntries `json:"properties"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/model_scheduleentries.go b/resource-manager/redis/2021-06-01/patchschedules/model_scheduleentries.go deleted file mode 100644 index d8f2f8f7132..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/model_scheduleentries.go +++ /dev/null @@ -1,8 +0,0 @@ -package patchschedules - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ScheduleEntries struct { - ScheduleEntries []ScheduleEntry `json:"scheduleEntries"` -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/model_scheduleentry.go b/resource-manager/redis/2021-06-01/patchschedules/model_scheduleentry.go deleted file mode 100644 index d0c7b04586c..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/model_scheduleentry.go +++ /dev/null @@ -1,10 +0,0 @@ -package patchschedules - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ScheduleEntry struct { - DayOfWeek DayOfWeek `json:"dayOfWeek"` - MaintenanceWindow *string `json:"maintenanceWindow,omitempty"` - StartHourUtc int64 `json:"startHourUtc"` -} diff --git a/resource-manager/redis/2021-06-01/patchschedules/predicates.go b/resource-manager/redis/2021-06-01/patchschedules/predicates.go deleted file mode 100644 index 68d24a97d80..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/predicates.go +++ /dev/null @@ -1,32 +0,0 @@ -package patchschedules - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisPatchScheduleOperationPredicate struct { - Id *string - Location *string - Name *string - Type *string -} - -func (p RedisPatchScheduleOperationPredicate) Matches(input RedisPatchSchedule) bool { - - 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/redis/2021-06-01/patchschedules/version.go b/resource-manager/redis/2021-06-01/patchschedules/version.go deleted file mode 100644 index 98f2c90925f..00000000000 --- a/resource-manager/redis/2021-06-01/patchschedules/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package patchschedules - -import "fmt" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -const defaultApiVersion = "2021-06-01" - -func userAgent() string { - return fmt.Sprintf("hashicorp/go-azure-sdk/patchschedules/%s", defaultApiVersion) -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/README.md b/resource-manager/redis/2021-06-01/privateendpointconnections/README.md deleted file mode 100644 index 385e64361a0..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/README.md +++ /dev/null @@ -1,85 +0,0 @@ - -## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/privateendpointconnections` Documentation - -The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `redis` (API Version `2021-06-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/redis/2021-06-01/privateendpointconnections" -``` - - -### Client Initialization - -```go -client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") -client.Client.Authorizer = authorizer -``` - - -### Example Usage: `PrivateEndpointConnectionsClient.Delete` - -```go -ctx := context.TODO() -id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "privateEndpointConnectionValue") - -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: `PrivateEndpointConnectionsClient.Get` - -```go -ctx := context.TODO() -id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "privateEndpointConnectionValue") - -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: `PrivateEndpointConnectionsClient.List` - -```go -ctx := context.TODO() -id := privateendpointconnections.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -read, err := client.List(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `PrivateEndpointConnectionsClient.Put` - -```go -ctx := context.TODO() -id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "privateEndpointConnectionValue") - -payload := privateendpointconnections.PrivateEndpointConnection{ - // ... -} - - -if err := client.PutThenPoll(ctx, id, payload); err != nil { - // handle the error -} -``` diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/redis/2021-06-01/privateendpointconnections/id_privateendpointconnection.go deleted file mode 100644 index 05631129a92..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/id_privateendpointconnection.go +++ /dev/null @@ -1,140 +0,0 @@ -package privateendpointconnections - -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 = PrivateEndpointConnectionId{} - -// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection -type PrivateEndpointConnectionId struct { - SubscriptionId string - ResourceGroupName string - RedisName string - PrivateEndpointConnectionName string -} - -// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct -func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, redisName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { - return PrivateEndpointConnectionId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - PrivateEndpointConnectionName: privateEndpointConnectionName, - } -} - -// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId -func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { - parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := PrivateEndpointConnectionId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { - return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId -// note: this method should only be used for API response data and not user input -func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { - parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := PrivateEndpointConnectionId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { - return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID -func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParsePrivateEndpointConnectionID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Private Endpoint Connection ID -func (id PrivateEndpointConnectionId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/privateEndpointConnections/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.PrivateEndpointConnectionName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID -func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), - resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), - resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), - resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), - resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), - } -} - -// String returns a human-readable description of this Private Endpoint Connection ID -func (id PrivateEndpointConnectionId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), - } - return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/redis/2021-06-01/privateendpointconnections/id_privateendpointconnection_test.go deleted file mode 100644 index aadef3d7649..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/id_privateendpointconnection_test.go +++ /dev/null @@ -1,327 +0,0 @@ -package privateendpointconnections - -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 = PrivateEndpointConnectionId{} - -func TestNewPrivateEndpointConnectionID(t *testing.T) { - id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "privateEndpointConnectionValue") - - if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { - t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") - } - - if id.ResourceGroupName != "example-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") - } - - if id.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } - - if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { - t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") - } -} - -func TestFormatPrivateEndpointConnectionID(t *testing.T) { - actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "privateEndpointConnectionValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/privateEndpointConnections/privateEndpointConnectionValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParsePrivateEndpointConnectionID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *PrivateEndpointConnectionId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/privateEndpointConnections", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/privateEndpointConnections/privateEndpointConnectionValue", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - PrivateEndpointConnectionName: "privateEndpointConnectionValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/privateEndpointConnections/privateEndpointConnectionValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParsePrivateEndpointConnectionID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.SubscriptionId != v.Expected.SubscriptionId { - t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) - } - - if actual.ResourceGroupName != v.Expected.ResourceGroupName { - t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) - } - - if actual.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { - t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) - } - - } -} - -func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *PrivateEndpointConnectionId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/privateEndpointConnections", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/privateEndpointConnections/privateEndpointConnectionValue", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - PrivateEndpointConnectionName: "privateEndpointConnectionValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/privateEndpointConnections/privateEndpointConnectionValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", - Expected: &PrivateEndpointConnectionId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.SubscriptionId != v.Expected.SubscriptionId { - t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) - } - - if actual.ResourceGroupName != v.Expected.ResourceGroupName { - t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) - } - - if actual.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { - t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) - } - - } -} - -func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { - segments := PrivateEndpointConnectionId{}.Segments() - if len(segments) == 0 { - t.Fatalf("PrivateEndpointConnectionId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/id_redi.go b/resource-manager/redis/2021-06-01/privateendpointconnections/id_redi.go deleted file mode 100644 index 086b4177452..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/id_redi.go +++ /dev/null @@ -1,127 +0,0 @@ -package privateendpointconnections - -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 = RediId{} - -// RediId is a struct representing the Resource ID for a Redi -type RediId struct { - SubscriptionId string - ResourceGroupName string - RedisName string -} - -// NewRediID returns a new RediId struct -func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { - return RediId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - } -} - -// ParseRediID parses 'input' into a RediId -func ParseRediID(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId -// note: this method should only be used for API response data and not user input -func ParseRediIDInsensitively(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateRediID checks that 'input' can be parsed as a Redi ID -func ValidateRediID(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 := ParseRediID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Redi ID -func (id RediId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Redi ID -func (id RediId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - } -} - -// String returns a human-readable description of this Redi ID -func (id RediId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - } - return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/id_redi_test.go b/resource-manager/redis/2021-06-01/privateendpointconnections/id_redi_test.go deleted file mode 100644 index aec3fe7be1c..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/id_redi_test.go +++ /dev/null @@ -1,282 +0,0 @@ -package privateendpointconnections - -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 = RediId{} - -func TestNewRediID(t *testing.T) { - id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } -} - -func TestFormatRediID(t *testing.T) { - actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseRediID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestParseRediIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestSegmentsForRediId(t *testing.T) { - segments := RediId{}.Segments() - if len(segments) == 0 { - t.Fatalf("RediId 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/redis/2021-06-01/privateendpointconnections/method_delete_autorest.go b/resource-manager/redis/2021-06-01/privateendpointconnections/method_delete_autorest.go deleted file mode 100644 index b722e5929ec..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package privateendpointconnections - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - HttpResponse *http.Response -} - -// Delete ... -func (c PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c PrivateEndpointConnectionsClient) preparerForDelete(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForDelete handles the response to the Delete request. The method always -// closes the http.Response Body. -func (c PrivateEndpointConnectionsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/method_list_autorest.go b/resource-manager/redis/2021-06-01/privateendpointconnections/method_list_autorest.go deleted file mode 100644 index a7c7155d4dd..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/method_list_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package privateendpointconnections - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *PrivateEndpointConnectionListResult -} - -// List ... -func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id RediId) (result ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForList prepares the List request. -func (c PrivateEndpointConnectionsClient) preparerForList(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c PrivateEndpointConnectionsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/method_put_autorest.go b/resource-manager/redis/2021-06-01/privateendpointconnections/method_put_autorest.go deleted file mode 100644 index 6020f9e8b91..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/method_put_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package privateendpointconnections - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// 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 { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Put ... -func (c PrivateEndpointConnectionsClient) Put(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PutOperationResponse, err error) { - req, err := c.preparerForPut(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Put", nil, "Failure preparing request") - return - } - - result, err = c.senderForPut(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpointconnections.PrivateEndpointConnectionsClient", "Put", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// PutThenPoll performs Put then polls until it's completed -func (c PrivateEndpointConnectionsClient) PutThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { - result, err := c.Put(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Put: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Put: %+v", err) - } - - return nil -} - -// preparerForPut prepares the Put request. -func (c PrivateEndpointConnectionsClient) preparerForPut(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForPut sends the Put request. The method will close the -// http.Response Body if it receives an error. -func (c PrivateEndpointConnectionsClient) senderForPut(ctx context.Context, req *http.Request) (future PutOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnection.go deleted file mode 100644 index fde7f4db0fc..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnection.go +++ /dev/null @@ -1,11 +0,0 @@ -package privateendpointconnections - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PrivateEndpointConnection struct { - Id *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnectionproperties.go deleted file mode 100644 index 549d255f069..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/model_privateendpointconnectionproperties.go +++ /dev/null @@ -1,10 +0,0 @@ -package privateendpointconnections - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PrivateEndpointConnectionProperties struct { - PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` - PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` - ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/privateendpointconnections/version.go b/resource-manager/redis/2021-06-01/privateendpointconnections/version.go deleted file mode 100644 index 0d17055f179..00000000000 --- a/resource-manager/redis/2021-06-01/privateendpointconnections/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package privateendpointconnections - -import "fmt" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -const defaultApiVersion = "2021-06-01" - -func userAgent() string { - return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) -} diff --git a/resource-manager/redis/2021-06-01/privatelinkresources/README.md b/resource-manager/redis/2021-06-01/privatelinkresources/README.md deleted file mode 100644 index 20bd272296e..00000000000 --- a/resource-manager/redis/2021-06-01/privatelinkresources/README.md +++ /dev/null @@ -1,36 +0,0 @@ - -## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/privatelinkresources` Documentation - -The `privatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `redis` (API Version `2021-06-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/redis/2021-06-01/privatelinkresources" -``` - - -### Client Initialization - -```go -client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") -client.Client.Authorizer = authorizer -``` - - -### Example Usage: `PrivateLinkResourcesClient.ListByRedisCache` - -```go -ctx := context.TODO() -id := privatelinkresources.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -read, err := client.ListByRedisCache(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/redis/2021-06-01/privatelinkresources/id_redi.go b/resource-manager/redis/2021-06-01/privatelinkresources/id_redi.go deleted file mode 100644 index cd7f8562a88..00000000000 --- a/resource-manager/redis/2021-06-01/privatelinkresources/id_redi.go +++ /dev/null @@ -1,127 +0,0 @@ -package privatelinkresources - -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 = RediId{} - -// RediId is a struct representing the Resource ID for a Redi -type RediId struct { - SubscriptionId string - ResourceGroupName string - RedisName string -} - -// NewRediID returns a new RediId struct -func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { - return RediId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - } -} - -// ParseRediID parses 'input' into a RediId -func ParseRediID(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId -// note: this method should only be used for API response data and not user input -func ParseRediIDInsensitively(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateRediID checks that 'input' can be parsed as a Redi ID -func ValidateRediID(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 := ParseRediID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Redi ID -func (id RediId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Redi ID -func (id RediId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - } -} - -// String returns a human-readable description of this Redi ID -func (id RediId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - } - return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/privatelinkresources/id_redi_test.go b/resource-manager/redis/2021-06-01/privatelinkresources/id_redi_test.go deleted file mode 100644 index 877f51cc8ef..00000000000 --- a/resource-manager/redis/2021-06-01/privatelinkresources/id_redi_test.go +++ /dev/null @@ -1,282 +0,0 @@ -package privatelinkresources - -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 = RediId{} - -func TestNewRediID(t *testing.T) { - id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } -} - -func TestFormatRediID(t *testing.T) { - actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseRediID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestParseRediIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestSegmentsForRediId(t *testing.T) { - segments := RediId{}.Segments() - if len(segments) == 0 { - t.Fatalf("RediId 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/redis/2021-06-01/privatelinkresources/method_listbyrediscache_autorest.go b/resource-manager/redis/2021-06-01/privatelinkresources/method_listbyrediscache_autorest.go deleted file mode 100644 index 402f9f1e249..00000000000 --- a/resource-manager/redis/2021-06-01/privatelinkresources/method_listbyrediscache_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package privatelinkresources - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByRedisCacheOperationResponse struct { - HttpResponse *http.Response - Model *PrivateLinkResourceListResult -} - -// ListByRedisCache ... -func (c PrivateLinkResourcesClient) ListByRedisCache(ctx context.Context, id RediId) (result ListByRedisCacheOperationResponse, err error) { - req, err := c.preparerForListByRedisCache(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "ListByRedisCache", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "ListByRedisCache", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByRedisCache(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "privatelinkresources.PrivateLinkResourcesClient", "ListByRedisCache", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForListByRedisCache prepares the ListByRedisCache request. -func (c PrivateLinkResourcesClient) preparerForListByRedisCache(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByRedisCache handles the response to the ListByRedisCache request. The method always -// closes the http.Response Body. -func (c PrivateLinkResourcesClient) responderForListByRedisCache(resp *http.Response) (result ListByRedisCacheOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/privatelinkresources/model_privatelinkresource.go b/resource-manager/redis/2021-06-01/privatelinkresources/model_privatelinkresource.go deleted file mode 100644 index 69e8ae0e57a..00000000000 --- a/resource-manager/redis/2021-06-01/privatelinkresources/model_privatelinkresource.go +++ /dev/null @@ -1,11 +0,0 @@ -package privatelinkresources - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PrivateLinkResource struct { - Id *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/privatelinkresources/version.go b/resource-manager/redis/2021-06-01/privatelinkresources/version.go deleted file mode 100644 index 4ee29f52669..00000000000 --- a/resource-manager/redis/2021-06-01/privatelinkresources/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package privatelinkresources - -import "fmt" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -const defaultApiVersion = "2021-06-01" - -func userAgent() string { - return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkresources/%s", defaultApiVersion) -} diff --git a/resource-manager/redis/2021-06-01/redis/README.md b/resource-manager/redis/2021-06-01/redis/README.md deleted file mode 100644 index f5f62f01f09..00000000000 --- a/resource-manager/redis/2021-06-01/redis/README.md +++ /dev/null @@ -1,456 +0,0 @@ - -## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/redis` Documentation - -The `redis` SDK allows for interaction with the Azure Resource Manager Service `redis` (API Version `2021-06-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/redis/2021-06-01/redis" -``` - - -### Client Initialization - -```go -client := redis.NewRedisClientWithBaseURI("https://management.azure.com") -client.Client.Authorizer = authorizer -``` - - -### Example Usage: `RedisClient.CheckNameAvailability` - -```go -ctx := context.TODO() -id := redis.NewSubscriptionID("12345678-1234-9876-4563-123456789012") - -payload := redis.CheckNameAvailabilityParameters{ - // ... -} - - -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: `RedisClient.Create` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := redis.RedisCreateParameters{ - // ... -} - - -if err := client.CreateThenPoll(ctx, id, payload); err != nil { - // handle the error -} -``` - - -### Example Usage: `RedisClient.Delete` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -if err := client.DeleteThenPoll(ctx, id); err != nil { - // handle the error -} -``` - - -### Example Usage: `RedisClient.ExportData` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := redis.ExportRDBParameters{ - // ... -} - - -if err := client.ExportDataThenPoll(ctx, id, payload); err != nil { - // handle the error -} -``` - - -### Example Usage: `RedisClient.FirewallRulesCreateOrUpdate` - -```go -ctx := context.TODO() -id := redis.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - -payload := redis.RedisFirewallRule{ - // ... -} - - -read, err := client.FirewallRulesCreateOrUpdate(ctx, id, payload) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.FirewallRulesDelete` - -```go -ctx := context.TODO() -id := redis.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - -read, err := client.FirewallRulesDelete(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.FirewallRulesGet` - -```go -ctx := context.TODO() -id := redis.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - -read, err := client.FirewallRulesGet(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.FirewallRulesList` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -// alternatively `client.FirewallRulesList(ctx, id)` can be used to do batched pagination -items, err := client.FirewallRulesListComplete(ctx, id) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` - - -### Example Usage: `RedisClient.ForceReboot` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := redis.RedisRebootParameters{ - // ... -} - - -read, err := client.ForceReboot(ctx, id, payload) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.Get` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -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: `RedisClient.ImportData` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := redis.ImportRDBParameters{ - // ... -} - - -if err := client.ImportDataThenPoll(ctx, id, payload); err != nil { - // handle the error -} -``` - - -### Example Usage: `RedisClient.LinkedServerCreate` - -```go -ctx := context.TODO() -id := redis.NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "linkedServerValue") - -payload := redis.RedisLinkedServerCreateParameters{ - // ... -} - - -if err := client.LinkedServerCreateThenPoll(ctx, id, payload); err != nil { - // handle the error -} -``` - - -### Example Usage: `RedisClient.LinkedServerDelete` - -```go -ctx := context.TODO() -id := redis.NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "linkedServerValue") - -read, err := client.LinkedServerDelete(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.LinkedServerGet` - -```go -ctx := context.TODO() -id := redis.NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "linkedServerValue") - -read, err := client.LinkedServerGet(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.LinkedServerList` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -// alternatively `client.LinkedServerList(ctx, id)` can be used to do batched pagination -items, err := client.LinkedServerListComplete(ctx, id) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` - - -### Example Usage: `RedisClient.ListByResourceGroup` - -```go -ctx := context.TODO() -id := redis.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") - -// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination -items, err := client.ListByResourceGroupComplete(ctx, id) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` - - -### Example Usage: `RedisClient.ListBySubscription` - -```go -ctx := context.TODO() -id := redis.NewSubscriptionID("12345678-1234-9876-4563-123456789012") - -// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination -items, err := client.ListBySubscriptionComplete(ctx, id) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` - - -### Example Usage: `RedisClient.ListKeys` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -read, err := client.ListKeys(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.ListUpgradeNotifications` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -// alternatively `client.ListUpgradeNotifications(ctx, id, redis.DefaultListUpgradeNotificationsOperationOptions())` can be used to do batched pagination -items, err := client.ListUpgradeNotificationsComplete(ctx, id, redis.DefaultListUpgradeNotificationsOperationOptions()) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` - - -### Example Usage: `RedisClient.PatchSchedulesCreateOrUpdate` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := redis.RedisPatchSchedule{ - // ... -} - - -read, err := client.PatchSchedulesCreateOrUpdate(ctx, id, payload) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.PatchSchedulesDelete` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -read, err := client.PatchSchedulesDelete(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.PatchSchedulesGet` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -read, err := client.PatchSchedulesGet(ctx, id) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.PatchSchedulesListByRedisResource` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -// alternatively `client.PatchSchedulesListByRedisResource(ctx, id)` can be used to do batched pagination -items, err := client.PatchSchedulesListByRedisResourceComplete(ctx, id) -if err != nil { - // handle the error -} -for _, item := range items { - // do something -} -``` - - -### Example Usage: `RedisClient.RegenerateKey` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := redis.RedisRegenerateKeyParameters{ - // ... -} - - -read, err := client.RegenerateKey(ctx, id, payload) -if err != nil { - // handle the error -} -if model := read.Model; model != nil { - // do something with the model/response object -} -``` - - -### Example Usage: `RedisClient.Update` - -```go -ctx := context.TODO() -id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - -payload := redis.RedisUpdateParameters{ - // ... -} - - -read, err := client.Update(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/redis/2021-06-01/redis/client.go b/resource-manager/redis/2021-06-01/redis/client.go deleted file mode 100644 index 36af1b1c1d3..00000000000 --- a/resource-manager/redis/2021-06-01/redis/client.go +++ /dev/null @@ -1,18 +0,0 @@ -package redis - -import "github.com/Azure/go-autorest/autorest" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisClient struct { - Client autorest.Client - baseUri string -} - -func NewRedisClientWithBaseURI(endpoint string) RedisClient { - return RedisClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, - } -} diff --git a/resource-manager/redis/2021-06-01/redis/constants.go b/resource-manager/redis/2021-06-01/redis/constants.go deleted file mode 100644 index e594c9434c4..00000000000 --- a/resource-manager/redis/2021-06-01/redis/constants.go +++ /dev/null @@ -1,383 +0,0 @@ -package redis - -import "strings" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DayOfWeek string - -const ( - DayOfWeekEveryday DayOfWeek = "Everyday" - DayOfWeekFriday DayOfWeek = "Friday" - DayOfWeekMonday DayOfWeek = "Monday" - DayOfWeekSaturday DayOfWeek = "Saturday" - DayOfWeekSunday DayOfWeek = "Sunday" - DayOfWeekThursday DayOfWeek = "Thursday" - DayOfWeekTuesday DayOfWeek = "Tuesday" - DayOfWeekWednesday DayOfWeek = "Wednesday" - DayOfWeekWeekend DayOfWeek = "Weekend" -) - -func PossibleValuesForDayOfWeek() []string { - return []string{ - string(DayOfWeekEveryday), - string(DayOfWeekFriday), - string(DayOfWeekMonday), - string(DayOfWeekSaturday), - string(DayOfWeekSunday), - string(DayOfWeekThursday), - string(DayOfWeekTuesday), - string(DayOfWeekWednesday), - string(DayOfWeekWeekend), - } -} - -func parseDayOfWeek(input string) (*DayOfWeek, error) { - vals := map[string]DayOfWeek{ - "everyday": DayOfWeekEveryday, - "friday": DayOfWeekFriday, - "monday": DayOfWeekMonday, - "saturday": DayOfWeekSaturday, - "sunday": DayOfWeekSunday, - "thursday": DayOfWeekThursday, - "tuesday": DayOfWeekTuesday, - "wednesday": DayOfWeekWednesday, - "weekend": DayOfWeekWeekend, - } - 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 PrivateEndpointConnectionProvisioningState string - -const ( - PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" - PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" - PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" - PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" -) - -func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { - return []string{ - string(PrivateEndpointConnectionProvisioningStateCreating), - string(PrivateEndpointConnectionProvisioningStateDeleting), - string(PrivateEndpointConnectionProvisioningStateFailed), - string(PrivateEndpointConnectionProvisioningStateSucceeded), - } -} - -func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { - vals := map[string]PrivateEndpointConnectionProvisioningState{ - "creating": PrivateEndpointConnectionProvisioningStateCreating, - "deleting": PrivateEndpointConnectionProvisioningStateDeleting, - "failed": PrivateEndpointConnectionProvisioningStateFailed, - "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := PrivateEndpointConnectionProvisioningState(input) - return &out, nil -} - -type PrivateEndpointServiceConnectionStatus string - -const ( - PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" - PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" - PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" -) - -func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { - return []string{ - string(PrivateEndpointServiceConnectionStatusApproved), - string(PrivateEndpointServiceConnectionStatusPending), - string(PrivateEndpointServiceConnectionStatusRejected), - } -} - -func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { - vals := map[string]PrivateEndpointServiceConnectionStatus{ - "approved": PrivateEndpointServiceConnectionStatusApproved, - "pending": PrivateEndpointServiceConnectionStatusPending, - "rejected": PrivateEndpointServiceConnectionStatusRejected, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := PrivateEndpointServiceConnectionStatus(input) - return &out, nil -} - -type ProvisioningState string - -const ( - ProvisioningStateCreating ProvisioningState = "Creating" - ProvisioningStateDeleting ProvisioningState = "Deleting" - ProvisioningStateDisabled ProvisioningState = "Disabled" - ProvisioningStateFailed ProvisioningState = "Failed" - ProvisioningStateLinking ProvisioningState = "Linking" - ProvisioningStateProvisioning ProvisioningState = "Provisioning" - ProvisioningStateRecoveringScaleFailure ProvisioningState = "RecoveringScaleFailure" - ProvisioningStateScaling ProvisioningState = "Scaling" - ProvisioningStateSucceeded ProvisioningState = "Succeeded" - ProvisioningStateUnlinking ProvisioningState = "Unlinking" - ProvisioningStateUnprovisioning ProvisioningState = "Unprovisioning" - ProvisioningStateUpdating ProvisioningState = "Updating" -) - -func PossibleValuesForProvisioningState() []string { - return []string{ - string(ProvisioningStateCreating), - string(ProvisioningStateDeleting), - string(ProvisioningStateDisabled), - string(ProvisioningStateFailed), - string(ProvisioningStateLinking), - string(ProvisioningStateProvisioning), - string(ProvisioningStateRecoveringScaleFailure), - string(ProvisioningStateScaling), - string(ProvisioningStateSucceeded), - string(ProvisioningStateUnlinking), - string(ProvisioningStateUnprovisioning), - string(ProvisioningStateUpdating), - } -} - -func parseProvisioningState(input string) (*ProvisioningState, error) { - vals := map[string]ProvisioningState{ - "creating": ProvisioningStateCreating, - "deleting": ProvisioningStateDeleting, - "disabled": ProvisioningStateDisabled, - "failed": ProvisioningStateFailed, - "linking": ProvisioningStateLinking, - "provisioning": ProvisioningStateProvisioning, - "recoveringscalefailure": ProvisioningStateRecoveringScaleFailure, - "scaling": ProvisioningStateScaling, - "succeeded": ProvisioningStateSucceeded, - "unlinking": ProvisioningStateUnlinking, - "unprovisioning": ProvisioningStateUnprovisioning, - "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 PublicNetworkAccess string - -const ( - PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" - PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" -) - -func PossibleValuesForPublicNetworkAccess() []string { - return []string{ - string(PublicNetworkAccessDisabled), - string(PublicNetworkAccessEnabled), - } -} - -func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { - vals := map[string]PublicNetworkAccess{ - "disabled": PublicNetworkAccessDisabled, - "enabled": PublicNetworkAccessEnabled, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := PublicNetworkAccess(input) - return &out, nil -} - -type RebootType string - -const ( - RebootTypeAllNodes RebootType = "AllNodes" - RebootTypePrimaryNode RebootType = "PrimaryNode" - RebootTypeSecondaryNode RebootType = "SecondaryNode" -) - -func PossibleValuesForRebootType() []string { - return []string{ - string(RebootTypeAllNodes), - string(RebootTypePrimaryNode), - string(RebootTypeSecondaryNode), - } -} - -func parseRebootType(input string) (*RebootType, error) { - vals := map[string]RebootType{ - "allnodes": RebootTypeAllNodes, - "primarynode": RebootTypePrimaryNode, - "secondarynode": RebootTypeSecondaryNode, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := RebootType(input) - return &out, nil -} - -type RedisKeyType string - -const ( - RedisKeyTypePrimary RedisKeyType = "Primary" - RedisKeyTypeSecondary RedisKeyType = "Secondary" -) - -func PossibleValuesForRedisKeyType() []string { - return []string{ - string(RedisKeyTypePrimary), - string(RedisKeyTypeSecondary), - } -} - -func parseRedisKeyType(input string) (*RedisKeyType, error) { - vals := map[string]RedisKeyType{ - "primary": RedisKeyTypePrimary, - "secondary": RedisKeyTypeSecondary, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := RedisKeyType(input) - return &out, nil -} - -type ReplicationRole string - -const ( - ReplicationRolePrimary ReplicationRole = "Primary" - ReplicationRoleSecondary ReplicationRole = "Secondary" -) - -func PossibleValuesForReplicationRole() []string { - return []string{ - string(ReplicationRolePrimary), - string(ReplicationRoleSecondary), - } -} - -func parseReplicationRole(input string) (*ReplicationRole, error) { - vals := map[string]ReplicationRole{ - "primary": ReplicationRolePrimary, - "secondary": ReplicationRoleSecondary, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := ReplicationRole(input) - return &out, nil -} - -type SkuFamily string - -const ( - SkuFamilyC SkuFamily = "C" - SkuFamilyP SkuFamily = "P" -) - -func PossibleValuesForSkuFamily() []string { - return []string{ - string(SkuFamilyC), - string(SkuFamilyP), - } -} - -func parseSkuFamily(input string) (*SkuFamily, error) { - vals := map[string]SkuFamily{ - "c": SkuFamilyC, - "p": SkuFamilyP, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := SkuFamily(input) - return &out, nil -} - -type SkuName string - -const ( - SkuNameBasic SkuName = "Basic" - SkuNamePremium SkuName = "Premium" - SkuNameStandard SkuName = "Standard" -) - -func PossibleValuesForSkuName() []string { - return []string{ - string(SkuNameBasic), - string(SkuNamePremium), - string(SkuNameStandard), - } -} - -func parseSkuName(input string) (*SkuName, error) { - vals := map[string]SkuName{ - "basic": SkuNameBasic, - "premium": SkuNamePremium, - "standard": SkuNameStandard, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := SkuName(input) - return &out, nil -} - -type TlsVersion string - -const ( - TlsVersionOnePointOne TlsVersion = "1.1" - TlsVersionOnePointTwo TlsVersion = "1.2" - TlsVersionOnePointZero TlsVersion = "1.0" -) - -func PossibleValuesForTlsVersion() []string { - return []string{ - string(TlsVersionOnePointOne), - string(TlsVersionOnePointTwo), - string(TlsVersionOnePointZero), - } -} - -func parseTlsVersion(input string) (*TlsVersion, error) { - vals := map[string]TlsVersion{ - "1.1": TlsVersionOnePointOne, - "1.2": TlsVersionOnePointTwo, - "1.0": TlsVersionOnePointZero, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := TlsVersion(input) - return &out, nil -} diff --git a/resource-manager/redis/2021-06-01/redis/id_firewallrule.go b/resource-manager/redis/2021-06-01/redis/id_firewallrule.go deleted file mode 100644 index 4112d34f3b7..00000000000 --- a/resource-manager/redis/2021-06-01/redis/id_firewallrule.go +++ /dev/null @@ -1,140 +0,0 @@ -package redis - -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 = FirewallRuleId{} - -// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule -type FirewallRuleId struct { - SubscriptionId string - ResourceGroupName string - RedisName string - FirewallRuleName string -} - -// NewFirewallRuleID returns a new FirewallRuleId struct -func NewFirewallRuleID(subscriptionId string, resourceGroupName string, redisName string, firewallRuleName string) FirewallRuleId { - return FirewallRuleId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - FirewallRuleName: firewallRuleName, - } -} - -// ParseFirewallRuleID parses 'input' into a FirewallRuleId -func ParseFirewallRuleID(input string) (*FirewallRuleId, error) { - parser := resourceids.NewParserFromResourceIdType(FirewallRuleId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := FirewallRuleId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.FirewallRuleName, ok = parsed.Parsed["firewallRuleName"]; !ok { - return nil, fmt.Errorf("the segment 'firewallRuleName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseFirewallRuleIDInsensitively parses 'input' case-insensitively into a FirewallRuleId -// note: this method should only be used for API response data and not user input -func ParseFirewallRuleIDInsensitively(input string) (*FirewallRuleId, error) { - parser := resourceids.NewParserFromResourceIdType(FirewallRuleId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := FirewallRuleId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.FirewallRuleName, ok = parsed.Parsed["firewallRuleName"]; !ok { - return nil, fmt.Errorf("the segment 'firewallRuleName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateFirewallRuleID checks that 'input' can be parsed as a Firewall Rule ID -func ValidateFirewallRuleID(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 := ParseFirewallRuleID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Firewall Rule ID -func (id FirewallRuleId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/firewallRules/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.FirewallRuleName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Firewall Rule ID -func (id FirewallRuleId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), - resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleValue"), - } -} - -// String returns a human-readable description of this Firewall Rule ID -func (id FirewallRuleId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), - } - return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/redis/id_firewallrule_test.go b/resource-manager/redis/2021-06-01/redis/id_firewallrule_test.go deleted file mode 100644 index 9142b00cb44..00000000000 --- a/resource-manager/redis/2021-06-01/redis/id_firewallrule_test.go +++ /dev/null @@ -1,327 +0,0 @@ -package redis - -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 = FirewallRuleId{} - -func TestNewFirewallRuleID(t *testing.T) { - id := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } - - if id.FirewallRuleName != "firewallRuleValue" { - t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleValue") - } -} - -func TestFormatFirewallRuleID(t *testing.T) { - actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "firewallRuleValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseFirewallRuleID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *FirewallRuleId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue", - Expected: &FirewallRuleId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - FirewallRuleName: "firewallRuleValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseFirewallRuleID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.FirewallRuleName != v.Expected.FirewallRuleName { - t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) - } - - } -} - -func TestParseFirewallRuleIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *FirewallRuleId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/fIrEwAlLrUlEs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue", - Expected: &FirewallRuleId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - FirewallRuleName: "firewallRuleValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/firewallRules/firewallRuleValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe", - Expected: &FirewallRuleId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - FirewallRuleName: "fIrEwAlLrUlEvAlUe", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseFirewallRuleIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.FirewallRuleName != v.Expected.FirewallRuleName { - t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) - } - - } -} - -func TestSegmentsForFirewallRuleId(t *testing.T) { - segments := FirewallRuleId{}.Segments() - if len(segments) == 0 { - t.Fatalf("FirewallRuleId 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/redis/2021-06-01/redis/id_linkedserver.go b/resource-manager/redis/2021-06-01/redis/id_linkedserver.go deleted file mode 100644 index b2b3e02774a..00000000000 --- a/resource-manager/redis/2021-06-01/redis/id_linkedserver.go +++ /dev/null @@ -1,140 +0,0 @@ -package redis - -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 = LinkedServerId{} - -// LinkedServerId is a struct representing the Resource ID for a Linked Server -type LinkedServerId struct { - SubscriptionId string - ResourceGroupName string - RedisName string - LinkedServerName string -} - -// NewLinkedServerID returns a new LinkedServerId struct -func NewLinkedServerID(subscriptionId string, resourceGroupName string, redisName string, linkedServerName string) LinkedServerId { - return LinkedServerId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - LinkedServerName: linkedServerName, - } -} - -// ParseLinkedServerID parses 'input' into a LinkedServerId -func ParseLinkedServerID(input string) (*LinkedServerId, error) { - parser := resourceids.NewParserFromResourceIdType(LinkedServerId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := LinkedServerId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.LinkedServerName, ok = parsed.Parsed["linkedServerName"]; !ok { - return nil, fmt.Errorf("the segment 'linkedServerName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseLinkedServerIDInsensitively parses 'input' case-insensitively into a LinkedServerId -// note: this method should only be used for API response data and not user input -func ParseLinkedServerIDInsensitively(input string) (*LinkedServerId, error) { - parser := resourceids.NewParserFromResourceIdType(LinkedServerId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := LinkedServerId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - if id.LinkedServerName, ok = parsed.Parsed["linkedServerName"]; !ok { - return nil, fmt.Errorf("the segment 'linkedServerName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateLinkedServerID checks that 'input' can be parsed as a Linked Server ID -func ValidateLinkedServerID(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 := ParseLinkedServerID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Linked Server ID -func (id LinkedServerId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/linkedServers/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.LinkedServerName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Linked Server ID -func (id LinkedServerId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - resourceids.StaticSegment("staticLinkedServers", "linkedServers", "linkedServers"), - resourceids.UserSpecifiedSegment("linkedServerName", "linkedServerValue"), - } -} - -// String returns a human-readable description of this Linked Server ID -func (id LinkedServerId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - fmt.Sprintf("Linked Server Name: %q", id.LinkedServerName), - } - return fmt.Sprintf("Linked Server (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/redis/id_linkedserver_test.go b/resource-manager/redis/2021-06-01/redis/id_linkedserver_test.go deleted file mode 100644 index 88ba3700cb2..00000000000 --- a/resource-manager/redis/2021-06-01/redis/id_linkedserver_test.go +++ /dev/null @@ -1,327 +0,0 @@ -package redis - -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 = LinkedServerId{} - -func TestNewLinkedServerID(t *testing.T) { - id := NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "linkedServerValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } - - if id.LinkedServerName != "linkedServerValue" { - t.Fatalf("Expected %q but got %q for Segment 'LinkedServerName'", id.LinkedServerName, "linkedServerValue") - } -} - -func TestFormatLinkedServerID(t *testing.T) { - actual := NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue", "linkedServerValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/linkedServers/linkedServerValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseLinkedServerID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *LinkedServerId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/linkedServers", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/linkedServers/linkedServerValue", - Expected: &LinkedServerId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - LinkedServerName: "linkedServerValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/linkedServers/linkedServerValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseLinkedServerID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.LinkedServerName != v.Expected.LinkedServerName { - t.Fatalf("Expected %q but got %q for LinkedServerName", v.Expected.LinkedServerName, actual.LinkedServerName) - } - - } -} - -func TestParseLinkedServerIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *LinkedServerId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/linkedServers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/lInKeDsErVeRs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/linkedServers/linkedServerValue", - Expected: &LinkedServerId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - LinkedServerName: "linkedServerValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/linkedServers/linkedServerValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE/lInKeDsErVeRs/lInKeDsErVeRvAlUe", - Expected: &LinkedServerId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - LinkedServerName: "lInKeDsErVeRvAlUe", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/lInKeDsErVeRs/lInKeDsErVeRvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseLinkedServerIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - if actual.LinkedServerName != v.Expected.LinkedServerName { - t.Fatalf("Expected %q but got %q for LinkedServerName", v.Expected.LinkedServerName, actual.LinkedServerName) - } - - } -} - -func TestSegmentsForLinkedServerId(t *testing.T) { - segments := LinkedServerId{}.Segments() - if len(segments) == 0 { - t.Fatalf("LinkedServerId 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/redis/2021-06-01/redis/id_redi.go b/resource-manager/redis/2021-06-01/redis/id_redi.go deleted file mode 100644 index 01b9bd58b52..00000000000 --- a/resource-manager/redis/2021-06-01/redis/id_redi.go +++ /dev/null @@ -1,127 +0,0 @@ -package redis - -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 = RediId{} - -// RediId is a struct representing the Resource ID for a Redi -type RediId struct { - SubscriptionId string - ResourceGroupName string - RedisName string -} - -// NewRediID returns a new RediId struct -func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { - return RediId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - RedisName: redisName, - } -} - -// ParseRediID parses 'input' into a RediId -func ParseRediID(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId -// note: this method should only be used for API response data and not user input -func ParseRediIDInsensitively(input string) (*RediId, error) { - parser := resourceids.NewParserFromResourceIdType(RediId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := RediId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.RedisName, ok = parsed.Parsed["redisName"]; !ok { - return nil, fmt.Errorf("the segment 'redisName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateRediID checks that 'input' can be parsed as a Redi ID -func ValidateRediID(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 := ParseRediID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Redi ID -func (id RediId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Redi ID -func (id RediId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), - resourceids.StaticSegment("staticRedis", "redis", "redis"), - resourceids.UserSpecifiedSegment("redisName", "redisValue"), - } -} - -// String returns a human-readable description of this Redi ID -func (id RediId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Redis Name: %q", id.RedisName), - } - return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/redis/2021-06-01/redis/id_redi_test.go b/resource-manager/redis/2021-06-01/redis/id_redi_test.go deleted file mode 100644 index a2e3dccb244..00000000000 --- a/resource-manager/redis/2021-06-01/redis/id_redi_test.go +++ /dev/null @@ -1,282 +0,0 @@ -package redis - -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 = RediId{} - -func TestNewRediID(t *testing.T) { - id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue") - - 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.RedisName != "redisValue" { - t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisValue") - } -} - -func TestFormatRediID(t *testing.T) { - actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseRediID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediID(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestParseRediIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *RediId - }{ - { - // 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.Cache", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - RedisName: "redisValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsVaLuE", - Expected: &RediId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - RedisName: "rEdIsVaLuE", - }, - }, - { - // 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.cAcHe/rEdIs/rEdIsVaLuE/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseRediIDInsensitively(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.RedisName != v.Expected.RedisName { - t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) - } - - } -} - -func TestSegmentsForRediId(t *testing.T) { - segments := RediId{}.Segments() - if len(segments) == 0 { - t.Fatalf("RediId 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/redis/2021-06-01/redis/method_checknameavailability_autorest.go b/resource-manager/redis/2021-06-01/redis/method_checknameavailability_autorest.go deleted file mode 100644 index f2bed614a26..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_checknameavailability_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CheckNameAvailabilityOperationResponse struct { - HttpResponse *http.Response -} - -// CheckNameAvailability ... -func (c RedisClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailabilityParameters) (result CheckNameAvailabilityOperationResponse, err error) { - req, err := c.preparerForCheckNameAvailability(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "CheckNameAvailability", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "CheckNameAvailability", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCheckNameAvailability(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "CheckNameAvailability", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCheckNameAvailability prepares the CheckNameAvailability request. -func (c RedisClient) preparerForCheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailabilityParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Cache/checkNameAvailability", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCheckNameAvailability handles the response to the CheckNameAvailability request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForCheckNameAvailability(resp *http.Response) (result CheckNameAvailabilityOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_create_autorest.go b/resource-manager/redis/2021-06-01/redis/method_create_autorest.go deleted file mode 100644 index 4fcccaf2919..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_create_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Create ... -func (c RedisClient) Create(ctx context.Context, id RediId, input RedisCreateParameters) (result CreateOperationResponse, err error) { - req, err := c.preparerForCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Create", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Create", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateThenPoll performs Create then polls until it's completed -func (c RedisClient) CreateThenPoll(ctx context.Context, id RediId, input RedisCreateParameters) error { - result, err := c.Create(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Create: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Create: %+v", err) - } - - return nil -} - -// preparerForCreate prepares the Create request. -func (c RedisClient) preparerForCreate(ctx context.Context, id RediId, input RedisCreateParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreate sends the Create request. The method will close the -// http.Response Body if it receives an error. -func (c RedisClient) senderForCreate(ctx context.Context, req *http.Request) (future CreateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_delete_autorest.go b/resource-manager/redis/2021-06-01/redis/method_delete_autorest.go deleted file mode 100644 index 00ab7744384..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// 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 polling.LongRunningPoller - HttpResponse *http.Response -} - -// Delete ... -func (c RedisClient) Delete(ctx context.Context, id RediId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c RedisClient) DeleteThenPoll(ctx context.Context, id RediId) error { - result, err := c.Delete(ctx, id) - if err != nil { - return fmt.Errorf("performing Delete: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Delete: %+v", err) - } - - return nil -} - -// preparerForDelete prepares the Delete request. -func (c RedisClient) preparerForDelete(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForDelete sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (c RedisClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_exportdata_autorest.go b/resource-manager/redis/2021-06-01/redis/method_exportdata_autorest.go deleted file mode 100644 index 307523a3b89..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_exportdata_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExportDataOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// ExportData ... -func (c RedisClient) ExportData(ctx context.Context, id RediId, input ExportRDBParameters) (result ExportDataOperationResponse, err error) { - req, err := c.preparerForExportData(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ExportData", nil, "Failure preparing request") - return - } - - result, err = c.senderForExportData(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ExportData", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// ExportDataThenPoll performs ExportData then polls until it's completed -func (c RedisClient) ExportDataThenPoll(ctx context.Context, id RediId, input ExportRDBParameters) error { - result, err := c.ExportData(ctx, id, input) - if err != nil { - return fmt.Errorf("performing ExportData: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after ExportData: %+v", err) - } - - return nil -} - -// preparerForExportData prepares the ExportData request. -func (c RedisClient) preparerForExportData(ctx context.Context, id RediId, input ExportRDBParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/export", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForExportData sends the ExportData request. The method will close the -// http.Response Body if it receives an error. -func (c RedisClient) senderForExportData(ctx context.Context, req *http.Request) (future ExportDataOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_firewallrulescreateorupdate_autorest.go b/resource-manager/redis/2021-06-01/redis/method_firewallrulescreateorupdate_autorest.go deleted file mode 100644 index decd047906e..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_firewallrulescreateorupdate_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package redis - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type FirewallRulesCreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *RedisFirewallRule -} - -// FirewallRulesCreateOrUpdate ... -func (c RedisClient) FirewallRulesCreateOrUpdate(ctx context.Context, id FirewallRuleId, input RedisFirewallRule) (result FirewallRulesCreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForFirewallRulesCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesCreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesCreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForFirewallRulesCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesCreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForFirewallRulesCreateOrUpdate prepares the FirewallRulesCreateOrUpdate request. -func (c RedisClient) preparerForFirewallRulesCreateOrUpdate(ctx context.Context, id FirewallRuleId, input RedisFirewallRule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForFirewallRulesCreateOrUpdate handles the response to the FirewallRulesCreateOrUpdate request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForFirewallRulesCreateOrUpdate(resp *http.Response) (result FirewallRulesCreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_firewallrulesdelete_autorest.go b/resource-manager/redis/2021-06-01/redis/method_firewallrulesdelete_autorest.go deleted file mode 100644 index 33379350389..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_firewallrulesdelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package redis - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type FirewallRulesDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// FirewallRulesDelete ... -func (c RedisClient) FirewallRulesDelete(ctx context.Context, id FirewallRuleId) (result FirewallRulesDeleteOperationResponse, err error) { - req, err := c.preparerForFirewallRulesDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForFirewallRulesDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForFirewallRulesDelete prepares the FirewallRulesDelete request. -func (c RedisClient) preparerForFirewallRulesDelete(ctx context.Context, id FirewallRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForFirewallRulesDelete handles the response to the FirewallRulesDelete request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForFirewallRulesDelete(resp *http.Response) (result FirewallRulesDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_firewallrulesget_autorest.go b/resource-manager/redis/2021-06-01/redis/method_firewallrulesget_autorest.go deleted file mode 100644 index 586eb3181ba..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_firewallrulesget_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package redis - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type FirewallRulesGetOperationResponse struct { - HttpResponse *http.Response - Model *RedisFirewallRule -} - -// FirewallRulesGet ... -func (c RedisClient) FirewallRulesGet(ctx context.Context, id FirewallRuleId) (result FirewallRulesGetOperationResponse, err error) { - req, err := c.preparerForFirewallRulesGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForFirewallRulesGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForFirewallRulesGet prepares the FirewallRulesGet request. -func (c RedisClient) preparerForFirewallRulesGet(ctx context.Context, id FirewallRuleId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForFirewallRulesGet handles the response to the FirewallRulesGet request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForFirewallRulesGet(resp *http.Response) (result FirewallRulesGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_firewallruleslist_autorest.go b/resource-manager/redis/2021-06-01/redis/method_firewallruleslist_autorest.go deleted file mode 100644 index a0bd616d355..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_firewallruleslist_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type FirewallRulesListOperationResponse struct { - HttpResponse *http.Response - Model *[]RedisFirewallRule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (FirewallRulesListOperationResponse, error) -} - -type FirewallRulesListCompleteResult struct { - Items []RedisFirewallRule -} - -func (r FirewallRulesListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r FirewallRulesListOperationResponse) LoadMore(ctx context.Context) (resp FirewallRulesListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// FirewallRulesList ... -func (c RedisClient) FirewallRulesList(ctx context.Context, id RediId) (resp FirewallRulesListOperationResponse, err error) { - req, err := c.preparerForFirewallRulesList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForFirewallRulesList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForFirewallRulesList prepares the FirewallRulesList request. -func (c RedisClient) preparerForFirewallRulesList(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/firewallRules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForFirewallRulesListWithNextLink prepares the FirewallRulesList request with the given nextLink token. -func (c RedisClient) preparerForFirewallRulesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForFirewallRulesList handles the response to the FirewallRulesList request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForFirewallRulesList(resp *http.Response) (result FirewallRulesListOperationResponse, err error) { - type page struct { - Values []RedisFirewallRule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result FirewallRulesListOperationResponse, err error) { - req, err := c.preparerForFirewallRulesListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForFirewallRulesList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "FirewallRulesList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// FirewallRulesListComplete retrieves all of the results into a single object -func (c RedisClient) FirewallRulesListComplete(ctx context.Context, id RediId) (FirewallRulesListCompleteResult, error) { - return c.FirewallRulesListCompleteMatchingPredicate(ctx, id, RedisFirewallRuleOperationPredicate{}) -} - -// FirewallRulesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RedisClient) FirewallRulesListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisFirewallRuleOperationPredicate) (resp FirewallRulesListCompleteResult, err error) { - items := make([]RedisFirewallRule, 0) - - page, err := c.FirewallRulesList(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := FirewallRulesListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/redis/method_forcereboot_autorest.go b/resource-manager/redis/2021-06-01/redis/method_forcereboot_autorest.go deleted file mode 100644 index 6c5700a3cf3..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_forcereboot_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ForceRebootOperationResponse struct { - HttpResponse *http.Response - Model *RedisForceRebootResponse -} - -// ForceReboot ... -func (c RedisClient) ForceReboot(ctx context.Context, id RediId, input RedisRebootParameters) (result ForceRebootOperationResponse, err error) { - req, err := c.preparerForForceReboot(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ForceReboot", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ForceReboot", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForForceReboot(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ForceReboot", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForForceReboot prepares the ForceReboot request. -func (c RedisClient) preparerForForceReboot(ctx context.Context, id RediId, input RedisRebootParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/forceReboot", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForForceReboot handles the response to the ForceReboot request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForForceReboot(resp *http.Response) (result ForceRebootOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_get_autorest.go b/resource-manager/redis/2021-06-01/redis/method_get_autorest.go deleted file mode 100644 index 7c2d15404af..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package redis - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *RedisResource -} - -// Get ... -func (c RedisClient) Get(ctx context.Context, id RediId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c RedisClient) preparerForGet(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_importdata_autorest.go b/resource-manager/redis/2021-06-01/redis/method_importdata_autorest.go deleted file mode 100644 index 73fad918334..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_importdata_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ImportDataOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// ImportData ... -func (c RedisClient) ImportData(ctx context.Context, id RediId, input ImportRDBParameters) (result ImportDataOperationResponse, err error) { - req, err := c.preparerForImportData(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ImportData", nil, "Failure preparing request") - return - } - - result, err = c.senderForImportData(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ImportData", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// ImportDataThenPoll performs ImportData then polls until it's completed -func (c RedisClient) ImportDataThenPoll(ctx context.Context, id RediId, input ImportRDBParameters) error { - result, err := c.ImportData(ctx, id, input) - if err != nil { - return fmt.Errorf("performing ImportData: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after ImportData: %+v", err) - } - - return nil -} - -// preparerForImportData prepares the ImportData request. -func (c RedisClient) preparerForImportData(ctx context.Context, id RediId, input ImportRDBParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/import", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForImportData sends the ImportData request. The method will close the -// http.Response Body if it receives an error. -func (c RedisClient) senderForImportData(ctx context.Context, req *http.Request) (future ImportDataOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_linkedservercreate_autorest.go b/resource-manager/redis/2021-06-01/redis/method_linkedservercreate_autorest.go deleted file mode 100644 index ad587353330..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_linkedservercreate_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type LinkedServerCreateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// LinkedServerCreate ... -func (c RedisClient) LinkedServerCreate(ctx context.Context, id LinkedServerId, input RedisLinkedServerCreateParameters) (result LinkedServerCreateOperationResponse, err error) { - req, err := c.preparerForLinkedServerCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerCreate", nil, "Failure preparing request") - return - } - - result, err = c.senderForLinkedServerCreate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerCreate", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// LinkedServerCreateThenPoll performs LinkedServerCreate then polls until it's completed -func (c RedisClient) LinkedServerCreateThenPoll(ctx context.Context, id LinkedServerId, input RedisLinkedServerCreateParameters) error { - result, err := c.LinkedServerCreate(ctx, id, input) - if err != nil { - return fmt.Errorf("performing LinkedServerCreate: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after LinkedServerCreate: %+v", err) - } - - return nil -} - -// preparerForLinkedServerCreate prepares the LinkedServerCreate request. -func (c RedisClient) preparerForLinkedServerCreate(ctx context.Context, id LinkedServerId, input RedisLinkedServerCreateParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForLinkedServerCreate sends the LinkedServerCreate request. The method will close the -// http.Response Body if it receives an error. -func (c RedisClient) senderForLinkedServerCreate(ctx context.Context, req *http.Request) (future LinkedServerCreateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_linkedserverdelete_autorest.go b/resource-manager/redis/2021-06-01/redis/method_linkedserverdelete_autorest.go deleted file mode 100644 index 59d45b71397..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_linkedserverdelete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package redis - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type LinkedServerDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// LinkedServerDelete ... -func (c RedisClient) LinkedServerDelete(ctx context.Context, id LinkedServerId) (result LinkedServerDeleteOperationResponse, err error) { - req, err := c.preparerForLinkedServerDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForLinkedServerDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForLinkedServerDelete prepares the LinkedServerDelete request. -func (c RedisClient) preparerForLinkedServerDelete(ctx context.Context, id LinkedServerId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForLinkedServerDelete handles the response to the LinkedServerDelete request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForLinkedServerDelete(resp *http.Response) (result LinkedServerDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_linkedserverget_autorest.go b/resource-manager/redis/2021-06-01/redis/method_linkedserverget_autorest.go deleted file mode 100644 index 2be5bab4594..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_linkedserverget_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package redis - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type LinkedServerGetOperationResponse struct { - HttpResponse *http.Response - Model *RedisLinkedServerWithProperties -} - -// LinkedServerGet ... -func (c RedisClient) LinkedServerGet(ctx context.Context, id LinkedServerId) (result LinkedServerGetOperationResponse, err error) { - req, err := c.preparerForLinkedServerGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForLinkedServerGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForLinkedServerGet prepares the LinkedServerGet request. -func (c RedisClient) preparerForLinkedServerGet(ctx context.Context, id LinkedServerId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForLinkedServerGet handles the response to the LinkedServerGet request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForLinkedServerGet(resp *http.Response) (result LinkedServerGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_linkedserverlist_autorest.go b/resource-manager/redis/2021-06-01/redis/method_linkedserverlist_autorest.go deleted file mode 100644 index 21d4c0fc9ed..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_linkedserverlist_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type LinkedServerListOperationResponse struct { - HttpResponse *http.Response - Model *[]RedisLinkedServerWithProperties - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (LinkedServerListOperationResponse, error) -} - -type LinkedServerListCompleteResult struct { - Items []RedisLinkedServerWithProperties -} - -func (r LinkedServerListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r LinkedServerListOperationResponse) LoadMore(ctx context.Context) (resp LinkedServerListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// LinkedServerList ... -func (c RedisClient) LinkedServerList(ctx context.Context, id RediId) (resp LinkedServerListOperationResponse, err error) { - req, err := c.preparerForLinkedServerList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForLinkedServerList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForLinkedServerList prepares the LinkedServerList request. -func (c RedisClient) preparerForLinkedServerList(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/linkedServers", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForLinkedServerListWithNextLink prepares the LinkedServerList request with the given nextLink token. -func (c RedisClient) preparerForLinkedServerListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForLinkedServerList handles the response to the LinkedServerList request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForLinkedServerList(resp *http.Response) (result LinkedServerListOperationResponse, err error) { - type page struct { - Values []RedisLinkedServerWithProperties `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result LinkedServerListOperationResponse, err error) { - req, err := c.preparerForLinkedServerListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForLinkedServerList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "LinkedServerList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// LinkedServerListComplete retrieves all of the results into a single object -func (c RedisClient) LinkedServerListComplete(ctx context.Context, id RediId) (LinkedServerListCompleteResult, error) { - return c.LinkedServerListCompleteMatchingPredicate(ctx, id, RedisLinkedServerWithPropertiesOperationPredicate{}) -} - -// LinkedServerListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RedisClient) LinkedServerListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisLinkedServerWithPropertiesOperationPredicate) (resp LinkedServerListCompleteResult, err error) { - items := make([]RedisLinkedServerWithProperties, 0) - - page, err := c.LinkedServerList(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := LinkedServerListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/redis/method_listbyresourcegroup_autorest.go b/resource-manager/redis/2021-06-01/redis/method_listbyresourcegroup_autorest.go deleted file mode 100644 index 5b25d2915ba..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_listbyresourcegroup_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByResourceGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]RedisResource - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) -} - -type ListByResourceGroupCompleteResult struct { - Items []RedisResource -} - -func (r ListByResourceGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByResourceGroup ... -func (c RedisClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByResourceGroup prepares the ListByResourceGroup request. -func (c RedisClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Cache/redis", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. -func (c RedisClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { - type page struct { - Values []RedisResource `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByResourceGroupComplete retrieves all of the results into a single object -func (c RedisClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { - return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, RedisResourceOperationPredicate{}) -} - -// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RedisClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate RedisResourceOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { - items := make([]RedisResource, 0) - - page, err := c.ListByResourceGroup(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/redis/method_listbysubscription_autorest.go b/resource-manager/redis/2021-06-01/redis/method_listbysubscription_autorest.go deleted file mode 100644 index 08103f373e3..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_listbysubscription_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListBySubscriptionOperationResponse struct { - HttpResponse *http.Response - Model *[]RedisResource - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) -} - -type ListBySubscriptionCompleteResult struct { - Items []RedisResource -} - -func (r ListBySubscriptionOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListBySubscription ... -func (c RedisClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { - req, err := c.preparerForListBySubscription(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListBySubscription", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListBySubscription(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListBySubscription prepares the ListBySubscription request. -func (c RedisClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Cache/redis", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. -func (c RedisClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListBySubscription handles the response to the ListBySubscription request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { - type page struct { - Values []RedisResource `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { - req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListBySubscription", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListBySubscription", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListBySubscription(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListBySubscriptionComplete retrieves all of the results into a single object -func (c RedisClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { - return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, RedisResourceOperationPredicate{}) -} - -// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RedisClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate RedisResourceOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { - items := make([]RedisResource, 0) - - page, err := c.ListBySubscription(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListBySubscriptionCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/redis/method_listkeys_autorest.go b/resource-manager/redis/2021-06-01/redis/method_listkeys_autorest.go deleted file mode 100644 index a9da9cd6b4b..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_listkeys_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListKeysOperationResponse struct { - HttpResponse *http.Response - Model *RedisAccessKeys -} - -// ListKeys ... -func (c RedisClient) ListKeys(ctx context.Context, id RediId) (result ListKeysOperationResponse, err error) { - req, err := c.preparerForListKeys(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListKeys", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListKeys", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListKeys(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListKeys", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForListKeys prepares the ListKeys request. -func (c RedisClient) preparerForListKeys(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/listKeys", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListKeys handles the response to the ListKeys request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForListKeys(resp *http.Response) (result ListKeysOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_listupgradenotifications_autorest.go b/resource-manager/redis/2021-06-01/redis/method_listupgradenotifications_autorest.go deleted file mode 100644 index ed9393cbb7b..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_listupgradenotifications_autorest.go +++ /dev/null @@ -1,215 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListUpgradeNotificationsOperationResponse struct { - HttpResponse *http.Response - Model *[]UpgradeNotification - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListUpgradeNotificationsOperationResponse, error) -} - -type ListUpgradeNotificationsCompleteResult struct { - Items []UpgradeNotification -} - -func (r ListUpgradeNotificationsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListUpgradeNotificationsOperationResponse) LoadMore(ctx context.Context) (resp ListUpgradeNotificationsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListUpgradeNotificationsOperationOptions struct { - History *float64 -} - -func DefaultListUpgradeNotificationsOperationOptions() ListUpgradeNotificationsOperationOptions { - return ListUpgradeNotificationsOperationOptions{} -} - -func (o ListUpgradeNotificationsOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListUpgradeNotificationsOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.History != nil { - out["history"] = *o.History - } - - return out -} - -// ListUpgradeNotifications ... -func (c RedisClient) ListUpgradeNotifications(ctx context.Context, id RediId, options ListUpgradeNotificationsOperationOptions) (resp ListUpgradeNotificationsOperationResponse, err error) { - req, err := c.preparerForListUpgradeNotifications(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListUpgradeNotifications", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListUpgradeNotifications", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListUpgradeNotifications(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListUpgradeNotifications", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListUpgradeNotifications prepares the ListUpgradeNotifications request. -func (c RedisClient) preparerForListUpgradeNotifications(ctx context.Context, id RediId, options ListUpgradeNotificationsOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(fmt.Sprintf("%s/listUpgradeNotifications", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListUpgradeNotificationsWithNextLink prepares the ListUpgradeNotifications request with the given nextLink token. -func (c RedisClient) preparerForListUpgradeNotificationsWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListUpgradeNotifications handles the response to the ListUpgradeNotifications request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForListUpgradeNotifications(resp *http.Response) (result ListUpgradeNotificationsOperationResponse, err error) { - type page struct { - Values []UpgradeNotification `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListUpgradeNotificationsOperationResponse, err error) { - req, err := c.preparerForListUpgradeNotificationsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListUpgradeNotifications", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListUpgradeNotifications", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListUpgradeNotifications(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "ListUpgradeNotifications", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListUpgradeNotificationsComplete retrieves all of the results into a single object -func (c RedisClient) ListUpgradeNotificationsComplete(ctx context.Context, id RediId, options ListUpgradeNotificationsOperationOptions) (ListUpgradeNotificationsCompleteResult, error) { - return c.ListUpgradeNotificationsCompleteMatchingPredicate(ctx, id, options, UpgradeNotificationOperationPredicate{}) -} - -// ListUpgradeNotificationsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RedisClient) ListUpgradeNotificationsCompleteMatchingPredicate(ctx context.Context, id RediId, options ListUpgradeNotificationsOperationOptions, predicate UpgradeNotificationOperationPredicate) (resp ListUpgradeNotificationsCompleteResult, err error) { - items := make([]UpgradeNotification, 0) - - page, err := c.ListUpgradeNotifications(ctx, id, options) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListUpgradeNotificationsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/redis/method_patchschedulescreateorupdate_autorest.go b/resource-manager/redis/2021-06-01/redis/method_patchschedulescreateorupdate_autorest.go deleted file mode 100644 index c395761a64f..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_patchschedulescreateorupdate_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PatchSchedulesCreateOrUpdateOperationResponse struct { - HttpResponse *http.Response - Model *RedisPatchSchedule -} - -// PatchSchedulesCreateOrUpdate ... -func (c RedisClient) PatchSchedulesCreateOrUpdate(ctx context.Context, id RediId, input RedisPatchSchedule) (result PatchSchedulesCreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForPatchSchedulesCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesCreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesCreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForPatchSchedulesCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesCreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForPatchSchedulesCreateOrUpdate prepares the PatchSchedulesCreateOrUpdate request. -func (c RedisClient) preparerForPatchSchedulesCreateOrUpdate(ctx context.Context, id RediId, input RedisPatchSchedule) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules/default", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForPatchSchedulesCreateOrUpdate handles the response to the PatchSchedulesCreateOrUpdate request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForPatchSchedulesCreateOrUpdate(resp *http.Response) (result PatchSchedulesCreateOrUpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_patchschedulesdelete_autorest.go b/resource-manager/redis/2021-06-01/redis/method_patchschedulesdelete_autorest.go deleted file mode 100644 index b71432da14c..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_patchschedulesdelete_autorest.go +++ /dev/null @@ -1,67 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PatchSchedulesDeleteOperationResponse struct { - HttpResponse *http.Response -} - -// PatchSchedulesDelete ... -func (c RedisClient) PatchSchedulesDelete(ctx context.Context, id RediId) (result PatchSchedulesDeleteOperationResponse, err error) { - req, err := c.preparerForPatchSchedulesDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesDelete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesDelete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForPatchSchedulesDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesDelete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForPatchSchedulesDelete prepares the PatchSchedulesDelete request. -func (c RedisClient) preparerForPatchSchedulesDelete(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules/default", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForPatchSchedulesDelete handles the response to the PatchSchedulesDelete request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForPatchSchedulesDelete(resp *http.Response) (result PatchSchedulesDeleteOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_patchschedulesget_autorest.go b/resource-manager/redis/2021-06-01/redis/method_patchschedulesget_autorest.go deleted file mode 100644 index 8604f06df69..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_patchschedulesget_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PatchSchedulesGetOperationResponse struct { - HttpResponse *http.Response - Model *RedisPatchSchedule -} - -// PatchSchedulesGet ... -func (c RedisClient) PatchSchedulesGet(ctx context.Context, id RediId) (result PatchSchedulesGetOperationResponse, err error) { - req, err := c.preparerForPatchSchedulesGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForPatchSchedulesGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForPatchSchedulesGet prepares the PatchSchedulesGet request. -func (c RedisClient) preparerForPatchSchedulesGet(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules/default", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForPatchSchedulesGet handles the response to the PatchSchedulesGet request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForPatchSchedulesGet(resp *http.Response) (result PatchSchedulesGetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_patchscheduleslistbyredisresource_autorest.go b/resource-manager/redis/2021-06-01/redis/method_patchscheduleslistbyredisresource_autorest.go deleted file mode 100644 index a29f4d3d5fd..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_patchscheduleslistbyredisresource_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PatchSchedulesListByRedisResourceOperationResponse struct { - HttpResponse *http.Response - Model *[]RedisPatchSchedule - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (PatchSchedulesListByRedisResourceOperationResponse, error) -} - -type PatchSchedulesListByRedisResourceCompleteResult struct { - Items []RedisPatchSchedule -} - -func (r PatchSchedulesListByRedisResourceOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r PatchSchedulesListByRedisResourceOperationResponse) LoadMore(ctx context.Context) (resp PatchSchedulesListByRedisResourceOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// PatchSchedulesListByRedisResource ... -func (c RedisClient) PatchSchedulesListByRedisResource(ctx context.Context, id RediId) (resp PatchSchedulesListByRedisResourceOperationResponse, err error) { - req, err := c.preparerForPatchSchedulesListByRedisResource(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesListByRedisResource", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesListByRedisResource", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForPatchSchedulesListByRedisResource(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesListByRedisResource", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForPatchSchedulesListByRedisResource prepares the PatchSchedulesListByRedisResource request. -func (c RedisClient) preparerForPatchSchedulesListByRedisResource(ctx context.Context, id RediId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/patchSchedules", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForPatchSchedulesListByRedisResourceWithNextLink prepares the PatchSchedulesListByRedisResource request with the given nextLink token. -func (c RedisClient) preparerForPatchSchedulesListByRedisResourceWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForPatchSchedulesListByRedisResource handles the response to the PatchSchedulesListByRedisResource request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForPatchSchedulesListByRedisResource(resp *http.Response) (result PatchSchedulesListByRedisResourceOperationResponse, err error) { - type page struct { - Values []RedisPatchSchedule `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result PatchSchedulesListByRedisResourceOperationResponse, err error) { - req, err := c.preparerForPatchSchedulesListByRedisResourceWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesListByRedisResource", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesListByRedisResource", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForPatchSchedulesListByRedisResource(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "PatchSchedulesListByRedisResource", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// PatchSchedulesListByRedisResourceComplete retrieves all of the results into a single object -func (c RedisClient) PatchSchedulesListByRedisResourceComplete(ctx context.Context, id RediId) (PatchSchedulesListByRedisResourceCompleteResult, error) { - return c.PatchSchedulesListByRedisResourceCompleteMatchingPredicate(ctx, id, RedisPatchScheduleOperationPredicate{}) -} - -// PatchSchedulesListByRedisResourceCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c RedisClient) PatchSchedulesListByRedisResourceCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisPatchScheduleOperationPredicate) (resp PatchSchedulesListByRedisResourceCompleteResult, err error) { - items := make([]RedisPatchSchedule, 0) - - page, err := c.PatchSchedulesListByRedisResource(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := PatchSchedulesListByRedisResourceCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/redis/2021-06-01/redis/method_regeneratekey_autorest.go b/resource-manager/redis/2021-06-01/redis/method_regeneratekey_autorest.go deleted file mode 100644 index 04356439423..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_regeneratekey_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package redis - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RegenerateKeyOperationResponse struct { - HttpResponse *http.Response - Model *RedisAccessKeys -} - -// RegenerateKey ... -func (c RedisClient) RegenerateKey(ctx context.Context, id RediId, input RedisRegenerateKeyParameters) (result RegenerateKeyOperationResponse, err error) { - req, err := c.preparerForRegenerateKey(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "RegenerateKey", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "RegenerateKey", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForRegenerateKey(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "RegenerateKey", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForRegenerateKey prepares the RegenerateKey request. -func (c RedisClient) preparerForRegenerateKey(ctx context.Context, id RediId, input RedisRegenerateKeyParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/regenerateKey", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForRegenerateKey handles the response to the RegenerateKey request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForRegenerateKey(resp *http.Response) (result RegenerateKeyOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/method_update_autorest.go b/resource-manager/redis/2021-06-01/redis/method_update_autorest.go deleted file mode 100644 index 378b7a1f1c3..00000000000 --- a/resource-manager/redis/2021-06-01/redis/method_update_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package redis - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - HttpResponse *http.Response - Model *RedisResource -} - -// Update ... -func (c RedisClient) Update(ctx context.Context, id RediId, input RedisUpdateParameters) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "redis.RedisClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c RedisClient) preparerForUpdate(ctx context.Context, id RediId, input RedisUpdateParameters) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForUpdate handles the response to the Update request. The method always -// closes the http.Response Body. -func (c RedisClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/redis/2021-06-01/redis/model_checknameavailabilityparameters.go b/resource-manager/redis/2021-06-01/redis/model_checknameavailabilityparameters.go deleted file mode 100644 index ed132a3981c..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_checknameavailabilityparameters.go +++ /dev/null @@ -1,9 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CheckNameAvailabilityParameters struct { - Name string `json:"name"` - Type string `json:"type"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_exportrdbparameters.go b/resource-manager/redis/2021-06-01/redis/model_exportrdbparameters.go deleted file mode 100644 index cff366a19ba..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_exportrdbparameters.go +++ /dev/null @@ -1,10 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ExportRDBParameters struct { - Container string `json:"container"` - Format *string `json:"format,omitempty"` - Prefix string `json:"prefix"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_importrdbparameters.go b/resource-manager/redis/2021-06-01/redis/model_importrdbparameters.go deleted file mode 100644 index 8be7995e9b5..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_importrdbparameters.go +++ /dev/null @@ -1,9 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ImportRDBParameters struct { - Files []string `json:"files"` - Format *string `json:"format,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_privateendpoint.go b/resource-manager/redis/2021-06-01/redis/model_privateendpoint.go deleted file mode 100644 index feae3de5d68..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_privateendpoint.go +++ /dev/null @@ -1,8 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PrivateEndpoint struct { - Id *string `json:"id,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_privateendpointconnection.go b/resource-manager/redis/2021-06-01/redis/model_privateendpointconnection.go deleted file mode 100644 index f29ef3379a4..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_privateendpointconnection.go +++ /dev/null @@ -1,11 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PrivateEndpointConnection struct { - Id *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_privateendpointconnectionproperties.go b/resource-manager/redis/2021-06-01/redis/model_privateendpointconnectionproperties.go deleted file mode 100644 index e2c073d021f..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_privateendpointconnectionproperties.go +++ /dev/null @@ -1,10 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PrivateEndpointConnectionProperties struct { - PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` - PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` - ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_privatelinkserviceconnectionstate.go b/resource-manager/redis/2021-06-01/redis/model_privatelinkserviceconnectionstate.go deleted file mode 100644 index e37ff707407..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_privatelinkserviceconnectionstate.go +++ /dev/null @@ -1,10 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type PrivateLinkServiceConnectionState struct { - ActionsRequired *string `json:"actionsRequired,omitempty"` - Description *string `json:"description,omitempty"` - Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisaccesskeys.go b/resource-manager/redis/2021-06-01/redis/model_redisaccesskeys.go deleted file mode 100644 index fc3136b6cab..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisaccesskeys.go +++ /dev/null @@ -1,9 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisAccessKeys struct { - PrimaryKey *string `json:"primaryKey,omitempty"` - SecondaryKey *string `json:"secondaryKey,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_rediscommonpropertiesredisconfiguration.go b/resource-manager/redis/2021-06-01/redis/model_rediscommonpropertiesredisconfiguration.go deleted file mode 100644 index d3c31fee073..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_rediscommonpropertiesredisconfiguration.go +++ /dev/null @@ -1,24 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisCommonPropertiesRedisConfiguration struct { - AofBackupEnabled *string `json:"aof-backup-enabled,omitempty"` - AofStorageConnectionString0 *string `json:"aof-storage-connection-string-0,omitempty"` - AofStorageConnectionString1 *string `json:"aof-storage-connection-string-1,omitempty"` - Authnotrequired *string `json:"authnotrequired,omitempty"` - Maxclients *string `json:"maxclients,omitempty"` - MaxfragmentationmemoryReserved *string `json:"maxfragmentationmemory-reserved,omitempty"` - MaxmemoryDelta *string `json:"maxmemory-delta,omitempty"` - MaxmemoryPolicy *string `json:"maxmemory-policy,omitempty"` - MaxmemoryReserved *string `json:"maxmemory-reserved,omitempty"` - NotifyKeyspaceEvents *string `json:"notify-keyspace-events,omitempty"` - PreferredDataArchiveAuthMethod *string `json:"preferred-data-archive-auth-method,omitempty"` - PreferredDataPersistenceAuthMethod *string `json:"preferred-data-persistence-auth-method,omitempty"` - RdbBackupEnabled *string `json:"rdb-backup-enabled,omitempty"` - RdbBackupFrequency *string `json:"rdb-backup-frequency,omitempty"` - RdbBackupMaxSnapshotCount *string `json:"rdb-backup-max-snapshot-count,omitempty"` - RdbStorageConnectionString *string `json:"rdb-storage-connection-string,omitempty"` - ZonalConfiguration *string `json:"zonal-configuration,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_rediscreateparameters.go b/resource-manager/redis/2021-06-01/redis/model_rediscreateparameters.go deleted file mode 100644 index 5d9c5e9f761..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_rediscreateparameters.go +++ /dev/null @@ -1,17 +0,0 @@ -package redis - -import ( - "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" - "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisCreateParameters struct { - Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` - Location string `json:"location"` - Properties RedisCreateProperties `json:"properties"` - Tags *map[string]string `json:"tags,omitempty"` - Zones *zones.Schema `json:"zones,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_rediscreateproperties.go b/resource-manager/redis/2021-06-01/redis/model_rediscreateproperties.go deleted file mode 100644 index 0ef298ce288..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_rediscreateproperties.go +++ /dev/null @@ -1,19 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisCreateProperties struct { - EnableNonSslPort *bool `json:"enableNonSslPort,omitempty"` - MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` - PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` - RedisConfiguration *RedisCommonPropertiesRedisConfiguration `json:"redisConfiguration,omitempty"` - RedisVersion *string `json:"redisVersion,omitempty"` - ReplicasPerMaster *int64 `json:"replicasPerMaster,omitempty"` - ReplicasPerPrimary *int64 `json:"replicasPerPrimary,omitempty"` - ShardCount *int64 `json:"shardCount,omitempty"` - Sku Sku `json:"sku"` - StaticIP *string `json:"staticIP,omitempty"` - SubnetId *string `json:"subnetId,omitempty"` - TenantSettings *map[string]string `json:"tenantSettings,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisfirewallrule.go b/resource-manager/redis/2021-06-01/redis/model_redisfirewallrule.go deleted file mode 100644 index 7e290af26c4..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisfirewallrule.go +++ /dev/null @@ -1,11 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisFirewallRule struct { - Id *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Properties RedisFirewallRuleProperties `json:"properties"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisfirewallruleproperties.go b/resource-manager/redis/2021-06-01/redis/model_redisfirewallruleproperties.go deleted file mode 100644 index 0b599eb2f75..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisfirewallruleproperties.go +++ /dev/null @@ -1,9 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisFirewallRuleProperties struct { - EndIP string `json:"endIP"` - StartIP string `json:"startIP"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisforcerebootresponse.go b/resource-manager/redis/2021-06-01/redis/model_redisforcerebootresponse.go deleted file mode 100644 index 8108fdf0b06..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisforcerebootresponse.go +++ /dev/null @@ -1,8 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisForceRebootResponse struct { - Message *string `json:"message,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisinstancedetails.go b/resource-manager/redis/2021-06-01/redis/model_redisinstancedetails.go deleted file mode 100644 index 660f035ab2f..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisinstancedetails.go +++ /dev/null @@ -1,13 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisInstanceDetails struct { - IsMaster *bool `json:"isMaster,omitempty"` - IsPrimary *bool `json:"isPrimary,omitempty"` - NonSslPort *int64 `json:"nonSslPort,omitempty"` - ShardId *int64 `json:"shardId,omitempty"` - SslPort *int64 `json:"sslPort,omitempty"` - Zone *string `json:"zone,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redislinkedserver.go b/resource-manager/redis/2021-06-01/redis/model_redislinkedserver.go deleted file mode 100644 index 1336ebf305b..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redislinkedserver.go +++ /dev/null @@ -1,8 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisLinkedServer struct { - Id *string `json:"id,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redislinkedservercreateparameters.go b/resource-manager/redis/2021-06-01/redis/model_redislinkedservercreateparameters.go deleted file mode 100644 index bcea5475afd..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redislinkedservercreateparameters.go +++ /dev/null @@ -1,8 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisLinkedServerCreateParameters struct { - Properties RedisLinkedServerCreateProperties `json:"properties"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redislinkedservercreateproperties.go b/resource-manager/redis/2021-06-01/redis/model_redislinkedservercreateproperties.go deleted file mode 100644 index 6f871a65321..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redislinkedservercreateproperties.go +++ /dev/null @@ -1,10 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisLinkedServerCreateProperties struct { - LinkedRedisCacheId string `json:"linkedRedisCacheId"` - LinkedRedisCacheLocation string `json:"linkedRedisCacheLocation"` - ServerRole ReplicationRole `json:"serverRole"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redislinkedserverproperties.go b/resource-manager/redis/2021-06-01/redis/model_redislinkedserverproperties.go deleted file mode 100644 index fda9bc684cb..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redislinkedserverproperties.go +++ /dev/null @@ -1,11 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisLinkedServerProperties struct { - LinkedRedisCacheId string `json:"linkedRedisCacheId"` - LinkedRedisCacheLocation string `json:"linkedRedisCacheLocation"` - ProvisioningState *string `json:"provisioningState,omitempty"` - ServerRole ReplicationRole `json:"serverRole"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redislinkedserverwithproperties.go b/resource-manager/redis/2021-06-01/redis/model_redislinkedserverwithproperties.go deleted file mode 100644 index 9e2f5220720..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redislinkedserverwithproperties.go +++ /dev/null @@ -1,11 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisLinkedServerWithProperties struct { - Id *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Properties *RedisLinkedServerProperties `json:"properties,omitempty"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redispatchschedule.go b/resource-manager/redis/2021-06-01/redis/model_redispatchschedule.go deleted file mode 100644 index 8f2e294d43b..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redispatchschedule.go +++ /dev/null @@ -1,12 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisPatchSchedule struct { - Id *string `json:"id,omitempty"` - Location *string `json:"location,omitempty"` - Name *string `json:"name,omitempty"` - Properties ScheduleEntries `json:"properties"` - Type *string `json:"type,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisproperties.go b/resource-manager/redis/2021-06-01/redis/model_redisproperties.go deleted file mode 100644 index a96036196ab..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisproperties.go +++ /dev/null @@ -1,27 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisProperties struct { - AccessKeys *RedisAccessKeys `json:"accessKeys,omitempty"` - EnableNonSslPort *bool `json:"enableNonSslPort,omitempty"` - HostName *string `json:"hostName,omitempty"` - Instances *[]RedisInstanceDetails `json:"instances,omitempty"` - LinkedServers *[]RedisLinkedServer `json:"linkedServers,omitempty"` - MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` - Port *int64 `json:"port,omitempty"` - PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` - ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` - PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` - RedisConfiguration *RedisCommonPropertiesRedisConfiguration `json:"redisConfiguration,omitempty"` - RedisVersion *string `json:"redisVersion,omitempty"` - ReplicasPerMaster *int64 `json:"replicasPerMaster,omitempty"` - ReplicasPerPrimary *int64 `json:"replicasPerPrimary,omitempty"` - ShardCount *int64 `json:"shardCount,omitempty"` - Sku Sku `json:"sku"` - SslPort *int64 `json:"sslPort,omitempty"` - StaticIP *string `json:"staticIP,omitempty"` - SubnetId *string `json:"subnetId,omitempty"` - TenantSettings *map[string]string `json:"tenantSettings,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisrebootparameters.go b/resource-manager/redis/2021-06-01/redis/model_redisrebootparameters.go deleted file mode 100644 index 774681c97e8..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisrebootparameters.go +++ /dev/null @@ -1,10 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisRebootParameters struct { - Ports *[]int64 `json:"ports,omitempty"` - RebootType *RebootType `json:"rebootType,omitempty"` - ShardId *int64 `json:"shardId,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisregeneratekeyparameters.go b/resource-manager/redis/2021-06-01/redis/model_redisregeneratekeyparameters.go deleted file mode 100644 index 7513a779b6a..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisregeneratekeyparameters.go +++ /dev/null @@ -1,8 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisRegenerateKeyParameters struct { - KeyType RedisKeyType `json:"keyType"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisresource.go b/resource-manager/redis/2021-06-01/redis/model_redisresource.go deleted file mode 100644 index aa8085ff87f..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisresource.go +++ /dev/null @@ -1,20 +0,0 @@ -package redis - -import ( - "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" - "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisResource struct { - Id *string `json:"id,omitempty"` - Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` - Location string `json:"location"` - Name *string `json:"name,omitempty"` - Properties RedisProperties `json:"properties"` - Tags *map[string]string `json:"tags,omitempty"` - Type *string `json:"type,omitempty"` - Zones *zones.Schema `json:"zones,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisupdateparameters.go b/resource-manager/redis/2021-06-01/redis/model_redisupdateparameters.go deleted file mode 100644 index 75fc22ebd5f..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisupdateparameters.go +++ /dev/null @@ -1,14 +0,0 @@ -package redis - -import ( - "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisUpdateParameters struct { - Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` - Properties *RedisUpdateProperties `json:"properties,omitempty"` - Tags *map[string]string `json:"tags,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_redisupdateproperties.go b/resource-manager/redis/2021-06-01/redis/model_redisupdateproperties.go deleted file mode 100644 index e7e74932773..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_redisupdateproperties.go +++ /dev/null @@ -1,17 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisUpdateProperties struct { - EnableNonSslPort *bool `json:"enableNonSslPort,omitempty"` - MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` - PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` - RedisConfiguration *RedisCommonPropertiesRedisConfiguration `json:"redisConfiguration,omitempty"` - RedisVersion *string `json:"redisVersion,omitempty"` - ReplicasPerMaster *int64 `json:"replicasPerMaster,omitempty"` - ReplicasPerPrimary *int64 `json:"replicasPerPrimary,omitempty"` - ShardCount *int64 `json:"shardCount,omitempty"` - Sku *Sku `json:"sku,omitempty"` - TenantSettings *map[string]string `json:"tenantSettings,omitempty"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_scheduleentries.go b/resource-manager/redis/2021-06-01/redis/model_scheduleentries.go deleted file mode 100644 index b51c737b6dc..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_scheduleentries.go +++ /dev/null @@ -1,8 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ScheduleEntries struct { - ScheduleEntries []ScheduleEntry `json:"scheduleEntries"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_scheduleentry.go b/resource-manager/redis/2021-06-01/redis/model_scheduleentry.go deleted file mode 100644 index 5be2fd65088..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_scheduleentry.go +++ /dev/null @@ -1,10 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ScheduleEntry struct { - DayOfWeek DayOfWeek `json:"dayOfWeek"` - MaintenanceWindow *string `json:"maintenanceWindow,omitempty"` - StartHourUtc int64 `json:"startHourUtc"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_sku.go b/resource-manager/redis/2021-06-01/redis/model_sku.go deleted file mode 100644 index da88aeee704..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_sku.go +++ /dev/null @@ -1,10 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type Sku struct { - Capacity int64 `json:"capacity"` - Family SkuFamily `json:"family"` - Name SkuName `json:"name"` -} diff --git a/resource-manager/redis/2021-06-01/redis/model_upgradenotification.go b/resource-manager/redis/2021-06-01/redis/model_upgradenotification.go deleted file mode 100644 index 418f8789093..00000000000 --- a/resource-manager/redis/2021-06-01/redis/model_upgradenotification.go +++ /dev/null @@ -1,28 +0,0 @@ -package redis - -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 UpgradeNotification struct { - Name *string `json:"name,omitempty"` - Timestamp *string `json:"timestamp,omitempty"` - UpsellNotification *map[string]string `json:"upsellNotification,omitempty"` -} - -func (o *UpgradeNotification) GetTimestampAsTime() (*time.Time, error) { - if o.Timestamp == nil { - return nil, nil - } - return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") -} - -func (o *UpgradeNotification) SetTimestampAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.Timestamp = &formatted -} diff --git a/resource-manager/redis/2021-06-01/redis/predicates.go b/resource-manager/redis/2021-06-01/redis/predicates.go deleted file mode 100644 index 7f122b3eaf2..00000000000 --- a/resource-manager/redis/2021-06-01/redis/predicates.go +++ /dev/null @@ -1,124 +0,0 @@ -package redis - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedisFirewallRuleOperationPredicate struct { - Id *string - Name *string - Type *string -} - -func (p RedisFirewallRuleOperationPredicate) Matches(input RedisFirewallRule) 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 RedisLinkedServerWithPropertiesOperationPredicate struct { - Id *string - Name *string - Type *string -} - -func (p RedisLinkedServerWithPropertiesOperationPredicate) Matches(input RedisLinkedServerWithProperties) 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 RedisPatchScheduleOperationPredicate struct { - Id *string - Location *string - Name *string - Type *string -} - -func (p RedisPatchScheduleOperationPredicate) Matches(input RedisPatchSchedule) bool { - - 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 -} - -type RedisResourceOperationPredicate struct { - Id *string - Location *string - Name *string - Type *string -} - -func (p RedisResourceOperationPredicate) Matches(input RedisResource) bool { - - 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 -} - -type UpgradeNotificationOperationPredicate struct { - Name *string - Timestamp *string -} - -func (p UpgradeNotificationOperationPredicate) Matches(input UpgradeNotification) bool { - - if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { - return false - } - - if p.Timestamp != nil && (input.Timestamp == nil && *p.Timestamp != *input.Timestamp) { - return false - } - - return true -} diff --git a/resource-manager/redis/2021-06-01/redis/version.go b/resource-manager/redis/2021-06-01/redis/version.go deleted file mode 100644 index faad986bd9a..00000000000 --- a/resource-manager/redis/2021-06-01/redis/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package redis - -import "fmt" - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -const defaultApiVersion = "2021-06-01" - -func userAgent() string { - return fmt.Sprintf("hashicorp/go-azure-sdk/redis/%s", defaultApiVersion) -} diff --git a/resource-manager/signalr/2023-02-01/client.go b/resource-manager/signalr/2023-02-01/client.go new file mode 100644 index 00000000000..e9dc407e2a7 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/client.go @@ -0,0 +1,28 @@ +package v2023_02_01 + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/signalr/2023-02-01/signalr" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 Client struct { + SignalR *signalr.SignalRClient +} + +func NewClientWithBaseURI(api environments.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + signalRClient, err := signalr.NewSignalRClientWithBaseURI(api) + if err != nil { + return nil, fmt.Errorf("building SignalR client: %+v", err) + } + configureFunc(signalRClient.Client) + + return &Client{ + SignalR: signalRClient, + }, nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/README.md b/resource-manager/signalr/2023-02-01/signalr/README.md new file mode 100644 index 00000000000..3462686063d --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/README.md @@ -0,0 +1,488 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/signalr/2023-02-01/signalr` Documentation + +The `signalr` SDK allows for interaction with the Azure Resource Manager Service `signalr` (API Version `2023-02-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/signalr/2023-02-01/signalr" +``` + + +### Client Initialization + +```go +client := signalr.NewSignalRClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SignalRClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := signalr.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := signalr.NameAvailabilityParameters{ + // ... +} + + +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: `SignalRClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +payload := signalr.SignalRResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.CustomCertificatesCreateOrUpdate` + +```go +ctx := context.TODO() +id := signalr.NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customCertificateValue") + +payload := signalr.CustomCertificate{ + // ... +} + + +if err := client.CustomCertificatesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.CustomCertificatesDelete` + +```go +ctx := context.TODO() +id := signalr.NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customCertificateValue") + +read, err := client.CustomCertificatesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.CustomCertificatesGet` + +```go +ctx := context.TODO() +id := signalr.NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customCertificateValue") + +read, err := client.CustomCertificatesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.CustomCertificatesList` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +// alternatively `client.CustomCertificatesList(ctx, id)` can be used to do batched pagination +items, err := client.CustomCertificatesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SignalRClient.CustomDomainsCreateOrUpdate` + +```go +ctx := context.TODO() +id := signalr.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customDomainValue") + +payload := signalr.CustomDomain{ + // ... +} + + +if err := client.CustomDomainsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.CustomDomainsDelete` + +```go +ctx := context.TODO() +id := signalr.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customDomainValue") + +if err := client.CustomDomainsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.CustomDomainsGet` + +```go +ctx := context.TODO() +id := signalr.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customDomainValue") + +read, err := client.CustomDomainsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.CustomDomainsList` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +// alternatively `client.CustomDomainsList(ctx, id)` can be used to do batched pagination +items, err := client.CustomDomainsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SignalRClient.Delete` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.Get` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +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: `SignalRClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := signalr.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SignalRClient.ListBySubscription` + +```go +ctx := context.TODO() +id := signalr.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SignalRClient.ListKeys` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +read, err := client.ListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.ListSkus` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +read, err := client.ListSkus(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.PrivateEndpointConnectionsDelete` + +```go +ctx := context.TODO() +id := signalr.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "privateEndpointConnectionValue") + +if err := client.PrivateEndpointConnectionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.PrivateEndpointConnectionsGet` + +```go +ctx := context.TODO() +id := signalr.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "privateEndpointConnectionValue") + +read, err := client.PrivateEndpointConnectionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.PrivateEndpointConnectionsList` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +// alternatively `client.PrivateEndpointConnectionsList(ctx, id)` can be used to do batched pagination +items, err := client.PrivateEndpointConnectionsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SignalRClient.PrivateEndpointConnectionsUpdate` + +```go +ctx := context.TODO() +id := signalr.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "privateEndpointConnectionValue") + +payload := signalr.PrivateEndpointConnection{ + // ... +} + + +read, err := client.PrivateEndpointConnectionsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.PrivateLinkResourcesList` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +// alternatively `client.PrivateLinkResourcesList(ctx, id)` can be used to do batched pagination +items, err := client.PrivateLinkResourcesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SignalRClient.RegenerateKey` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +payload := signalr.RegenerateKeyParameters{ + // ... +} + + +if err := client.RegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.Restart` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +if err := client.RestartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.SharedPrivateLinkResourcesCreateOrUpdate` + +```go +ctx := context.TODO() +id := signalr.NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "sharedPrivateLinkResourceValue") + +payload := signalr.SharedPrivateLinkResource{ + // ... +} + + +if err := client.SharedPrivateLinkResourcesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.SharedPrivateLinkResourcesDelete` + +```go +ctx := context.TODO() +id := signalr.NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "sharedPrivateLinkResourceValue") + +if err := client.SharedPrivateLinkResourcesDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.SharedPrivateLinkResourcesGet` + +```go +ctx := context.TODO() +id := signalr.NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "sharedPrivateLinkResourceValue") + +read, err := client.SharedPrivateLinkResourcesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignalRClient.SharedPrivateLinkResourcesList` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +// alternatively `client.SharedPrivateLinkResourcesList(ctx, id)` can be used to do batched pagination +items, err := client.SharedPrivateLinkResourcesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SignalRClient.Update` + +```go +ctx := context.TODO() +id := signalr.NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + +payload := signalr.SignalRResource{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SignalRClient.UsagesList` + +```go +ctx := context.TODO() +id := signalr.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.UsagesList(ctx, id)` can be used to do batched pagination +items, err := client.UsagesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/signalr/2023-02-01/signalr/client.go b/resource-manager/signalr/2023-02-01/signalr/client.go new file mode 100644 index 00000000000..509f41249f3 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/client.go @@ -0,0 +1,26 @@ +package signalr + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "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 SignalRClient struct { + Client *resourcemanager.Client +} + +func NewSignalRClientWithBaseURI(api environments.Api) (*SignalRClient, error) { + client, err := resourcemanager.NewResourceManagerClient(api, "signalr", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SignalRClient: %+v", err) + } + + return &SignalRClient{ + Client: client, + }, nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/constants.go b/resource-manager/signalr/2023-02-01/signalr/constants.go new file mode 100644 index 00000000000..1319917bb21 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/constants.go @@ -0,0 +1,374 @@ +package signalr + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ACLAction string + +const ( + ACLActionAllow ACLAction = "Allow" + ACLActionDeny ACLAction = "Deny" +) + +func PossibleValuesForACLAction() []string { + return []string{ + string(ACLActionAllow), + string(ACLActionDeny), + } +} + +func parseACLAction(input string) (*ACLAction, error) { + vals := map[string]ACLAction{ + "allow": ACLActionAllow, + "deny": ACLActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ACLAction(input) + return &out, nil +} + +type FeatureFlags string + +const ( + FeatureFlagsEnableConnectivityLogs FeatureFlags = "EnableConnectivityLogs" + FeatureFlagsEnableLiveTrace FeatureFlags = "EnableLiveTrace" + FeatureFlagsEnableMessagingLogs FeatureFlags = "EnableMessagingLogs" + FeatureFlagsServiceMode FeatureFlags = "ServiceMode" +) + +func PossibleValuesForFeatureFlags() []string { + return []string{ + string(FeatureFlagsEnableConnectivityLogs), + string(FeatureFlagsEnableLiveTrace), + string(FeatureFlagsEnableMessagingLogs), + string(FeatureFlagsServiceMode), + } +} + +func parseFeatureFlags(input string) (*FeatureFlags, error) { + vals := map[string]FeatureFlags{ + "enableconnectivitylogs": FeatureFlagsEnableConnectivityLogs, + "enablelivetrace": FeatureFlagsEnableLiveTrace, + "enablemessaginglogs": FeatureFlagsEnableMessagingLogs, + "servicemode": FeatureFlagsServiceMode, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FeatureFlags(input) + return &out, nil +} + +type KeyType string + +const ( + KeyTypePrimary KeyType = "Primary" + KeyTypeSalt KeyType = "Salt" + KeyTypeSecondary KeyType = "Secondary" +) + +func PossibleValuesForKeyType() []string { + return []string{ + string(KeyTypePrimary), + string(KeyTypeSalt), + string(KeyTypeSecondary), + } +} + +func parseKeyType(input string) (*KeyType, error) { + vals := map[string]KeyType{ + "primary": KeyTypePrimary, + "salt": KeyTypeSalt, + "secondary": KeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyType(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStatus string + +const ( + PrivateLinkServiceConnectionStatusApproved PrivateLinkServiceConnectionStatus = "Approved" + PrivateLinkServiceConnectionStatusDisconnected PrivateLinkServiceConnectionStatus = "Disconnected" + PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" + PrivateLinkServiceConnectionStatusRejected PrivateLinkServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStatusApproved), + string(PrivateLinkServiceConnectionStatusDisconnected), + string(PrivateLinkServiceConnectionStatusPending), + string(PrivateLinkServiceConnectionStatusRejected), + } +} + +func parsePrivateLinkServiceConnectionStatus(input string) (*PrivateLinkServiceConnectionStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStatus{ + "approved": PrivateLinkServiceConnectionStatusApproved, + "disconnected": PrivateLinkServiceConnectionStatusDisconnected, + "pending": PrivateLinkServiceConnectionStatusPending, + "rejected": PrivateLinkServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMoving ProvisioningState = "Moving" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUnknown ProvisioningState = "Unknown" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMoving), + string(ProvisioningStateRunning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUnknown), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "moving": ProvisioningStateMoving, + "running": ProvisioningStateRunning, + "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 ScaleType string + +const ( + ScaleTypeAutomatic ScaleType = "Automatic" + ScaleTypeManual ScaleType = "Manual" + ScaleTypeNone ScaleType = "None" +) + +func PossibleValuesForScaleType() []string { + return []string{ + string(ScaleTypeAutomatic), + string(ScaleTypeManual), + string(ScaleTypeNone), + } +} + +func parseScaleType(input string) (*ScaleType, error) { + vals := map[string]ScaleType{ + "automatic": ScaleTypeAutomatic, + "manual": ScaleTypeManual, + "none": ScaleTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScaleType(input) + return &out, nil +} + +type ServiceKind string + +const ( + ServiceKindRawWebSockets ServiceKind = "RawWebSockets" + ServiceKindSignalR ServiceKind = "SignalR" +) + +func PossibleValuesForServiceKind() []string { + return []string{ + string(ServiceKindRawWebSockets), + string(ServiceKindSignalR), + } +} + +func parseServiceKind(input string) (*ServiceKind, error) { + vals := map[string]ServiceKind{ + "rawwebsockets": ServiceKindRawWebSockets, + "signalr": ServiceKindSignalR, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServiceKind(input) + return &out, nil +} + +type SharedPrivateLinkResourceStatus string + +const ( + SharedPrivateLinkResourceStatusApproved SharedPrivateLinkResourceStatus = "Approved" + SharedPrivateLinkResourceStatusDisconnected SharedPrivateLinkResourceStatus = "Disconnected" + SharedPrivateLinkResourceStatusPending SharedPrivateLinkResourceStatus = "Pending" + SharedPrivateLinkResourceStatusRejected SharedPrivateLinkResourceStatus = "Rejected" + SharedPrivateLinkResourceStatusTimeout SharedPrivateLinkResourceStatus = "Timeout" +) + +func PossibleValuesForSharedPrivateLinkResourceStatus() []string { + return []string{ + string(SharedPrivateLinkResourceStatusApproved), + string(SharedPrivateLinkResourceStatusDisconnected), + string(SharedPrivateLinkResourceStatusPending), + string(SharedPrivateLinkResourceStatusRejected), + string(SharedPrivateLinkResourceStatusTimeout), + } +} + +func parseSharedPrivateLinkResourceStatus(input string) (*SharedPrivateLinkResourceStatus, error) { + vals := map[string]SharedPrivateLinkResourceStatus{ + "approved": SharedPrivateLinkResourceStatusApproved, + "disconnected": SharedPrivateLinkResourceStatusDisconnected, + "pending": SharedPrivateLinkResourceStatusPending, + "rejected": SharedPrivateLinkResourceStatusRejected, + "timeout": SharedPrivateLinkResourceStatusTimeout, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SharedPrivateLinkResourceStatus(input) + return &out, nil +} + +type SignalRRequestType string + +const ( + SignalRRequestTypeClientConnection SignalRRequestType = "ClientConnection" + SignalRRequestTypeRESTAPI SignalRRequestType = "RESTAPI" + SignalRRequestTypeServerConnection SignalRRequestType = "ServerConnection" + SignalRRequestTypeTrace SignalRRequestType = "Trace" +) + +func PossibleValuesForSignalRRequestType() []string { + return []string{ + string(SignalRRequestTypeClientConnection), + string(SignalRRequestTypeRESTAPI), + string(SignalRRequestTypeServerConnection), + string(SignalRRequestTypeTrace), + } +} + +func parseSignalRRequestType(input string) (*SignalRRequestType, error) { + vals := map[string]SignalRRequestType{ + "clientconnection": SignalRRequestTypeClientConnection, + "restapi": SignalRRequestTypeRESTAPI, + "serverconnection": SignalRRequestTypeServerConnection, + "trace": SignalRRequestTypeTrace, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SignalRRequestType(input) + return &out, nil +} + +type SignalRSkuTier string + +const ( + SignalRSkuTierBasic SignalRSkuTier = "Basic" + SignalRSkuTierFree SignalRSkuTier = "Free" + SignalRSkuTierPremium SignalRSkuTier = "Premium" + SignalRSkuTierStandard SignalRSkuTier = "Standard" +) + +func PossibleValuesForSignalRSkuTier() []string { + return []string{ + string(SignalRSkuTierBasic), + string(SignalRSkuTierFree), + string(SignalRSkuTierPremium), + string(SignalRSkuTierStandard), + } +} + +func parseSignalRSkuTier(input string) (*SignalRSkuTier, error) { + vals := map[string]SignalRSkuTier{ + "basic": SignalRSkuTierBasic, + "free": SignalRSkuTierFree, + "premium": SignalRSkuTierPremium, + "standard": SignalRSkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SignalRSkuTier(input) + return &out, nil +} + +type UpstreamAuthType string + +const ( + UpstreamAuthTypeManagedIdentity UpstreamAuthType = "ManagedIdentity" + UpstreamAuthTypeNone UpstreamAuthType = "None" +) + +func PossibleValuesForUpstreamAuthType() []string { + return []string{ + string(UpstreamAuthTypeManagedIdentity), + string(UpstreamAuthTypeNone), + } +} + +func parseUpstreamAuthType(input string) (*UpstreamAuthType, error) { + vals := map[string]UpstreamAuthType{ + "managedidentity": UpstreamAuthTypeManagedIdentity, + "none": UpstreamAuthTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpstreamAuthType(input) + return &out, nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/id_customcertificate.go b/resource-manager/signalr/2023-02-01/signalr/id_customcertificate.go new file mode 100644 index 00000000000..67788c9ffe6 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_customcertificate.go @@ -0,0 +1,140 @@ +package signalr + +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 = CustomCertificateId{} + +// CustomCertificateId is a struct representing the Resource ID for a Custom Certificate +type CustomCertificateId struct { + SubscriptionId string + ResourceGroupName string + SignalRName string + CustomCertificateName string +} + +// NewCustomCertificateID returns a new CustomCertificateId struct +func NewCustomCertificateID(subscriptionId string, resourceGroupName string, signalRName string, customCertificateName string) CustomCertificateId { + return CustomCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SignalRName: signalRName, + CustomCertificateName: customCertificateName, + } +} + +// ParseCustomCertificateID parses 'input' into a CustomCertificateId +func ParseCustomCertificateID(input string) (*CustomCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomCertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.CustomCertificateName, ok = parsed.Parsed["customCertificateName"]; !ok { + return nil, fmt.Errorf("the segment 'customCertificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCustomCertificateIDInsensitively parses 'input' case-insensitively into a CustomCertificateId +// note: this method should only be used for API response data and not user input +func ParseCustomCertificateIDInsensitively(input string) (*CustomCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomCertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.CustomCertificateName, ok = parsed.Parsed["customCertificateName"]; !ok { + return nil, fmt.Errorf("the segment 'customCertificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCustomCertificateID checks that 'input' can be parsed as a Custom Certificate ID +func ValidateCustomCertificateID(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 := ParseCustomCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Custom Certificate ID +func (id CustomCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/signalR/%s/customCertificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SignalRName, id.CustomCertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Custom Certificate ID +func (id CustomCertificateId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticSignalR", "signalR", "signalR"), + resourceids.UserSpecifiedSegment("signalRName", "signalRValue"), + resourceids.StaticSegment("staticCustomCertificates", "customCertificates", "customCertificates"), + resourceids.UserSpecifiedSegment("customCertificateName", "customCertificateValue"), + } +} + +// String returns a human-readable description of this Custom Certificate ID +func (id CustomCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Signal R Name: %q", id.SignalRName), + fmt.Sprintf("Custom Certificate Name: %q", id.CustomCertificateName), + } + return fmt.Sprintf("Custom Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/signalr/2023-02-01/signalr/id_customcertificate_test.go b/resource-manager/signalr/2023-02-01/signalr/id_customcertificate_test.go new file mode 100644 index 00000000000..0f61c83ad38 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_customcertificate_test.go @@ -0,0 +1,327 @@ +package signalr + +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 = CustomCertificateId{} + +func TestNewCustomCertificateID(t *testing.T) { + id := NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customCertificateValue") + + 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.SignalRName != "signalRValue" { + t.Fatalf("Expected %q but got %q for Segment 'SignalRName'", id.SignalRName, "signalRValue") + } + + if id.CustomCertificateName != "customCertificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CustomCertificateName'", id.CustomCertificateName, "customCertificateValue") + } +} + +func TestFormatCustomCertificateID(t *testing.T) { + actual := NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customCertificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customCertificates/customCertificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCustomCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomCertificateId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customCertificates/customCertificateValue", + Expected: &CustomCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + CustomCertificateName: "customCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customCertificates/customCertificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomCertificateID(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.CustomCertificateName != v.Expected.CustomCertificateName { + t.Fatalf("Expected %q but got %q for CustomCertificateName", v.Expected.CustomCertificateName, actual.CustomCertificateName) + } + + } +} + +func TestParseCustomCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomCertificateId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customCertificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/cUsToMcErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customCertificates/customCertificateValue", + Expected: &CustomCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + CustomCertificateName: "customCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customCertificates/customCertificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/cUsToMcErTiFiCaTeS/cUsToMcErTiFiCaTeVaLuE", + Expected: &CustomCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SignalRName: "sIgNaLrVaLuE", + CustomCertificateName: "cUsToMcErTiFiCaTeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/cUsToMcErTiFiCaTeS/cUsToMcErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomCertificateIDInsensitively(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.CustomCertificateName != v.Expected.CustomCertificateName { + t.Fatalf("Expected %q but got %q for CustomCertificateName", v.Expected.CustomCertificateName, actual.CustomCertificateName) + } + + } +} + +func TestSegmentsForCustomCertificateId(t *testing.T) { + segments := CustomCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CustomCertificateId 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/signalr/2023-02-01/signalr/id_customdomain.go b/resource-manager/signalr/2023-02-01/signalr/id_customdomain.go new file mode 100644 index 00000000000..f4d13f4f6b4 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_customdomain.go @@ -0,0 +1,140 @@ +package signalr + +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 = CustomDomainId{} + +// CustomDomainId is a struct representing the Resource ID for a Custom Domain +type CustomDomainId struct { + SubscriptionId string + ResourceGroupName string + SignalRName string + CustomDomainName string +} + +// NewCustomDomainID returns a new CustomDomainId struct +func NewCustomDomainID(subscriptionId string, resourceGroupName string, signalRName string, customDomainName string) CustomDomainId { + return CustomDomainId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SignalRName: signalRName, + CustomDomainName: customDomainName, + } +} + +// ParseCustomDomainID parses 'input' into a CustomDomainId +func ParseCustomDomainID(input string) (*CustomDomainId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomDomainId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomDomainId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.CustomDomainName, ok = parsed.Parsed["customDomainName"]; !ok { + return nil, fmt.Errorf("the segment 'customDomainName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCustomDomainIDInsensitively parses 'input' case-insensitively into a CustomDomainId +// note: this method should only be used for API response data and not user input +func ParseCustomDomainIDInsensitively(input string) (*CustomDomainId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomDomainId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomDomainId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.CustomDomainName, ok = parsed.Parsed["customDomainName"]; !ok { + return nil, fmt.Errorf("the segment 'customDomainName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCustomDomainID checks that 'input' can be parsed as a Custom Domain ID +func ValidateCustomDomainID(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 := ParseCustomDomainID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Custom Domain ID +func (id CustomDomainId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/signalR/%s/customDomains/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SignalRName, id.CustomDomainName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Custom Domain ID +func (id CustomDomainId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticSignalR", "signalR", "signalR"), + resourceids.UserSpecifiedSegment("signalRName", "signalRValue"), + resourceids.StaticSegment("staticCustomDomains", "customDomains", "customDomains"), + resourceids.UserSpecifiedSegment("customDomainName", "customDomainValue"), + } +} + +// String returns a human-readable description of this Custom Domain ID +func (id CustomDomainId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Signal R Name: %q", id.SignalRName), + fmt.Sprintf("Custom Domain Name: %q", id.CustomDomainName), + } + return fmt.Sprintf("Custom Domain (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/signalr/2023-02-01/signalr/id_customdomain_test.go b/resource-manager/signalr/2023-02-01/signalr/id_customdomain_test.go new file mode 100644 index 00000000000..d43fef04afb --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_customdomain_test.go @@ -0,0 +1,327 @@ +package signalr + +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 = CustomDomainId{} + +func TestNewCustomDomainID(t *testing.T) { + id := NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customDomainValue") + + 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.SignalRName != "signalRValue" { + t.Fatalf("Expected %q but got %q for Segment 'SignalRName'", id.SignalRName, "signalRValue") + } + + if id.CustomDomainName != "customDomainValue" { + t.Fatalf("Expected %q but got %q for Segment 'CustomDomainName'", id.CustomDomainName, "customDomainValue") + } +} + +func TestFormatCustomDomainID(t *testing.T) { + actual := NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "customDomainValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customDomains/customDomainValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCustomDomainID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomDomainId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customDomains", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customDomains/customDomainValue", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customDomains/customDomainValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomDomainID(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.CustomDomainName != v.Expected.CustomDomainName { + t.Fatalf("Expected %q but got %q for CustomDomainName", v.Expected.CustomDomainName, actual.CustomDomainName) + } + + } +} + +func TestParseCustomDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomDomainId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customDomains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/cUsToMdOmAiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customDomains/customDomainValue", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/customDomains/customDomainValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/cUsToMdOmAiNs/cUsToMdOmAiNvAlUe", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SignalRName: "sIgNaLrVaLuE", + CustomDomainName: "cUsToMdOmAiNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/cUsToMdOmAiNs/cUsToMdOmAiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomDomainIDInsensitively(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.CustomDomainName != v.Expected.CustomDomainName { + t.Fatalf("Expected %q but got %q for CustomDomainName", v.Expected.CustomDomainName, actual.CustomDomainName) + } + + } +} + +func TestSegmentsForCustomDomainId(t *testing.T) { + segments := CustomDomainId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CustomDomainId 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/signalr/2023-02-01/signalr/id_location.go b/resource-manager/signalr/2023-02-01/signalr/id_location.go new file mode 100644 index 00000000000..84247bfb615 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_location.go @@ -0,0 +1,114 @@ +package signalr + +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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, 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.SignalRService/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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + 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/signalr/2023-02-01/signalr/id_location_test.go b/resource-manager/signalr/2023-02-01/signalr/id_location_test.go new file mode 100644 index 00000000000..8e9a896ac52 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_location_test.go @@ -0,0 +1,237 @@ +package signalr + +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.SignalRService/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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "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.sIgNaLrSeRvIcE/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/signalr/2023-02-01/signalr/id_privateendpointconnection.go b/resource-manager/signalr/2023-02-01/signalr/id_privateendpointconnection.go new file mode 100644 index 00000000000..876e9ce998d --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_privateendpointconnection.go @@ -0,0 +1,140 @@ +package signalr + +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 = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + SignalRName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, signalRName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SignalRName: signalRName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/signalR/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SignalRName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticSignalR", "signalR", "signalR"), + resourceids.UserSpecifiedSegment("signalRName", "signalRValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Signal R Name: %q", id.SignalRName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/signalr/2023-02-01/signalr/id_privateendpointconnection_test.go b/resource-manager/signalr/2023-02-01/signalr/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..b6a6a4d3b53 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package signalr + +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 = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SignalRName != "signalRValue" { + t.Fatalf("Expected %q but got %q for Segment 'SignalRName'", id.SignalRName, "signalRValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SignalRName: "sIgNaLrVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/signalr/2023-02-01/signalr/id_sharedprivatelinkresource.go b/resource-manager/signalr/2023-02-01/signalr/id_sharedprivatelinkresource.go new file mode 100644 index 00000000000..48ceb149494 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_sharedprivatelinkresource.go @@ -0,0 +1,140 @@ +package signalr + +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 = SharedPrivateLinkResourceId{} + +// SharedPrivateLinkResourceId is a struct representing the Resource ID for a Shared Private Link Resource +type SharedPrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + SignalRName string + SharedPrivateLinkResourceName string +} + +// NewSharedPrivateLinkResourceID returns a new SharedPrivateLinkResourceId struct +func NewSharedPrivateLinkResourceID(subscriptionId string, resourceGroupName string, signalRName string, sharedPrivateLinkResourceName string) SharedPrivateLinkResourceId { + return SharedPrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SignalRName: signalRName, + SharedPrivateLinkResourceName: sharedPrivateLinkResourceName, + } +} + +// ParseSharedPrivateLinkResourceID parses 'input' into a SharedPrivateLinkResourceId +func ParseSharedPrivateLinkResourceID(input string) (*SharedPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(SharedPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SharedPrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.SharedPrivateLinkResourceName, ok = parsed.Parsed["sharedPrivateLinkResourceName"]; !ok { + return nil, fmt.Errorf("the segment 'sharedPrivateLinkResourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSharedPrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a SharedPrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParseSharedPrivateLinkResourceIDInsensitively(input string) (*SharedPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(SharedPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SharedPrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + if id.SharedPrivateLinkResourceName, ok = parsed.Parsed["sharedPrivateLinkResourceName"]; !ok { + return nil, fmt.Errorf("the segment 'sharedPrivateLinkResourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSharedPrivateLinkResourceID checks that 'input' can be parsed as a Shared Private Link Resource ID +func ValidateSharedPrivateLinkResourceID(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 := ParseSharedPrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Shared Private Link Resource ID +func (id SharedPrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/signalR/%s/sharedPrivateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SignalRName, id.SharedPrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Shared Private Link Resource ID +func (id SharedPrivateLinkResourceId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticSignalR", "signalR", "signalR"), + resourceids.UserSpecifiedSegment("signalRName", "signalRValue"), + resourceids.StaticSegment("staticSharedPrivateLinkResources", "sharedPrivateLinkResources", "sharedPrivateLinkResources"), + resourceids.UserSpecifiedSegment("sharedPrivateLinkResourceName", "sharedPrivateLinkResourceValue"), + } +} + +// String returns a human-readable description of this Shared Private Link Resource ID +func (id SharedPrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Signal R Name: %q", id.SignalRName), + fmt.Sprintf("Shared Private Link Resource Name: %q", id.SharedPrivateLinkResourceName), + } + return fmt.Sprintf("Shared Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/signalr/2023-02-01/signalr/id_sharedprivatelinkresource_test.go b/resource-manager/signalr/2023-02-01/signalr/id_sharedprivatelinkresource_test.go new file mode 100644 index 00000000000..60b9034b105 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_sharedprivatelinkresource_test.go @@ -0,0 +1,327 @@ +package signalr + +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 = SharedPrivateLinkResourceId{} + +func TestNewSharedPrivateLinkResourceID(t *testing.T) { + id := NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "sharedPrivateLinkResourceValue") + + 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.SignalRName != "signalRValue" { + t.Fatalf("Expected %q but got %q for Segment 'SignalRName'", id.SignalRName, "signalRValue") + } + + if id.SharedPrivateLinkResourceName != "sharedPrivateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'SharedPrivateLinkResourceName'", id.SharedPrivateLinkResourceName, "sharedPrivateLinkResourceValue") + } +} + +func TestFormatSharedPrivateLinkResourceID(t *testing.T) { + actual := NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue", "sharedPrivateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSharedPrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SharedPrivateLinkResourceId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/sharedPrivateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue", + Expected: &SharedPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + SharedPrivateLinkResourceName: "sharedPrivateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSharedPrivateLinkResourceID(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.SharedPrivateLinkResourceName != v.Expected.SharedPrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for SharedPrivateLinkResourceName", v.Expected.SharedPrivateLinkResourceName, actual.SharedPrivateLinkResourceName) + } + + } +} + +func TestParseSharedPrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SharedPrivateLinkResourceId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/sharedPrivateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/sHaReDpRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue", + Expected: &SharedPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + SharedPrivateLinkResourceName: "sharedPrivateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/sHaReDpRiVaTeLiNkReSoUrCeS/sHaReDpRiVaTeLiNkReSoUrCeVaLuE", + Expected: &SharedPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SignalRName: "sIgNaLrVaLuE", + SharedPrivateLinkResourceName: "sHaReDpRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/sHaReDpRiVaTeLiNkReSoUrCeS/sHaReDpRiVaTeLiNkReSoUrCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSharedPrivateLinkResourceIDInsensitively(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + if actual.SharedPrivateLinkResourceName != v.Expected.SharedPrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for SharedPrivateLinkResourceName", v.Expected.SharedPrivateLinkResourceName, actual.SharedPrivateLinkResourceName) + } + + } +} + +func TestSegmentsForSharedPrivateLinkResourceId(t *testing.T) { + segments := SharedPrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SharedPrivateLinkResourceId 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/signalr/2023-02-01/signalr/id_signalr.go b/resource-manager/signalr/2023-02-01/signalr/id_signalr.go new file mode 100644 index 00000000000..eeacf19e7c8 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_signalr.go @@ -0,0 +1,127 @@ +package signalr + +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 = SignalRId{} + +// SignalRId is a struct representing the Resource ID for a Signal R +type SignalRId struct { + SubscriptionId string + ResourceGroupName string + SignalRName string +} + +// NewSignalRID returns a new SignalRId struct +func NewSignalRID(subscriptionId string, resourceGroupName string, signalRName string) SignalRId { + return SignalRId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SignalRName: signalRName, + } +} + +// ParseSignalRID parses 'input' into a SignalRId +func ParseSignalRID(input string) (*SignalRId, error) { + parser := resourceids.NewParserFromResourceIdType(SignalRId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SignalRId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSignalRIDInsensitively parses 'input' case-insensitively into a SignalRId +// note: this method should only be used for API response data and not user input +func ParseSignalRIDInsensitively(input string) (*SignalRId, error) { + parser := resourceids.NewParserFromResourceIdType(SignalRId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SignalRId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.SignalRName, ok = parsed.Parsed["signalRName"]; !ok { + return nil, fmt.Errorf("the segment 'signalRName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSignalRID checks that 'input' can be parsed as a Signal R ID +func ValidateSignalRID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSignalRID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Signal R ID +func (id SignalRId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/signalR/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SignalRName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Signal R ID +func (id SignalRId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticSignalR", "signalR", "signalR"), + resourceids.UserSpecifiedSegment("signalRName", "signalRValue"), + } +} + +// String returns a human-readable description of this Signal R ID +func (id SignalRId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Signal R Name: %q", id.SignalRName), + } + return fmt.Sprintf("Signal R (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/signalr/2023-02-01/signalr/id_signalr_test.go b/resource-manager/signalr/2023-02-01/signalr/id_signalr_test.go new file mode 100644 index 00000000000..fd5f6f74aaa --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/id_signalr_test.go @@ -0,0 +1,282 @@ +package signalr + +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 = SignalRId{} + +func TestNewSignalRID(t *testing.T) { + id := NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue") + + 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.SignalRName != "signalRValue" { + t.Fatalf("Expected %q but got %q for Segment 'SignalRName'", id.SignalRName, "signalRValue") + } +} + +func TestFormatSignalRID(t *testing.T) { + actual := NewSignalRID("12345678-1234-9876-4563-123456789012", "example-resource-group", "signalRValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSignalRID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SignalRId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Expected: &SignalRId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSignalRID(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + } +} + +func TestParseSignalRIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SignalRId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue", + Expected: &SignalRId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SignalRName: "signalRValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/signalR/signalRValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE", + Expected: &SignalRId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SignalRName: "sIgNaLrVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/sIgNaLr/sIgNaLrVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSignalRIDInsensitively(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.SignalRName != v.Expected.SignalRName { + t.Fatalf("Expected %q but got %q for SignalRName", v.Expected.SignalRName, actual.SignalRName) + } + + } +} + +func TestSegmentsForSignalRId(t *testing.T) { + segments := SignalRId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SignalRId 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/signalr/2023-02-01/signalr/method_checknameavailability.go b/resource-manager/signalr/2023-02-01/signalr/method_checknameavailability.go new file mode 100644 index 00000000000..21c3b4199a9 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_checknameavailability.go @@ -0,0 +1,56 @@ +package signalr + +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 *NameAvailability +} + +// CheckNameAvailability ... +func (c SignalRClient) CheckNameAvailability(ctx context.Context, id LocationId, input NameAvailabilityParameters) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_createorupdate.go b/resource-manager/signalr/2023-02-01/signalr/method_createorupdate.go new file mode 100644 index 00000000000..053157d2bf5 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_createorupdate.go @@ -0,0 +1,75 @@ +package signalr + +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 SignalRClient) CreateOrUpdate(ctx context.Context, id SignalRId, input SignalRResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 SignalRClient) CreateOrUpdateThenPoll(ctx context.Context, id SignalRId, input SignalRResource) 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/signalr/2023-02-01/signalr/method_customcertificatescreateorupdate.go b/resource-manager/signalr/2023-02-01/signalr/method_customcertificatescreateorupdate.go new file mode 100644 index 00000000000..fa1112341dd --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customcertificatescreateorupdate.go @@ -0,0 +1,74 @@ +package signalr + +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 CustomCertificatesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CustomCertificatesCreateOrUpdate ... +func (c SignalRClient) CustomCertificatesCreateOrUpdate(ctx context.Context, id CustomCertificateId, input CustomCertificate) (result CustomCertificatesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 +} + +// CustomCertificatesCreateOrUpdateThenPoll performs CustomCertificatesCreateOrUpdate then polls until it's completed +func (c SignalRClient) CustomCertificatesCreateOrUpdateThenPoll(ctx context.Context, id CustomCertificateId, input CustomCertificate) error { + result, err := c.CustomCertificatesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CustomCertificatesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CustomCertificatesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_customcertificatesdelete.go b/resource-manager/signalr/2023-02-01/signalr/method_customcertificatesdelete.go new file mode 100644 index 00000000000..d7ed7b35034 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customcertificatesdelete.go @@ -0,0 +1,47 @@ +package signalr + +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 CustomCertificatesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CustomCertificatesDelete ... +func (c SignalRClient) CustomCertificatesDelete(ctx context.Context, id CustomCertificateId) (result CustomCertificatesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_customcertificatesget.go b/resource-manager/signalr/2023-02-01/signalr/method_customcertificatesget.go new file mode 100644 index 00000000000..030369210d0 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customcertificatesget.go @@ -0,0 +1,51 @@ +package signalr + +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 CustomCertificatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CustomCertificate +} + +// CustomCertificatesGet ... +func (c SignalRClient) CustomCertificatesGet(ctx context.Context, id CustomCertificateId) (result CustomCertificatesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_customcertificateslist.go b/resource-manager/signalr/2023-02-01/signalr/method_customcertificateslist.go new file mode 100644 index 00000000000..5e8e83c4528 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customcertificateslist.go @@ -0,0 +1,89 @@ +package signalr + +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 CustomCertificatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CustomCertificate +} + +type CustomCertificatesListCompleteResult struct { + Items []CustomCertificate +} + +// CustomCertificatesList ... +func (c SignalRClient) CustomCertificatesList(ctx context.Context, id SignalRId) (result CustomCertificatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/customCertificates", 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 *[]CustomCertificate `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CustomCertificatesListComplete retrieves all the results into a single object +func (c SignalRClient) CustomCertificatesListComplete(ctx context.Context, id SignalRId) (CustomCertificatesListCompleteResult, error) { + return c.CustomCertificatesListCompleteMatchingPredicate(ctx, id, CustomCertificateOperationPredicate{}) +} + +// CustomCertificatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) CustomCertificatesListCompleteMatchingPredicate(ctx context.Context, id SignalRId, predicate CustomCertificateOperationPredicate) (result CustomCertificatesListCompleteResult, err error) { + items := make([]CustomCertificate, 0) + + resp, err := c.CustomCertificatesList(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 = CustomCertificatesListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_customdomainscreateorupdate.go b/resource-manager/signalr/2023-02-01/signalr/method_customdomainscreateorupdate.go new file mode 100644 index 00000000000..151aa1a06e3 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customdomainscreateorupdate.go @@ -0,0 +1,73 @@ +package signalr + +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 CustomDomainsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CustomDomainsCreateOrUpdate ... +func (c SignalRClient) CustomDomainsCreateOrUpdate(ctx context.Context, id CustomDomainId, input CustomDomain) (result CustomDomainsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 +} + +// CustomDomainsCreateOrUpdateThenPoll performs CustomDomainsCreateOrUpdate then polls until it's completed +func (c SignalRClient) CustomDomainsCreateOrUpdateThenPoll(ctx context.Context, id CustomDomainId, input CustomDomain) error { + result, err := c.CustomDomainsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CustomDomainsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CustomDomainsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_customdomainsdelete.go b/resource-manager/signalr/2023-02-01/signalr/method_customdomainsdelete.go new file mode 100644 index 00000000000..58606cc46e7 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customdomainsdelete.go @@ -0,0 +1,71 @@ +package signalr + +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 CustomDomainsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CustomDomainsDelete ... +func (c SignalRClient) CustomDomainsDelete(ctx context.Context, id CustomDomainId) (result CustomDomainsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 +} + +// CustomDomainsDeleteThenPoll performs CustomDomainsDelete then polls until it's completed +func (c SignalRClient) CustomDomainsDeleteThenPoll(ctx context.Context, id CustomDomainId) error { + result, err := c.CustomDomainsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing CustomDomainsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CustomDomainsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_customdomainsget.go b/resource-manager/signalr/2023-02-01/signalr/method_customdomainsget.go new file mode 100644 index 00000000000..666e5d1962f --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customdomainsget.go @@ -0,0 +1,51 @@ +package signalr + +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 CustomDomainsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CustomDomain +} + +// CustomDomainsGet ... +func (c SignalRClient) CustomDomainsGet(ctx context.Context, id CustomDomainId) (result CustomDomainsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_customdomainslist.go b/resource-manager/signalr/2023-02-01/signalr/method_customdomainslist.go new file mode 100644 index 00000000000..4ee0e015209 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_customdomainslist.go @@ -0,0 +1,89 @@ +package signalr + +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 CustomDomainsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CustomDomain +} + +type CustomDomainsListCompleteResult struct { + Items []CustomDomain +} + +// CustomDomainsList ... +func (c SignalRClient) CustomDomainsList(ctx context.Context, id SignalRId) (result CustomDomainsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/customDomains", 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 *[]CustomDomain `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CustomDomainsListComplete retrieves all the results into a single object +func (c SignalRClient) CustomDomainsListComplete(ctx context.Context, id SignalRId) (CustomDomainsListCompleteResult, error) { + return c.CustomDomainsListCompleteMatchingPredicate(ctx, id, CustomDomainOperationPredicate{}) +} + +// CustomDomainsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) CustomDomainsListCompleteMatchingPredicate(ctx context.Context, id SignalRId, predicate CustomDomainOperationPredicate) (result CustomDomainsListCompleteResult, err error) { + items := make([]CustomDomain, 0) + + resp, err := c.CustomDomainsList(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 = CustomDomainsListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_delete.go b/resource-manager/signalr/2023-02-01/signalr/method_delete.go new file mode 100644 index 00000000000..ede29721bfc --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_delete.go @@ -0,0 +1,71 @@ +package signalr + +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 SignalRClient) Delete(ctx context.Context, id SignalRId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 SignalRClient) DeleteThenPoll(ctx context.Context, id SignalRId) 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/signalr/2023-02-01/signalr/method_get.go b/resource-manager/signalr/2023-02-01/signalr/method_get.go new file mode 100644 index 00000000000..89d906d24da --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_get.go @@ -0,0 +1,51 @@ +package signalr + +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 *SignalRResource +} + +// Get ... +func (c SignalRClient) Get(ctx context.Context, id SignalRId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_listbyresourcegroup.go b/resource-manager/signalr/2023-02-01/signalr/method_listbyresourcegroup.go new file mode 100644 index 00000000000..521ae8d4a9e --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_listbyresourcegroup.go @@ -0,0 +1,90 @@ +package signalr + +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 ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SignalRResource +} + +type ListByResourceGroupCompleteResult struct { + Items []SignalRResource +} + +// ListByResourceGroup ... +func (c SignalRClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SignalRService/signalR", 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 *[]SignalRResource `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c SignalRClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SignalRResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SignalRResourceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]SignalRResource, 0) + + resp, err := c.ListByResourceGroup(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 = ListByResourceGroupCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_listbysubscription.go b/resource-manager/signalr/2023-02-01/signalr/method_listbysubscription.go new file mode 100644 index 00000000000..eeb0fa4330c --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_listbysubscription.go @@ -0,0 +1,90 @@ +package signalr + +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 ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SignalRResource +} + +type ListBySubscriptionCompleteResult struct { + Items []SignalRResource +} + +// ListBySubscription ... +func (c SignalRClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SignalRService/signalR", 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 *[]SignalRResource `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c SignalRClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, SignalRResourceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SignalRResourceOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]SignalRResource, 0) + + resp, err := c.ListBySubscription(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 = ListBySubscriptionCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_listkeys.go b/resource-manager/signalr/2023-02-01/signalr/method_listkeys.go new file mode 100644 index 00000000000..4fe7d4b9662 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_listkeys.go @@ -0,0 +1,52 @@ +package signalr + +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 ListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SignalRKeys +} + +// ListKeys ... +func (c SignalRClient) ListKeys(ctx context.Context, id SignalRId) (result ListKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", 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/signalr/2023-02-01/signalr/method_listskus.go b/resource-manager/signalr/2023-02-01/signalr/method_listskus.go new file mode 100644 index 00000000000..6792a155e0e --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_listskus.go @@ -0,0 +1,52 @@ +package signalr + +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 ListSkusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SkuList +} + +// ListSkus ... +func (c SignalRClient) ListSkus(ctx context.Context, id SignalRId) (result ListSkusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/skus", 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/signalr/2023-02-01/signalr/method_privateendpointconnectionsdelete.go b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsdelete.go new file mode 100644 index 00000000000..fa2434f0fb4 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsdelete.go @@ -0,0 +1,71 @@ +package signalr + +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 PrivateEndpointConnectionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// PrivateEndpointConnectionsDelete ... +func (c SignalRClient) PrivateEndpointConnectionsDelete(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 +} + +// PrivateEndpointConnectionsDeleteThenPoll performs PrivateEndpointConnectionsDelete then polls until it's completed +func (c SignalRClient) PrivateEndpointConnectionsDeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.PrivateEndpointConnectionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing PrivateEndpointConnectionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PrivateEndpointConnectionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsget.go b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsget.go new file mode 100644 index 00000000000..5701c138a42 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsget.go @@ -0,0 +1,51 @@ +package signalr + +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 PrivateEndpointConnectionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// PrivateEndpointConnectionsGet ... +func (c SignalRClient) PrivateEndpointConnectionsGet(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_privateendpointconnectionslist.go b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionslist.go new file mode 100644 index 00000000000..360ea0e9209 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionslist.go @@ -0,0 +1,89 @@ +package signalr + +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 PrivateEndpointConnectionsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type PrivateEndpointConnectionsListCompleteResult struct { + Items []PrivateEndpointConnection +} + +// PrivateEndpointConnectionsList ... +func (c SignalRClient) PrivateEndpointConnectionsList(ctx context.Context, id SignalRId) (result PrivateEndpointConnectionsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", 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 *[]PrivateEndpointConnection `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PrivateEndpointConnectionsListComplete retrieves all the results into a single object +func (c SignalRClient) PrivateEndpointConnectionsListComplete(ctx context.Context, id SignalRId) (PrivateEndpointConnectionsListCompleteResult, error) { + return c.PrivateEndpointConnectionsListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// PrivateEndpointConnectionsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) PrivateEndpointConnectionsListCompleteMatchingPredicate(ctx context.Context, id SignalRId, predicate PrivateEndpointConnectionOperationPredicate) (result PrivateEndpointConnectionsListCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.PrivateEndpointConnectionsList(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 = PrivateEndpointConnectionsListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsupdate.go b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsupdate.go new file mode 100644 index 00000000000..fbb3eb10176 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_privateendpointconnectionsupdate.go @@ -0,0 +1,55 @@ +package signalr + +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 PrivateEndpointConnectionsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// PrivateEndpointConnectionsUpdate ... +func (c SignalRClient) PrivateEndpointConnectionsUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_privatelinkresourceslist.go b/resource-manager/signalr/2023-02-01/signalr/method_privatelinkresourceslist.go new file mode 100644 index 00000000000..d9bf3d3348a --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_privatelinkresourceslist.go @@ -0,0 +1,89 @@ +package signalr + +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 PrivateLinkResourcesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type PrivateLinkResourcesListCompleteResult struct { + Items []PrivateLinkResource +} + +// PrivateLinkResourcesList ... +func (c SignalRClient) PrivateLinkResourcesList(ctx context.Context, id SignalRId) (result PrivateLinkResourcesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", 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 *[]PrivateLinkResource `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PrivateLinkResourcesListComplete retrieves all the results into a single object +func (c SignalRClient) PrivateLinkResourcesListComplete(ctx context.Context, id SignalRId) (PrivateLinkResourcesListCompleteResult, error) { + return c.PrivateLinkResourcesListCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// PrivateLinkResourcesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) PrivateLinkResourcesListCompleteMatchingPredicate(ctx context.Context, id SignalRId, predicate PrivateLinkResourceOperationPredicate) (result PrivateLinkResourcesListCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.PrivateLinkResourcesList(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 = PrivateLinkResourcesListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_regeneratekey.go b/resource-manager/signalr/2023-02-01/signalr/method_regeneratekey.go new file mode 100644 index 00000000000..da5b3ce5c65 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_regeneratekey.go @@ -0,0 +1,73 @@ +package signalr + +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 RegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// RegenerateKey ... +func (c SignalRClient) RegenerateKey(ctx context.Context, id SignalRId, input RegenerateKeyParameters) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", 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 +} + +// RegenerateKeyThenPoll performs RegenerateKey then polls until it's completed +func (c SignalRClient) RegenerateKeyThenPoll(ctx context.Context, id SignalRId, input RegenerateKeyParameters) error { + result, err := c.RegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_restart.go b/resource-manager/signalr/2023-02-01/signalr/method_restart.go new file mode 100644 index 00000000000..86608a56483 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_restart.go @@ -0,0 +1,70 @@ +package signalr + +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 RestartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Restart ... +func (c SignalRClient) Restart(ctx context.Context, id SignalRId) (result RestartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/restart", 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 +} + +// RestartThenPoll performs Restart then polls until it's completed +func (c SignalRClient) RestartThenPoll(ctx context.Context, id SignalRId) error { + result, err := c.Restart(ctx, id) + if err != nil { + return fmt.Errorf("performing Restart: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Restart: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcescreateorupdate.go b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcescreateorupdate.go new file mode 100644 index 00000000000..f1415a6e8f6 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcescreateorupdate.go @@ -0,0 +1,74 @@ +package signalr + +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 SharedPrivateLinkResourcesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SharedPrivateLinkResourcesCreateOrUpdate ... +func (c SignalRClient) SharedPrivateLinkResourcesCreateOrUpdate(ctx context.Context, id SharedPrivateLinkResourceId, input SharedPrivateLinkResource) (result SharedPrivateLinkResourcesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 +} + +// SharedPrivateLinkResourcesCreateOrUpdateThenPoll performs SharedPrivateLinkResourcesCreateOrUpdate then polls until it's completed +func (c SignalRClient) SharedPrivateLinkResourcesCreateOrUpdateThenPoll(ctx context.Context, id SharedPrivateLinkResourceId, input SharedPrivateLinkResource) error { + result, err := c.SharedPrivateLinkResourcesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SharedPrivateLinkResourcesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SharedPrivateLinkResourcesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcesdelete.go b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcesdelete.go new file mode 100644 index 00000000000..b2e174e1be2 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcesdelete.go @@ -0,0 +1,71 @@ +package signalr + +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 SharedPrivateLinkResourcesDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SharedPrivateLinkResourcesDelete ... +func (c SignalRClient) SharedPrivateLinkResourcesDelete(ctx context.Context, id SharedPrivateLinkResourceId) (result SharedPrivateLinkResourcesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 +} + +// SharedPrivateLinkResourcesDeleteThenPoll performs SharedPrivateLinkResourcesDelete then polls until it's completed +func (c SignalRClient) SharedPrivateLinkResourcesDeleteThenPoll(ctx context.Context, id SharedPrivateLinkResourceId) error { + result, err := c.SharedPrivateLinkResourcesDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing SharedPrivateLinkResourcesDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SharedPrivateLinkResourcesDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcesget.go b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcesget.go new file mode 100644 index 00000000000..7c8a7de7abf --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourcesget.go @@ -0,0 +1,51 @@ +package signalr + +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 SharedPrivateLinkResourcesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SharedPrivateLinkResource +} + +// SharedPrivateLinkResourcesGet ... +func (c SignalRClient) SharedPrivateLinkResourcesGet(ctx context.Context, id SharedPrivateLinkResourceId) (result SharedPrivateLinkResourcesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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/signalr/2023-02-01/signalr/method_sharedprivatelinkresourceslist.go b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourceslist.go new file mode 100644 index 00000000000..b1fffdc6af5 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_sharedprivatelinkresourceslist.go @@ -0,0 +1,89 @@ +package signalr + +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 SharedPrivateLinkResourcesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SharedPrivateLinkResource +} + +type SharedPrivateLinkResourcesListCompleteResult struct { + Items []SharedPrivateLinkResource +} + +// SharedPrivateLinkResourcesList ... +func (c SignalRClient) SharedPrivateLinkResourcesList(ctx context.Context, id SignalRId) (result SharedPrivateLinkResourcesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sharedPrivateLinkResources", 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 *[]SharedPrivateLinkResource `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SharedPrivateLinkResourcesListComplete retrieves all the results into a single object +func (c SignalRClient) SharedPrivateLinkResourcesListComplete(ctx context.Context, id SignalRId) (SharedPrivateLinkResourcesListCompleteResult, error) { + return c.SharedPrivateLinkResourcesListCompleteMatchingPredicate(ctx, id, SharedPrivateLinkResourceOperationPredicate{}) +} + +// SharedPrivateLinkResourcesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) SharedPrivateLinkResourcesListCompleteMatchingPredicate(ctx context.Context, id SignalRId, predicate SharedPrivateLinkResourceOperationPredicate) (result SharedPrivateLinkResourcesListCompleteResult, err error) { + items := make([]SharedPrivateLinkResource, 0) + + resp, err := c.SharedPrivateLinkResourcesList(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 = SharedPrivateLinkResourcesListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/method_update.go b/resource-manager/signalr/2023-02-01/signalr/method_update.go new file mode 100644 index 00000000000..5cc1c84877f --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_update.go @@ -0,0 +1,74 @@ +package signalr + +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 SignalRClient) Update(ctx context.Context, id SignalRId, input SignalRResource) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + 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 SignalRClient) UpdateThenPoll(ctx context.Context, id SignalRId, input SignalRResource) 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/signalr/2023-02-01/signalr/method_usageslist.go b/resource-manager/signalr/2023-02-01/signalr/method_usageslist.go new file mode 100644 index 00000000000..a00f30fadf2 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/method_usageslist.go @@ -0,0 +1,89 @@ +package signalr + +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 UsagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SignalRUsage +} + +type UsagesListCompleteResult struct { + Items []SignalRUsage +} + +// UsagesList ... +func (c SignalRClient) UsagesList(ctx context.Context, id LocationId) (result UsagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/usages", 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 *[]SignalRUsage `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// UsagesListComplete retrieves all the results into a single object +func (c SignalRClient) UsagesListComplete(ctx context.Context, id LocationId) (UsagesListCompleteResult, error) { + return c.UsagesListCompleteMatchingPredicate(ctx, id, SignalRUsageOperationPredicate{}) +} + +// UsagesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SignalRClient) UsagesListCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate SignalRUsageOperationPredicate) (result UsagesListCompleteResult, err error) { + items := make([]SignalRUsage, 0) + + resp, err := c.UsagesList(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 = UsagesListCompleteResult{ + Items: items, + } + return +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_customcertificate.go b/resource-manager/signalr/2023-02-01/signalr/model_customcertificate.go new file mode 100644 index 00000000000..d6ff9633aa0 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_customcertificate.go @@ -0,0 +1,16 @@ +package signalr + +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 CustomCertificate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties CustomCertificateProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_customcertificateproperties.go b/resource-manager/signalr/2023-02-01/signalr/model_customcertificateproperties.go new file mode 100644 index 00000000000..95b0e37cbc8 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_customcertificateproperties.go @@ -0,0 +1,11 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificateProperties struct { + KeyVaultBaseUri string `json:"keyVaultBaseUri"` + KeyVaultSecretName string `json:"keyVaultSecretName"` + KeyVaultSecretVersion *string `json:"keyVaultSecretVersion,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_customdomain.go b/resource-manager/signalr/2023-02-01/signalr/model_customdomain.go new file mode 100644 index 00000000000..07cf8a4002e --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_customdomain.go @@ -0,0 +1,16 @@ +package signalr + +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 CustomDomain struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties CustomDomainProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_customdomainproperties.go b/resource-manager/signalr/2023-02-01/signalr/model_customdomainproperties.go new file mode 100644 index 00000000000..c084ddc8155 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_customdomainproperties.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainProperties struct { + CustomCertificate ResourceReference `json:"customCertificate"` + DomainName string `json:"domainName"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_livetracecategory.go b/resource-manager/signalr/2023-02-01/signalr/model_livetracecategory.go new file mode 100644 index 00000000000..eaf0b128ba7 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_livetracecategory.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LiveTraceCategory struct { + Enabled *string `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_livetraceconfiguration.go b/resource-manager/signalr/2023-02-01/signalr/model_livetraceconfiguration.go new file mode 100644 index 00000000000..62766225faf --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_livetraceconfiguration.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LiveTraceConfiguration struct { + Categories *[]LiveTraceCategory `json:"categories,omitempty"` + Enabled *string `json:"enabled,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_managedidentitysettings.go b/resource-manager/signalr/2023-02-01/signalr/model_managedidentitysettings.go new file mode 100644 index 00000000000..05ada7009e8 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_managedidentitysettings.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentitySettings struct { + Resource *string `json:"resource,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_nameavailability.go b/resource-manager/signalr/2023-02-01/signalr/model_nameavailability.go new file mode 100644 index 00000000000..1c5d9874121 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_nameavailability.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameAvailability struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_nameavailabilityparameters.go b/resource-manager/signalr/2023-02-01/signalr/model_nameavailabilityparameters.go new file mode 100644 index 00000000000..e555e38d3e0 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_nameavailabilityparameters.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameAvailabilityParameters struct { + Name string `json:"name"` + Type string `json:"type"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_networkacl.go b/resource-manager/signalr/2023-02-01/signalr/model_networkacl.go new file mode 100644 index 00000000000..4527c32d44e --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_networkacl.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkACL struct { + Allow *[]SignalRRequestType `json:"allow,omitempty"` + Deny *[]SignalRRequestType `json:"deny,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_privateendpoint.go b/resource-manager/signalr/2023-02-01/signalr/model_privateendpoint.go new file mode 100644 index 00000000000..386ec10fcc5 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_privateendpoint.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_privateendpointacl.go b/resource-manager/signalr/2023-02-01/signalr/model_privateendpointacl.go new file mode 100644 index 00000000000..023e23531e9 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_privateendpointacl.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointACL struct { + Allow *[]SignalRRequestType `json:"allow,omitempty"` + Deny *[]SignalRRequestType `json:"deny,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_privateendpointconnection.go b/resource-manager/signalr/2023-02-01/signalr/model_privateendpointconnection.go new file mode 100644 index 00000000000..f82669103c5 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package signalr + +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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_privateendpointconnectionproperties.go b/resource-manager/signalr/2023-02-01/signalr/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..4f579802977 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_privatelinkresource.go b/resource-manager/signalr/2023-02-01/signalr/model_privatelinkresource.go new file mode 100644 index 00000000000..066fc50b9d4 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_privatelinkresourceproperties.go b/resource-manager/signalr/2023-02-01/signalr/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..15661eded28 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_privatelinkresourceproperties.go @@ -0,0 +1,11 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` + ShareablePrivateLinkResourceTypes *[]ShareablePrivateLinkResourceType `json:"shareablePrivateLinkResourceTypes,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_privatelinkserviceconnectionstate.go b/resource-manager/signalr/2023-02-01/signalr/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..943f9ca6832 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateLinkServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_regeneratekeyparameters.go b/resource-manager/signalr/2023-02-01/signalr/model_regeneratekeyparameters.go new file mode 100644 index 00000000000..13b82dd658c --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_regeneratekeyparameters.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyParameters struct { + KeyType *KeyType `json:"keyType,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_resourcelogcategory.go b/resource-manager/signalr/2023-02-01/signalr/model_resourcelogcategory.go new file mode 100644 index 00000000000..d43e44612c0 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_resourcelogcategory.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceLogCategory struct { + Enabled *string `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_resourcelogconfiguration.go b/resource-manager/signalr/2023-02-01/signalr/model_resourcelogconfiguration.go new file mode 100644 index 00000000000..34bfdaaa1e4 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_resourcelogconfiguration.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceLogConfiguration struct { + Categories *[]ResourceLogCategory `json:"categories,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_resourcereference.go b/resource-manager/signalr/2023-02-01/signalr/model_resourcereference.go new file mode 100644 index 00000000000..7a2971d96a8 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_resourcereference.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceReference struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_resourcesku.go b/resource-manager/signalr/2023-02-01/signalr/model_resourcesku.go new file mode 100644 index 00000000000..e05ec7fcdc7 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_resourcesku.go @@ -0,0 +1,12 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SignalRSkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_serverlesssettings.go b/resource-manager/signalr/2023-02-01/signalr/model_serverlesssettings.go new file mode 100644 index 00000000000..0075693e2e5 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_serverlesssettings.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerlessSettings struct { + ConnectionTimeoutInSeconds *int64 `json:"connectionTimeoutInSeconds,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_serverlessupstreamsettings.go b/resource-manager/signalr/2023-02-01/signalr/model_serverlessupstreamsettings.go new file mode 100644 index 00000000000..7248ea8446b --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_serverlessupstreamsettings.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerlessUpstreamSettings struct { + Templates *[]UpstreamTemplate `json:"templates,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_shareableprivatelinkresourceproperties.go b/resource-manager/signalr/2023-02-01/signalr/model_shareableprivatelinkresourceproperties.go new file mode 100644 index 00000000000..acc48625575 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_shareableprivatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShareablePrivateLinkResourceProperties struct { + Description *string `json:"description,omitempty"` + GroupId *string `json:"groupId,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_shareableprivatelinkresourcetype.go b/resource-manager/signalr/2023-02-01/signalr/model_shareableprivatelinkresourcetype.go new file mode 100644 index 00000000000..18407d00fe3 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_shareableprivatelinkresourcetype.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShareablePrivateLinkResourceType struct { + Name *string `json:"name,omitempty"` + Properties *ShareablePrivateLinkResourceProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_sharedprivatelinkresource.go b/resource-manager/signalr/2023-02-01/signalr/model_sharedprivatelinkresource.go new file mode 100644 index 00000000000..6c5aab1998b --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_sharedprivatelinkresource.go @@ -0,0 +1,16 @@ +package signalr + +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 SharedPrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SharedPrivateLinkResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_sharedprivatelinkresourceproperties.go b/resource-manager/signalr/2023-02-01/signalr/model_sharedprivatelinkresourceproperties.go new file mode 100644 index 00000000000..425fbc50526 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_sharedprivatelinkresourceproperties.go @@ -0,0 +1,12 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedPrivateLinkResourceProperties struct { + GroupId string `json:"groupId"` + PrivateLinkResourceId string `json:"privateLinkResourceId"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RequestMessage *string `json:"requestMessage,omitempty"` + Status *SharedPrivateLinkResourceStatus `json:"status,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrcorssettings.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrcorssettings.go new file mode 100644 index 00000000000..aa046d4b367 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrcorssettings.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRCorsSettings struct { + AllowedOrigins *[]string `json:"allowedOrigins,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrfeature.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrfeature.go new file mode 100644 index 00000000000..506f4ec0e67 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrfeature.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRFeature struct { + Flag FeatureFlags `json:"flag"` + Properties *map[string]string `json:"properties,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrkeys.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrkeys.go new file mode 100644 index 00000000000..70821e28a59 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrkeys.go @@ -0,0 +1,11 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRKeys struct { + PrimaryConnectionString *string `json:"primaryConnectionString,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryConnectionString *string `json:"secondaryConnectionString,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrnetworkacls.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrnetworkacls.go new file mode 100644 index 00000000000..05050a335b8 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrnetworkacls.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRNetworkACLs struct { + DefaultAction *ACLAction `json:"defaultAction,omitempty"` + PrivateEndpoints *[]PrivateEndpointACL `json:"privateEndpoints,omitempty"` + PublicNetwork *NetworkACL `json:"publicNetwork,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrproperties.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrproperties.go new file mode 100644 index 00000000000..256fade2289 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrproperties.go @@ -0,0 +1,27 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRProperties struct { + Cors *SignalRCorsSettings `json:"cors,omitempty"` + DisableAadAuth *bool `json:"disableAadAuth,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + ExternalIP *string `json:"externalIP,omitempty"` + Features *[]SignalRFeature `json:"features,omitempty"` + HostName *string `json:"hostName,omitempty"` + HostNamePrefix *string `json:"hostNamePrefix,omitempty"` + LiveTraceConfiguration *LiveTraceConfiguration `json:"liveTraceConfiguration,omitempty"` + NetworkACLs *SignalRNetworkACLs `json:"networkACLs,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *string `json:"publicNetworkAccess,omitempty"` + PublicPort *int64 `json:"publicPort,omitempty"` + ResourceLogConfiguration *ResourceLogConfiguration `json:"resourceLogConfiguration,omitempty"` + ServerPort *int64 `json:"serverPort,omitempty"` + Serverless *ServerlessSettings `json:"serverless,omitempty"` + SharedPrivateLinkResources *[]SharedPrivateLinkResource `json:"sharedPrivateLinkResources,omitempty"` + Tls *SignalRTlsSettings `json:"tls,omitempty"` + Upstream *ServerlessUpstreamSettings `json:"upstream,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrresource.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrresource.go new file mode 100644 index 00000000000..cb8f23323bf --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrresource.go @@ -0,0 +1,22 @@ +package signalr + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRResource struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemOrUserAssignedMap `json:"identity,omitempty"` + Kind *ServiceKind `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SignalRProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrtlssettings.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrtlssettings.go new file mode 100644 index 00000000000..94dbfbda5e6 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrtlssettings.go @@ -0,0 +1,8 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRTlsSettings struct { + ClientCertEnabled *bool `json:"clientCertEnabled,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrusage.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrusage.go new file mode 100644 index 00000000000..2bd863e5aff --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrusage.go @@ -0,0 +1,12 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRUsage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Id *string `json:"id,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *SignalRUsageName `json:"name,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_signalrusagename.go b/resource-manager/signalr/2023-02-01/signalr/model_signalrusagename.go new file mode 100644 index 00000000000..f9a475cc7c1 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_signalrusagename.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRUsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_sku.go b/resource-manager/signalr/2023-02-01/signalr/model_sku.go new file mode 100644 index 00000000000..0b2efca5d62 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_sku.go @@ -0,0 +1,10 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *SkuCapacity `json:"capacity,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_skucapacity.go b/resource-manager/signalr/2023-02-01/signalr/model_skucapacity.go new file mode 100644 index 00000000000..3ac0d557740 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_skucapacity.go @@ -0,0 +1,12 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuCapacity struct { + AllowedValues *[]int64 `json:"allowedValues,omitempty"` + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + ScaleType *ScaleType `json:"scaleType,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_skulist.go b/resource-manager/signalr/2023-02-01/signalr/model_skulist.go new file mode 100644 index 00000000000..70410fb96c8 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_skulist.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuList struct { + NextLink *string `json:"nextLink,omitempty"` + Value *[]Sku `json:"value,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_upstreamauthsettings.go b/resource-manager/signalr/2023-02-01/signalr/model_upstreamauthsettings.go new file mode 100644 index 00000000000..e5418bfaecf --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_upstreamauthsettings.go @@ -0,0 +1,9 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpstreamAuthSettings struct { + ManagedIdentity *ManagedIdentitySettings `json:"managedIdentity,omitempty"` + Type *UpstreamAuthType `json:"type,omitempty"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/model_upstreamtemplate.go b/resource-manager/signalr/2023-02-01/signalr/model_upstreamtemplate.go new file mode 100644 index 00000000000..476b1dd7cde --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/model_upstreamtemplate.go @@ -0,0 +1,12 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpstreamTemplate struct { + Auth *UpstreamAuthSettings `json:"auth,omitempty"` + CategoryPattern *string `json:"categoryPattern,omitempty"` + EventPattern *string `json:"eventPattern,omitempty"` + HubPattern *string `json:"hubPattern,omitempty"` + UrlTemplate string `json:"urlTemplate"` +} diff --git a/resource-manager/signalr/2023-02-01/signalr/predicates.go b/resource-manager/signalr/2023-02-01/signalr/predicates.go new file mode 100644 index 00000000000..3d91bb4a851 --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/predicates.go @@ -0,0 +1,175 @@ +package signalr + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificateOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CustomCertificateOperationPredicate) Matches(input CustomCertificate) 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 CustomDomainOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CustomDomainOperationPredicate) Matches(input CustomDomain) 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 PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} + +type SharedPrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SharedPrivateLinkResourceOperationPredicate) Matches(input SharedPrivateLinkResource) 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 SignalRResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SignalRResourceOperationPredicate) Matches(input SignalRResource) bool { + + 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 +} + +type SignalRUsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 + Unit *string +} + +func (p SignalRUsageOperationPredicate) Matches(input SignalRUsage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil && *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Limit != nil && (input.Limit == nil && *p.Limit != *input.Limit) { + return false + } + + if p.Unit != nil && (input.Unit == nil && *p.Unit != *input.Unit) { + return false + } + + return true +} diff --git a/resource-manager/signalr/2023-02-01/signalr/version.go b/resource-manager/signalr/2023-02-01/signalr/version.go new file mode 100644 index 00000000000..33187b558db --- /dev/null +++ b/resource-manager/signalr/2023-02-01/signalr/version.go @@ -0,0 +1,12 @@ +package signalr + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/signalr/%s", defaultApiVersion) +} diff --git a/resource-manager/webpubsub/2023-02-01/client.go b/resource-manager/webpubsub/2023-02-01/client.go new file mode 100644 index 00000000000..3b61c794fcd --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/client.go @@ -0,0 +1,23 @@ +package v2023_02_01 + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/hashicorp/go-azure-sdk/resource-manager/webpubsub/2023-02-01/webpubsub" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Client struct { + WebPubSub *webpubsub.WebPubSubClient +} + +func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { + + webPubSubClient := webpubsub.NewWebPubSubClientWithBaseURI(endpoint) + configureAuthFunc(&webPubSubClient.Client) + + return Client{ + WebPubSub: &webPubSubClient, + } +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/README.md b/resource-manager/webpubsub/2023-02-01/webpubsub/README.md new file mode 100644 index 00000000000..fa2bbec3a42 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/README.md @@ -0,0 +1,550 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/webpubsub/2023-02-01/webpubsub` Documentation + +The `webpubsub` SDK allows for interaction with the Azure Resource Manager Service `webpubsub` (API Version `2023-02-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/webpubsub/2023-02-01/webpubsub" +``` + + +### Client Initialization + +```go +client := webpubsub.NewWebPubSubClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WebPubSubClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := webpubsub.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := webpubsub.NameAvailabilityParameters{ + // ... +} + + +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: `WebPubSubClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +payload := webpubsub.WebPubSubResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.CustomCertificatesCreateOrUpdate` + +```go +ctx := context.TODO() +id := webpubsub.NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customCertificateValue") + +payload := webpubsub.CustomCertificate{ + // ... +} + + +if err := client.CustomCertificatesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.CustomCertificatesDelete` + +```go +ctx := context.TODO() +id := webpubsub.NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customCertificateValue") + +read, err := client.CustomCertificatesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.CustomCertificatesGet` + +```go +ctx := context.TODO() +id := webpubsub.NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customCertificateValue") + +read, err := client.CustomCertificatesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.CustomCertificatesList` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +// alternatively `client.CustomCertificatesList(ctx, id)` can be used to do batched pagination +items, err := client.CustomCertificatesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.CustomDomainsCreateOrUpdate` + +```go +ctx := context.TODO() +id := webpubsub.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customDomainValue") + +payload := webpubsub.CustomDomain{ + // ... +} + + +if err := client.CustomDomainsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.CustomDomainsDelete` + +```go +ctx := context.TODO() +id := webpubsub.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customDomainValue") + +if err := client.CustomDomainsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.CustomDomainsGet` + +```go +ctx := context.TODO() +id := webpubsub.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customDomainValue") + +read, err := client.CustomDomainsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.CustomDomainsList` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +// alternatively `client.CustomDomainsList(ctx, id)` can be used to do batched pagination +items, err := client.CustomDomainsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.Delete` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.Get` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +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: `WebPubSubClient.HubsCreateOrUpdate` + +```go +ctx := context.TODO() +id := webpubsub.NewHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "hubValue") + +payload := webpubsub.WebPubSubHub{ + // ... +} + + +if err := client.HubsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.HubsDelete` + +```go +ctx := context.TODO() +id := webpubsub.NewHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "hubValue") + +if err := client.HubsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.HubsGet` + +```go +ctx := context.TODO() +id := webpubsub.NewHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "hubValue") + +read, err := client.HubsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.HubsList` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +// alternatively `client.HubsList(ctx, id)` can be used to do batched pagination +items, err := client.HubsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := webpubsub.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.ListBySubscription` + +```go +ctx := context.TODO() +id := webpubsub.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.ListKeys` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +read, err := client.ListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.ListSkus` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +read, err := client.ListSkus(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.PrivateEndpointConnectionsDelete` + +```go +ctx := context.TODO() +id := webpubsub.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "privateEndpointConnectionValue") + +if err := client.PrivateEndpointConnectionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.PrivateEndpointConnectionsGet` + +```go +ctx := context.TODO() +id := webpubsub.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "privateEndpointConnectionValue") + +read, err := client.PrivateEndpointConnectionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.PrivateEndpointConnectionsList` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +// alternatively `client.PrivateEndpointConnectionsList(ctx, id)` can be used to do batched pagination +items, err := client.PrivateEndpointConnectionsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.PrivateEndpointConnectionsUpdate` + +```go +ctx := context.TODO() +id := webpubsub.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "privateEndpointConnectionValue") + +payload := webpubsub.PrivateEndpointConnection{ + // ... +} + + +read, err := client.PrivateEndpointConnectionsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.PrivateLinkResourcesList` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +// alternatively `client.PrivateLinkResourcesList(ctx, id)` can be used to do batched pagination +items, err := client.PrivateLinkResourcesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.RegenerateKey` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +payload := webpubsub.RegenerateKeyParameters{ + // ... +} + + +if err := client.RegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.Restart` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +if err := client.RestartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.SharedPrivateLinkResourcesCreateOrUpdate` + +```go +ctx := context.TODO() +id := webpubsub.NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "sharedPrivateLinkResourceValue") + +payload := webpubsub.SharedPrivateLinkResource{ + // ... +} + + +if err := client.SharedPrivateLinkResourcesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.SharedPrivateLinkResourcesDelete` + +```go +ctx := context.TODO() +id := webpubsub.NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "sharedPrivateLinkResourceValue") + +if err := client.SharedPrivateLinkResourcesDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.SharedPrivateLinkResourcesGet` + +```go +ctx := context.TODO() +id := webpubsub.NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "sharedPrivateLinkResourceValue") + +read, err := client.SharedPrivateLinkResourcesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebPubSubClient.SharedPrivateLinkResourcesList` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +// alternatively `client.SharedPrivateLinkResourcesList(ctx, id)` can be used to do batched pagination +items, err := client.SharedPrivateLinkResourcesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebPubSubClient.Update` + +```go +ctx := context.TODO() +id := webpubsub.NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + +payload := webpubsub.WebPubSubResource{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebPubSubClient.UsagesList` + +```go +ctx := context.TODO() +id := webpubsub.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.UsagesList(ctx, id)` can be used to do batched pagination +items, err := client.UsagesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/client.go b/resource-manager/webpubsub/2023-02-01/webpubsub/client.go new file mode 100644 index 00000000000..2e86ea49bf5 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/client.go @@ -0,0 +1,18 @@ +package webpubsub + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebPubSubClient struct { + Client autorest.Client + baseUri string +} + +func NewWebPubSubClientWithBaseURI(endpoint string) WebPubSubClient { + return WebPubSubClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/constants.go b/resource-manager/webpubsub/2023-02-01/webpubsub/constants.go new file mode 100644 index 00000000000..419b11a6efa --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/constants.go @@ -0,0 +1,362 @@ +package webpubsub + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ACLAction string + +const ( + ACLActionAllow ACLAction = "Allow" + ACLActionDeny ACLAction = "Deny" +) + +func PossibleValuesForACLAction() []string { + return []string{ + string(ACLActionAllow), + string(ACLActionDeny), + } +} + +func parseACLAction(input string) (*ACLAction, error) { + vals := map[string]ACLAction{ + "allow": ACLActionAllow, + "deny": ACLActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ACLAction(input) + return &out, nil +} + +type EventListenerEndpointDiscriminator string + +const ( + EventListenerEndpointDiscriminatorEventHub EventListenerEndpointDiscriminator = "EventHub" +) + +func PossibleValuesForEventListenerEndpointDiscriminator() []string { + return []string{ + string(EventListenerEndpointDiscriminatorEventHub), + } +} + +func parseEventListenerEndpointDiscriminator(input string) (*EventListenerEndpointDiscriminator, error) { + vals := map[string]EventListenerEndpointDiscriminator{ + "eventhub": EventListenerEndpointDiscriminatorEventHub, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventListenerEndpointDiscriminator(input) + return &out, nil +} + +type EventListenerFilterDiscriminator string + +const ( + EventListenerFilterDiscriminatorEventName EventListenerFilterDiscriminator = "EventName" +) + +func PossibleValuesForEventListenerFilterDiscriminator() []string { + return []string{ + string(EventListenerFilterDiscriminatorEventName), + } +} + +func parseEventListenerFilterDiscriminator(input string) (*EventListenerFilterDiscriminator, error) { + vals := map[string]EventListenerFilterDiscriminator{ + "eventname": EventListenerFilterDiscriminatorEventName, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventListenerFilterDiscriminator(input) + return &out, nil +} + +type KeyType string + +const ( + KeyTypePrimary KeyType = "Primary" + KeyTypeSalt KeyType = "Salt" + KeyTypeSecondary KeyType = "Secondary" +) + +func PossibleValuesForKeyType() []string { + return []string{ + string(KeyTypePrimary), + string(KeyTypeSalt), + string(KeyTypeSecondary), + } +} + +func parseKeyType(input string) (*KeyType, error) { + vals := map[string]KeyType{ + "primary": KeyTypePrimary, + "salt": KeyTypeSalt, + "secondary": KeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyType(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStatus string + +const ( + PrivateLinkServiceConnectionStatusApproved PrivateLinkServiceConnectionStatus = "Approved" + PrivateLinkServiceConnectionStatusDisconnected PrivateLinkServiceConnectionStatus = "Disconnected" + PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" + PrivateLinkServiceConnectionStatusRejected PrivateLinkServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStatusApproved), + string(PrivateLinkServiceConnectionStatusDisconnected), + string(PrivateLinkServiceConnectionStatusPending), + string(PrivateLinkServiceConnectionStatusRejected), + } +} + +func parsePrivateLinkServiceConnectionStatus(input string) (*PrivateLinkServiceConnectionStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStatus{ + "approved": PrivateLinkServiceConnectionStatusApproved, + "disconnected": PrivateLinkServiceConnectionStatusDisconnected, + "pending": PrivateLinkServiceConnectionStatusPending, + "rejected": PrivateLinkServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMoving ProvisioningState = "Moving" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUnknown ProvisioningState = "Unknown" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMoving), + string(ProvisioningStateRunning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUnknown), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "moving": ProvisioningStateMoving, + "running": ProvisioningStateRunning, + "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 ScaleType string + +const ( + ScaleTypeAutomatic ScaleType = "Automatic" + ScaleTypeManual ScaleType = "Manual" + ScaleTypeNone ScaleType = "None" +) + +func PossibleValuesForScaleType() []string { + return []string{ + string(ScaleTypeAutomatic), + string(ScaleTypeManual), + string(ScaleTypeNone), + } +} + +func parseScaleType(input string) (*ScaleType, error) { + vals := map[string]ScaleType{ + "automatic": ScaleTypeAutomatic, + "manual": ScaleTypeManual, + "none": ScaleTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScaleType(input) + return &out, nil +} + +type SharedPrivateLinkResourceStatus string + +const ( + SharedPrivateLinkResourceStatusApproved SharedPrivateLinkResourceStatus = "Approved" + SharedPrivateLinkResourceStatusDisconnected SharedPrivateLinkResourceStatus = "Disconnected" + SharedPrivateLinkResourceStatusPending SharedPrivateLinkResourceStatus = "Pending" + SharedPrivateLinkResourceStatusRejected SharedPrivateLinkResourceStatus = "Rejected" + SharedPrivateLinkResourceStatusTimeout SharedPrivateLinkResourceStatus = "Timeout" +) + +func PossibleValuesForSharedPrivateLinkResourceStatus() []string { + return []string{ + string(SharedPrivateLinkResourceStatusApproved), + string(SharedPrivateLinkResourceStatusDisconnected), + string(SharedPrivateLinkResourceStatusPending), + string(SharedPrivateLinkResourceStatusRejected), + string(SharedPrivateLinkResourceStatusTimeout), + } +} + +func parseSharedPrivateLinkResourceStatus(input string) (*SharedPrivateLinkResourceStatus, error) { + vals := map[string]SharedPrivateLinkResourceStatus{ + "approved": SharedPrivateLinkResourceStatusApproved, + "disconnected": SharedPrivateLinkResourceStatusDisconnected, + "pending": SharedPrivateLinkResourceStatusPending, + "rejected": SharedPrivateLinkResourceStatusRejected, + "timeout": SharedPrivateLinkResourceStatusTimeout, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SharedPrivateLinkResourceStatus(input) + return &out, nil +} + +type UpstreamAuthType string + +const ( + UpstreamAuthTypeManagedIdentity UpstreamAuthType = "ManagedIdentity" + UpstreamAuthTypeNone UpstreamAuthType = "None" +) + +func PossibleValuesForUpstreamAuthType() []string { + return []string{ + string(UpstreamAuthTypeManagedIdentity), + string(UpstreamAuthTypeNone), + } +} + +func parseUpstreamAuthType(input string) (*UpstreamAuthType, error) { + vals := map[string]UpstreamAuthType{ + "managedidentity": UpstreamAuthTypeManagedIdentity, + "none": UpstreamAuthTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpstreamAuthType(input) + return &out, nil +} + +type WebPubSubRequestType string + +const ( + WebPubSubRequestTypeClientConnection WebPubSubRequestType = "ClientConnection" + WebPubSubRequestTypeRESTAPI WebPubSubRequestType = "RESTAPI" + WebPubSubRequestTypeServerConnection WebPubSubRequestType = "ServerConnection" + WebPubSubRequestTypeTrace WebPubSubRequestType = "Trace" +) + +func PossibleValuesForWebPubSubRequestType() []string { + return []string{ + string(WebPubSubRequestTypeClientConnection), + string(WebPubSubRequestTypeRESTAPI), + string(WebPubSubRequestTypeServerConnection), + string(WebPubSubRequestTypeTrace), + } +} + +func parseWebPubSubRequestType(input string) (*WebPubSubRequestType, error) { + vals := map[string]WebPubSubRequestType{ + "clientconnection": WebPubSubRequestTypeClientConnection, + "restapi": WebPubSubRequestTypeRESTAPI, + "serverconnection": WebPubSubRequestTypeServerConnection, + "trace": WebPubSubRequestTypeTrace, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WebPubSubRequestType(input) + return &out, nil +} + +type WebPubSubSkuTier string + +const ( + WebPubSubSkuTierBasic WebPubSubSkuTier = "Basic" + WebPubSubSkuTierFree WebPubSubSkuTier = "Free" + WebPubSubSkuTierPremium WebPubSubSkuTier = "Premium" + WebPubSubSkuTierStandard WebPubSubSkuTier = "Standard" +) + +func PossibleValuesForWebPubSubSkuTier() []string { + return []string{ + string(WebPubSubSkuTierBasic), + string(WebPubSubSkuTierFree), + string(WebPubSubSkuTierPremium), + string(WebPubSubSkuTierStandard), + } +} + +func parseWebPubSubSkuTier(input string) (*WebPubSubSkuTier, error) { + vals := map[string]WebPubSubSkuTier{ + "basic": WebPubSubSkuTierBasic, + "free": WebPubSubSkuTierFree, + "premium": WebPubSubSkuTierPremium, + "standard": WebPubSubSkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WebPubSubSkuTier(input) + return &out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_customcertificate.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customcertificate.go new file mode 100644 index 00000000000..e0cbd8288dc --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customcertificate.go @@ -0,0 +1,140 @@ +package webpubsub + +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 = CustomCertificateId{} + +// CustomCertificateId is a struct representing the Resource ID for a Custom Certificate +type CustomCertificateId struct { + SubscriptionId string + ResourceGroupName string + WebPubSubName string + CustomCertificateName string +} + +// NewCustomCertificateID returns a new CustomCertificateId struct +func NewCustomCertificateID(subscriptionId string, resourceGroupName string, webPubSubName string, customCertificateName string) CustomCertificateId { + return CustomCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WebPubSubName: webPubSubName, + CustomCertificateName: customCertificateName, + } +} + +// ParseCustomCertificateID parses 'input' into a CustomCertificateId +func ParseCustomCertificateID(input string) (*CustomCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomCertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.CustomCertificateName, ok = parsed.Parsed["customCertificateName"]; !ok { + return nil, fmt.Errorf("the segment 'customCertificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCustomCertificateIDInsensitively parses 'input' case-insensitively into a CustomCertificateId +// note: this method should only be used for API response data and not user input +func ParseCustomCertificateIDInsensitively(input string) (*CustomCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomCertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.CustomCertificateName, ok = parsed.Parsed["customCertificateName"]; !ok { + return nil, fmt.Errorf("the segment 'customCertificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCustomCertificateID checks that 'input' can be parsed as a Custom Certificate ID +func ValidateCustomCertificateID(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 := ParseCustomCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Custom Certificate ID +func (id CustomCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s/customCertificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WebPubSubName, id.CustomCertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Custom Certificate ID +func (id CustomCertificateId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticWebPubSub", "webPubSub", "webPubSub"), + resourceids.UserSpecifiedSegment("webPubSubName", "webPubSubValue"), + resourceids.StaticSegment("staticCustomCertificates", "customCertificates", "customCertificates"), + resourceids.UserSpecifiedSegment("customCertificateName", "customCertificateValue"), + } +} + +// String returns a human-readable description of this Custom Certificate ID +func (id CustomCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Web Pub Sub Name: %q", id.WebPubSubName), + fmt.Sprintf("Custom Certificate Name: %q", id.CustomCertificateName), + } + return fmt.Sprintf("Custom Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_customcertificate_test.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customcertificate_test.go new file mode 100644 index 00000000000..dbdbd0cec9c --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customcertificate_test.go @@ -0,0 +1,327 @@ +package webpubsub + +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 = CustomCertificateId{} + +func TestNewCustomCertificateID(t *testing.T) { + id := NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customCertificateValue") + + 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.WebPubSubName != "webPubSubValue" { + t.Fatalf("Expected %q but got %q for Segment 'WebPubSubName'", id.WebPubSubName, "webPubSubValue") + } + + if id.CustomCertificateName != "customCertificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CustomCertificateName'", id.CustomCertificateName, "customCertificateValue") + } +} + +func TestFormatCustomCertificateID(t *testing.T) { + actual := NewCustomCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customCertificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customCertificates/customCertificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCustomCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomCertificateId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customCertificates/customCertificateValue", + Expected: &CustomCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + CustomCertificateName: "customCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customCertificates/customCertificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomCertificateID(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.CustomCertificateName != v.Expected.CustomCertificateName { + t.Fatalf("Expected %q but got %q for CustomCertificateName", v.Expected.CustomCertificateName, actual.CustomCertificateName) + } + + } +} + +func TestParseCustomCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomCertificateId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customCertificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/cUsToMcErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customCertificates/customCertificateValue", + Expected: &CustomCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + CustomCertificateName: "customCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customCertificates/customCertificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/cUsToMcErTiFiCaTeS/cUsToMcErTiFiCaTeVaLuE", + Expected: &CustomCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WebPubSubName: "wEbPuBsUbVaLuE", + CustomCertificateName: "cUsToMcErTiFiCaTeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/cUsToMcErTiFiCaTeS/cUsToMcErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomCertificateIDInsensitively(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.CustomCertificateName != v.Expected.CustomCertificateName { + t.Fatalf("Expected %q but got %q for CustomCertificateName", v.Expected.CustomCertificateName, actual.CustomCertificateName) + } + + } +} + +func TestSegmentsForCustomCertificateId(t *testing.T) { + segments := CustomCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CustomCertificateId 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/webpubsub/2023-02-01/webpubsub/id_customdomain.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customdomain.go new file mode 100644 index 00000000000..dcfbc02681a --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customdomain.go @@ -0,0 +1,140 @@ +package webpubsub + +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 = CustomDomainId{} + +// CustomDomainId is a struct representing the Resource ID for a Custom Domain +type CustomDomainId struct { + SubscriptionId string + ResourceGroupName string + WebPubSubName string + CustomDomainName string +} + +// NewCustomDomainID returns a new CustomDomainId struct +func NewCustomDomainID(subscriptionId string, resourceGroupName string, webPubSubName string, customDomainName string) CustomDomainId { + return CustomDomainId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WebPubSubName: webPubSubName, + CustomDomainName: customDomainName, + } +} + +// ParseCustomDomainID parses 'input' into a CustomDomainId +func ParseCustomDomainID(input string) (*CustomDomainId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomDomainId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomDomainId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.CustomDomainName, ok = parsed.Parsed["customDomainName"]; !ok { + return nil, fmt.Errorf("the segment 'customDomainName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCustomDomainIDInsensitively parses 'input' case-insensitively into a CustomDomainId +// note: this method should only be used for API response data and not user input +func ParseCustomDomainIDInsensitively(input string) (*CustomDomainId, error) { + parser := resourceids.NewParserFromResourceIdType(CustomDomainId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CustomDomainId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.CustomDomainName, ok = parsed.Parsed["customDomainName"]; !ok { + return nil, fmt.Errorf("the segment 'customDomainName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCustomDomainID checks that 'input' can be parsed as a Custom Domain ID +func ValidateCustomDomainID(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 := ParseCustomDomainID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Custom Domain ID +func (id CustomDomainId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s/customDomains/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WebPubSubName, id.CustomDomainName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Custom Domain ID +func (id CustomDomainId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticWebPubSub", "webPubSub", "webPubSub"), + resourceids.UserSpecifiedSegment("webPubSubName", "webPubSubValue"), + resourceids.StaticSegment("staticCustomDomains", "customDomains", "customDomains"), + resourceids.UserSpecifiedSegment("customDomainName", "customDomainValue"), + } +} + +// String returns a human-readable description of this Custom Domain ID +func (id CustomDomainId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Web Pub Sub Name: %q", id.WebPubSubName), + fmt.Sprintf("Custom Domain Name: %q", id.CustomDomainName), + } + return fmt.Sprintf("Custom Domain (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_customdomain_test.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customdomain_test.go new file mode 100644 index 00000000000..048beda55e8 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_customdomain_test.go @@ -0,0 +1,327 @@ +package webpubsub + +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 = CustomDomainId{} + +func TestNewCustomDomainID(t *testing.T) { + id := NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customDomainValue") + + 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.WebPubSubName != "webPubSubValue" { + t.Fatalf("Expected %q but got %q for Segment 'WebPubSubName'", id.WebPubSubName, "webPubSubValue") + } + + if id.CustomDomainName != "customDomainValue" { + t.Fatalf("Expected %q but got %q for Segment 'CustomDomainName'", id.CustomDomainName, "customDomainValue") + } +} + +func TestFormatCustomDomainID(t *testing.T) { + actual := NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "customDomainValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customDomains/customDomainValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCustomDomainID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomDomainId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customDomains", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customDomains/customDomainValue", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customDomains/customDomainValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomDomainID(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.CustomDomainName != v.Expected.CustomDomainName { + t.Fatalf("Expected %q but got %q for CustomDomainName", v.Expected.CustomDomainName, actual.CustomDomainName) + } + + } +} + +func TestParseCustomDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CustomDomainId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customDomains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/cUsToMdOmAiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customDomains/customDomainValue", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/customDomains/customDomainValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/cUsToMdOmAiNs/cUsToMdOmAiNvAlUe", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WebPubSubName: "wEbPuBsUbVaLuE", + CustomDomainName: "cUsToMdOmAiNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/cUsToMdOmAiNs/cUsToMdOmAiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCustomDomainIDInsensitively(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.CustomDomainName != v.Expected.CustomDomainName { + t.Fatalf("Expected %q but got %q for CustomDomainName", v.Expected.CustomDomainName, actual.CustomDomainName) + } + + } +} + +func TestSegmentsForCustomDomainId(t *testing.T) { + segments := CustomDomainId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CustomDomainId 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/webpubsub/2023-02-01/webpubsub/id_hub.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_hub.go new file mode 100644 index 00000000000..021d6fecee0 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_hub.go @@ -0,0 +1,140 @@ +package webpubsub + +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 = HubId{} + +// HubId is a struct representing the Resource ID for a Hub +type HubId struct { + SubscriptionId string + ResourceGroupName string + WebPubSubName string + HubName string +} + +// NewHubID returns a new HubId struct +func NewHubID(subscriptionId string, resourceGroupName string, webPubSubName string, hubName string) HubId { + return HubId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WebPubSubName: webPubSubName, + HubName: hubName, + } +} + +// ParseHubID parses 'input' into a HubId +func ParseHubID(input string) (*HubId, error) { + parser := resourceids.NewParserFromResourceIdType(HubId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HubId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.HubName, ok = parsed.Parsed["hubName"]; !ok { + return nil, fmt.Errorf("the segment 'hubName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseHubIDInsensitively parses 'input' case-insensitively into a HubId +// note: this method should only be used for API response data and not user input +func ParseHubIDInsensitively(input string) (*HubId, error) { + parser := resourceids.NewParserFromResourceIdType(HubId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := HubId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.HubName, ok = parsed.Parsed["hubName"]; !ok { + return nil, fmt.Errorf("the segment 'hubName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateHubID checks that 'input' can be parsed as a Hub ID +func ValidateHubID(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 := ParseHubID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Hub ID +func (id HubId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s/hubs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WebPubSubName, id.HubName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Hub ID +func (id HubId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticWebPubSub", "webPubSub", "webPubSub"), + resourceids.UserSpecifiedSegment("webPubSubName", "webPubSubValue"), + resourceids.StaticSegment("staticHubs", "hubs", "hubs"), + resourceids.UserSpecifiedSegment("hubName", "hubValue"), + } +} + +// String returns a human-readable description of this Hub ID +func (id HubId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Web Pub Sub Name: %q", id.WebPubSubName), + fmt.Sprintf("Hub Name: %q", id.HubName), + } + return fmt.Sprintf("Hub (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_hub_test.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_hub_test.go new file mode 100644 index 00000000000..297df08a603 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_hub_test.go @@ -0,0 +1,327 @@ +package webpubsub + +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 = HubId{} + +func TestNewHubID(t *testing.T) { + id := NewHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "hubValue") + + 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.WebPubSubName != "webPubSubValue" { + t.Fatalf("Expected %q but got %q for Segment 'WebPubSubName'", id.WebPubSubName, "webPubSubValue") + } + + if id.HubName != "hubValue" { + t.Fatalf("Expected %q but got %q for Segment 'HubName'", id.HubName, "hubValue") + } +} + +func TestFormatHubID(t *testing.T) { + actual := NewHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "hubValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/hubs/hubValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHubID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HubId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/hubs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/hubs/hubValue", + Expected: &HubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + HubName: "hubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/hubs/hubValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHubID(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.HubName != v.Expected.HubName { + t.Fatalf("Expected %q but got %q for HubName", v.Expected.HubName, actual.HubName) + } + + } +} + +func TestParseHubIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HubId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/hubs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/hUbS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/hubs/hubValue", + Expected: &HubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + HubName: "hubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/hubs/hubValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/hUbS/hUbVaLuE", + Expected: &HubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WebPubSubName: "wEbPuBsUbVaLuE", + HubName: "hUbVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/hUbS/hUbVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHubIDInsensitively(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.HubName != v.Expected.HubName { + t.Fatalf("Expected %q but got %q for HubName", v.Expected.HubName, actual.HubName) + } + + } +} + +func TestSegmentsForHubId(t *testing.T) { + segments := HubId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HubId 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/webpubsub/2023-02-01/webpubsub/id_location.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_location.go new file mode 100644 index 00000000000..f4544190a60 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_location.go @@ -0,0 +1,114 @@ +package webpubsub + +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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := LocationId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.LocationName, ok = parsed.Parsed["locationName"]; !ok { + return nil, fmt.Errorf("the segment 'locationName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, 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.SignalRService/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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + 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/webpubsub/2023-02-01/webpubsub/id_location_test.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_location_test.go new file mode 100644 index 00000000000..3f5675e7afd --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_location_test.go @@ -0,0 +1,237 @@ +package webpubsub + +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.SignalRService/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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.SignalRService/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "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.sIgNaLrSeRvIcE/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/webpubsub/2023-02-01/webpubsub/id_privateendpointconnection.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_privateendpointconnection.go new file mode 100644 index 00000000000..0bffb4fe0a7 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_privateendpointconnection.go @@ -0,0 +1,140 @@ +package webpubsub + +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 = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + WebPubSubName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, webPubSubName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WebPubSubName: webPubSubName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WebPubSubName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticWebPubSub", "webPubSub", "webPubSub"), + resourceids.UserSpecifiedSegment("webPubSubName", "webPubSubValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Web Pub Sub Name: %q", id.WebPubSubName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_privateendpointconnection_test.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..caf747978b0 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package webpubsub + +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 = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WebPubSubName != "webPubSubValue" { + t.Fatalf("Expected %q but got %q for Segment 'WebPubSubName'", id.WebPubSubName, "webPubSubValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WebPubSubName: "wEbPuBsUbVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_sharedprivatelinkresource.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_sharedprivatelinkresource.go new file mode 100644 index 00000000000..eaa87e06c33 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_sharedprivatelinkresource.go @@ -0,0 +1,140 @@ +package webpubsub + +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 = SharedPrivateLinkResourceId{} + +// SharedPrivateLinkResourceId is a struct representing the Resource ID for a Shared Private Link Resource +type SharedPrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + WebPubSubName string + SharedPrivateLinkResourceName string +} + +// NewSharedPrivateLinkResourceID returns a new SharedPrivateLinkResourceId struct +func NewSharedPrivateLinkResourceID(subscriptionId string, resourceGroupName string, webPubSubName string, sharedPrivateLinkResourceName string) SharedPrivateLinkResourceId { + return SharedPrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WebPubSubName: webPubSubName, + SharedPrivateLinkResourceName: sharedPrivateLinkResourceName, + } +} + +// ParseSharedPrivateLinkResourceID parses 'input' into a SharedPrivateLinkResourceId +func ParseSharedPrivateLinkResourceID(input string) (*SharedPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(SharedPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SharedPrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.SharedPrivateLinkResourceName, ok = parsed.Parsed["sharedPrivateLinkResourceName"]; !ok { + return nil, fmt.Errorf("the segment 'sharedPrivateLinkResourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSharedPrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a SharedPrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParseSharedPrivateLinkResourceIDInsensitively(input string) (*SharedPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(SharedPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SharedPrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + if id.SharedPrivateLinkResourceName, ok = parsed.Parsed["sharedPrivateLinkResourceName"]; !ok { + return nil, fmt.Errorf("the segment 'sharedPrivateLinkResourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSharedPrivateLinkResourceID checks that 'input' can be parsed as a Shared Private Link Resource ID +func ValidateSharedPrivateLinkResourceID(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 := ParseSharedPrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Shared Private Link Resource ID +func (id SharedPrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s/sharedPrivateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WebPubSubName, id.SharedPrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Shared Private Link Resource ID +func (id SharedPrivateLinkResourceId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticWebPubSub", "webPubSub", "webPubSub"), + resourceids.UserSpecifiedSegment("webPubSubName", "webPubSubValue"), + resourceids.StaticSegment("staticSharedPrivateLinkResources", "sharedPrivateLinkResources", "sharedPrivateLinkResources"), + resourceids.UserSpecifiedSegment("sharedPrivateLinkResourceName", "sharedPrivateLinkResourceValue"), + } +} + +// String returns a human-readable description of this Shared Private Link Resource ID +func (id SharedPrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Web Pub Sub Name: %q", id.WebPubSubName), + fmt.Sprintf("Shared Private Link Resource Name: %q", id.SharedPrivateLinkResourceName), + } + return fmt.Sprintf("Shared Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_sharedprivatelinkresource_test.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_sharedprivatelinkresource_test.go new file mode 100644 index 00000000000..d874f1ca2fb --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_sharedprivatelinkresource_test.go @@ -0,0 +1,327 @@ +package webpubsub + +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 = SharedPrivateLinkResourceId{} + +func TestNewSharedPrivateLinkResourceID(t *testing.T) { + id := NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "sharedPrivateLinkResourceValue") + + 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.WebPubSubName != "webPubSubValue" { + t.Fatalf("Expected %q but got %q for Segment 'WebPubSubName'", id.WebPubSubName, "webPubSubValue") + } + + if id.SharedPrivateLinkResourceName != "sharedPrivateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'SharedPrivateLinkResourceName'", id.SharedPrivateLinkResourceName, "sharedPrivateLinkResourceValue") + } +} + +func TestFormatSharedPrivateLinkResourceID(t *testing.T) { + actual := NewSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue", "sharedPrivateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSharedPrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SharedPrivateLinkResourceId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/sharedPrivateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue", + Expected: &SharedPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + SharedPrivateLinkResourceName: "sharedPrivateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSharedPrivateLinkResourceID(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.SharedPrivateLinkResourceName != v.Expected.SharedPrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for SharedPrivateLinkResourceName", v.Expected.SharedPrivateLinkResourceName, actual.SharedPrivateLinkResourceName) + } + + } +} + +func TestParseSharedPrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SharedPrivateLinkResourceId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/sharedPrivateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/sHaReDpRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue", + Expected: &SharedPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + SharedPrivateLinkResourceName: "sharedPrivateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/sharedPrivateLinkResources/sharedPrivateLinkResourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/sHaReDpRiVaTeLiNkReSoUrCeS/sHaReDpRiVaTeLiNkReSoUrCeVaLuE", + Expected: &SharedPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WebPubSubName: "wEbPuBsUbVaLuE", + SharedPrivateLinkResourceName: "sHaReDpRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/sHaReDpRiVaTeLiNkReSoUrCeS/sHaReDpRiVaTeLiNkReSoUrCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSharedPrivateLinkResourceIDInsensitively(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + if actual.SharedPrivateLinkResourceName != v.Expected.SharedPrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for SharedPrivateLinkResourceName", v.Expected.SharedPrivateLinkResourceName, actual.SharedPrivateLinkResourceName) + } + + } +} + +func TestSegmentsForSharedPrivateLinkResourceId(t *testing.T) { + segments := SharedPrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SharedPrivateLinkResourceId 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/webpubsub/2023-02-01/webpubsub/id_webpubsub.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_webpubsub.go new file mode 100644 index 00000000000..dc26aa1f67d --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_webpubsub.go @@ -0,0 +1,127 @@ +package webpubsub + +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 = WebPubSubId{} + +// WebPubSubId is a struct representing the Resource ID for a Web Pub Sub +type WebPubSubId struct { + SubscriptionId string + ResourceGroupName string + WebPubSubName string +} + +// NewWebPubSubID returns a new WebPubSubId struct +func NewWebPubSubID(subscriptionId string, resourceGroupName string, webPubSubName string) WebPubSubId { + return WebPubSubId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WebPubSubName: webPubSubName, + } +} + +// ParseWebPubSubID parses 'input' into a WebPubSubId +func ParseWebPubSubID(input string) (*WebPubSubId, error) { + parser := resourceids.NewParserFromResourceIdType(WebPubSubId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WebPubSubId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWebPubSubIDInsensitively parses 'input' case-insensitively into a WebPubSubId +// note: this method should only be used for API response data and not user input +func ParseWebPubSubIDInsensitively(input string) (*WebPubSubId, error) { + parser := resourceids.NewParserFromResourceIdType(WebPubSubId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WebPubSubId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WebPubSubName, ok = parsed.Parsed["webPubSubName"]; !ok { + return nil, fmt.Errorf("the segment 'webPubSubName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWebPubSubID checks that 'input' can be parsed as a Web Pub Sub ID +func ValidateWebPubSubID(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 := ParseWebPubSubID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Web Pub Sub ID +func (id WebPubSubId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WebPubSubName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Web Pub Sub ID +func (id WebPubSubId) 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("staticMicrosoftSignalRService", "Microsoft.SignalRService", "Microsoft.SignalRService"), + resourceids.StaticSegment("staticWebPubSub", "webPubSub", "webPubSub"), + resourceids.UserSpecifiedSegment("webPubSubName", "webPubSubValue"), + } +} + +// String returns a human-readable description of this Web Pub Sub ID +func (id WebPubSubId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Web Pub Sub Name: %q", id.WebPubSubName), + } + return fmt.Sprintf("Web Pub Sub (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/id_webpubsub_test.go b/resource-manager/webpubsub/2023-02-01/webpubsub/id_webpubsub_test.go new file mode 100644 index 00000000000..f5680f7b41d --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/id_webpubsub_test.go @@ -0,0 +1,282 @@ +package webpubsub + +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 = WebPubSubId{} + +func TestNewWebPubSubID(t *testing.T) { + id := NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue") + + 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.WebPubSubName != "webPubSubValue" { + t.Fatalf("Expected %q but got %q for Segment 'WebPubSubName'", id.WebPubSubName, "webPubSubValue") + } +} + +func TestFormatWebPubSubID(t *testing.T) { + actual := NewWebPubSubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "webPubSubValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWebPubSubID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WebPubSubId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Expected: &WebPubSubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWebPubSubID(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + } +} + +func TestParseWebPubSubIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WebPubSubId + }{ + { + // 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.SignalRService", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue", + Expected: &WebPubSubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WebPubSubName: "webPubSubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.SignalRService/webPubSub/webPubSubValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE", + Expected: &WebPubSubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WebPubSubName: "wEbPuBsUbVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sIgNaLrSeRvIcE/wEbPuBsUb/wEbPuBsUbVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWebPubSubIDInsensitively(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.WebPubSubName != v.Expected.WebPubSubName { + t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName) + } + + } +} + +func TestSegmentsForWebPubSubId(t *testing.T) { + segments := WebPubSubId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WebPubSubId 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/webpubsub/2023-02-01/webpubsub/method_checknameavailability_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_checknameavailability_autorest.go new file mode 100644 index 00000000000..57bdce7a48c --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_checknameavailability_autorest.go @@ -0,0 +1,70 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + Model *NameAvailability +} + +// CheckNameAvailability ... +func (c WebPubSubClient) CheckNameAvailability(ctx context.Context, id LocationId, input NameAvailabilityParameters) (result CheckNameAvailabilityOperationResponse, err error) { + req, err := c.preparerForCheckNameAvailability(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CheckNameAvailability", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CheckNameAvailability", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCheckNameAvailability(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CheckNameAvailability", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCheckNameAvailability prepares the CheckNameAvailability request. +func (c WebPubSubClient) preparerForCheckNameAvailability(ctx context.Context, id LocationId, input NameAvailabilityParameters) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/checkNameAvailability", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCheckNameAvailability handles the response to the CheckNameAvailability request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForCheckNameAvailability(resp *http.Response) (result CheckNameAvailabilityOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_createorupdate_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_createorupdate_autorest.go new file mode 100644 index 00000000000..e21fceac115 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c WebPubSubClient) CreateOrUpdate(ctx context.Context, id WebPubSubId, input WebPubSubResource) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c WebPubSubClient) CreateOrUpdateThenPoll(ctx context.Context, id WebPubSubId, input WebPubSubResource) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c WebPubSubClient) preparerForCreateOrUpdate(ctx context.Context, id WebPubSubId, input WebPubSubResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatescreateorupdate_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatescreateorupdate_autorest.go new file mode 100644 index 00000000000..f7e0c1a1fbe --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatescreateorupdate_autorest.go @@ -0,0 +1,79 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificatesCreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CustomCertificatesCreateOrUpdate ... +func (c WebPubSubClient) CustomCertificatesCreateOrUpdate(ctx context.Context, id CustomCertificateId, input CustomCertificate) (result CustomCertificatesCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCustomCertificatesCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesCreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCustomCertificatesCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CustomCertificatesCreateOrUpdateThenPoll performs CustomCertificatesCreateOrUpdate then polls until it's completed +func (c WebPubSubClient) CustomCertificatesCreateOrUpdateThenPoll(ctx context.Context, id CustomCertificateId, input CustomCertificate) error { + result, err := c.CustomCertificatesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CustomCertificatesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CustomCertificatesCreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCustomCertificatesCreateOrUpdate prepares the CustomCertificatesCreateOrUpdate request. +func (c WebPubSubClient) preparerForCustomCertificatesCreateOrUpdate(ctx context.Context, id CustomCertificateId, input CustomCertificate) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCustomCertificatesCreateOrUpdate sends the CustomCertificatesCreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForCustomCertificatesCreateOrUpdate(ctx context.Context, req *http.Request) (future CustomCertificatesCreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatesdelete_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatesdelete_autorest.go new file mode 100644 index 00000000000..f03cf9396ae --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatesdelete_autorest.go @@ -0,0 +1,66 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificatesDeleteOperationResponse struct { + HttpResponse *http.Response +} + +// CustomCertificatesDelete ... +func (c WebPubSubClient) CustomCertificatesDelete(ctx context.Context, id CustomCertificateId) (result CustomCertificatesDeleteOperationResponse, err error) { + req, err := c.preparerForCustomCertificatesDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesDelete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesDelete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCustomCertificatesDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesDelete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCustomCertificatesDelete prepares the CustomCertificatesDelete request. +func (c WebPubSubClient) preparerForCustomCertificatesDelete(ctx context.Context, id CustomCertificateId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCustomCertificatesDelete handles the response to the CustomCertificatesDelete request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForCustomCertificatesDelete(resp *http.Response) (result CustomCertificatesDeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatesget_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatesget_autorest.go new file mode 100644 index 00000000000..41979d76a10 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificatesget_autorest.go @@ -0,0 +1,68 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificatesGetOperationResponse struct { + HttpResponse *http.Response + Model *CustomCertificate +} + +// CustomCertificatesGet ... +func (c WebPubSubClient) CustomCertificatesGet(ctx context.Context, id CustomCertificateId) (result CustomCertificatesGetOperationResponse, err error) { + req, err := c.preparerForCustomCertificatesGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCustomCertificatesGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCustomCertificatesGet prepares the CustomCertificatesGet request. +func (c WebPubSubClient) preparerForCustomCertificatesGet(ctx context.Context, id CustomCertificateId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCustomCertificatesGet handles the response to the CustomCertificatesGet request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForCustomCertificatesGet(resp *http.Response) (result CustomCertificatesGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificateslist_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificateslist_autorest.go new file mode 100644 index 00000000000..058dabda48f --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customcertificateslist_autorest.go @@ -0,0 +1,186 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificatesListOperationResponse struct { + HttpResponse *http.Response + Model *[]CustomCertificate + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (CustomCertificatesListOperationResponse, error) +} + +type CustomCertificatesListCompleteResult struct { + Items []CustomCertificate +} + +func (r CustomCertificatesListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r CustomCertificatesListOperationResponse) LoadMore(ctx context.Context) (resp CustomCertificatesListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// CustomCertificatesList ... +func (c WebPubSubClient) CustomCertificatesList(ctx context.Context, id WebPubSubId) (resp CustomCertificatesListOperationResponse, err error) { + req, err := c.preparerForCustomCertificatesList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForCustomCertificatesList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForCustomCertificatesList prepares the CustomCertificatesList request. +func (c WebPubSubClient) preparerForCustomCertificatesList(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/customCertificates", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForCustomCertificatesListWithNextLink prepares the CustomCertificatesList request with the given nextLink token. +func (c WebPubSubClient) preparerForCustomCertificatesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCustomCertificatesList handles the response to the CustomCertificatesList request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForCustomCertificatesList(resp *http.Response) (result CustomCertificatesListOperationResponse, err error) { + type page struct { + Values []CustomCertificate `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result CustomCertificatesListOperationResponse, err error) { + req, err := c.preparerForCustomCertificatesListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCustomCertificatesList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomCertificatesList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// CustomCertificatesListComplete retrieves all of the results into a single object +func (c WebPubSubClient) CustomCertificatesListComplete(ctx context.Context, id WebPubSubId) (CustomCertificatesListCompleteResult, error) { + return c.CustomCertificatesListCompleteMatchingPredicate(ctx, id, CustomCertificateOperationPredicate{}) +} + +// CustomCertificatesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) CustomCertificatesListCompleteMatchingPredicate(ctx context.Context, id WebPubSubId, predicate CustomCertificateOperationPredicate) (resp CustomCertificatesListCompleteResult, err error) { + items := make([]CustomCertificate, 0) + + page, err := c.CustomCertificatesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := CustomCertificatesListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainscreateorupdate_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainscreateorupdate_autorest.go new file mode 100644 index 00000000000..7ab78e6c0af --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainscreateorupdate_autorest.go @@ -0,0 +1,79 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainsCreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CustomDomainsCreateOrUpdate ... +func (c WebPubSubClient) CustomDomainsCreateOrUpdate(ctx context.Context, id CustomDomainId, input CustomDomain) (result CustomDomainsCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCustomDomainsCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsCreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCustomDomainsCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CustomDomainsCreateOrUpdateThenPoll performs CustomDomainsCreateOrUpdate then polls until it's completed +func (c WebPubSubClient) CustomDomainsCreateOrUpdateThenPoll(ctx context.Context, id CustomDomainId, input CustomDomain) error { + result, err := c.CustomDomainsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CustomDomainsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CustomDomainsCreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCustomDomainsCreateOrUpdate prepares the CustomDomainsCreateOrUpdate request. +func (c WebPubSubClient) preparerForCustomDomainsCreateOrUpdate(ctx context.Context, id CustomDomainId, input CustomDomain) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCustomDomainsCreateOrUpdate sends the CustomDomainsCreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForCustomDomainsCreateOrUpdate(ctx context.Context, req *http.Request) (future CustomDomainsCreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainsdelete_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainsdelete_autorest.go new file mode 100644 index 00000000000..d96aad4bd5c --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainsdelete_autorest.go @@ -0,0 +1,78 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainsDeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CustomDomainsDelete ... +func (c WebPubSubClient) CustomDomainsDelete(ctx context.Context, id CustomDomainId) (result CustomDomainsDeleteOperationResponse, err error) { + req, err := c.preparerForCustomDomainsDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForCustomDomainsDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CustomDomainsDeleteThenPoll performs CustomDomainsDelete then polls until it's completed +func (c WebPubSubClient) CustomDomainsDeleteThenPoll(ctx context.Context, id CustomDomainId) error { + result, err := c.CustomDomainsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing CustomDomainsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CustomDomainsDelete: %+v", err) + } + + return nil +} + +// preparerForCustomDomainsDelete prepares the CustomDomainsDelete request. +func (c WebPubSubClient) preparerForCustomDomainsDelete(ctx context.Context, id CustomDomainId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCustomDomainsDelete sends the CustomDomainsDelete request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForCustomDomainsDelete(ctx context.Context, req *http.Request) (future CustomDomainsDeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainsget_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainsget_autorest.go new file mode 100644 index 00000000000..c663498ee51 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainsget_autorest.go @@ -0,0 +1,68 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainsGetOperationResponse struct { + HttpResponse *http.Response + Model *CustomDomain +} + +// CustomDomainsGet ... +func (c WebPubSubClient) CustomDomainsGet(ctx context.Context, id CustomDomainId) (result CustomDomainsGetOperationResponse, err error) { + req, err := c.preparerForCustomDomainsGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCustomDomainsGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCustomDomainsGet prepares the CustomDomainsGet request. +func (c WebPubSubClient) preparerForCustomDomainsGet(ctx context.Context, id CustomDomainId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCustomDomainsGet handles the response to the CustomDomainsGet request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForCustomDomainsGet(resp *http.Response) (result CustomDomainsGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainslist_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainslist_autorest.go new file mode 100644 index 00000000000..24e1691e5c1 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_customdomainslist_autorest.go @@ -0,0 +1,186 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainsListOperationResponse struct { + HttpResponse *http.Response + Model *[]CustomDomain + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (CustomDomainsListOperationResponse, error) +} + +type CustomDomainsListCompleteResult struct { + Items []CustomDomain +} + +func (r CustomDomainsListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r CustomDomainsListOperationResponse) LoadMore(ctx context.Context) (resp CustomDomainsListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// CustomDomainsList ... +func (c WebPubSubClient) CustomDomainsList(ctx context.Context, id WebPubSubId) (resp CustomDomainsListOperationResponse, err error) { + req, err := c.preparerForCustomDomainsList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForCustomDomainsList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForCustomDomainsList prepares the CustomDomainsList request. +func (c WebPubSubClient) preparerForCustomDomainsList(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/customDomains", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForCustomDomainsListWithNextLink prepares the CustomDomainsList request with the given nextLink token. +func (c WebPubSubClient) preparerForCustomDomainsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCustomDomainsList handles the response to the CustomDomainsList request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForCustomDomainsList(resp *http.Response) (result CustomDomainsListOperationResponse, err error) { + type page struct { + Values []CustomDomain `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result CustomDomainsListOperationResponse, err error) { + req, err := c.preparerForCustomDomainsListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCustomDomainsList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "CustomDomainsList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// CustomDomainsListComplete retrieves all of the results into a single object +func (c WebPubSubClient) CustomDomainsListComplete(ctx context.Context, id WebPubSubId) (CustomDomainsListCompleteResult, error) { + return c.CustomDomainsListCompleteMatchingPredicate(ctx, id, CustomDomainOperationPredicate{}) +} + +// CustomDomainsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) CustomDomainsListCompleteMatchingPredicate(ctx context.Context, id WebPubSubId, predicate CustomDomainOperationPredicate) (resp CustomDomainsListCompleteResult, err error) { + items := make([]CustomDomain, 0) + + page, err := c.CustomDomainsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := CustomDomainsListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_delete_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_delete_autorest.go new file mode 100644 index 00000000000..7f35dcf5f4e --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_delete_autorest.go @@ -0,0 +1,78 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c WebPubSubClient) Delete(ctx context.Context, id WebPubSubId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c WebPubSubClient) DeleteThenPoll(ctx context.Context, id WebPubSubId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c WebPubSubClient) preparerForDelete(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_get_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_get_autorest.go new file mode 100644 index 00000000000..dba6e5aecee --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_get_autorest.go @@ -0,0 +1,68 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *WebPubSubResource +} + +// Get ... +func (c WebPubSubClient) Get(ctx context.Context, id WebPubSubId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c WebPubSubClient) preparerForGet(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubscreateorupdate_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubscreateorupdate_autorest.go new file mode 100644 index 00000000000..9be5ec8cb78 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubscreateorupdate_autorest.go @@ -0,0 +1,79 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HubsCreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// HubsCreateOrUpdate ... +func (c WebPubSubClient) HubsCreateOrUpdate(ctx context.Context, id HubId, input WebPubSubHub) (result HubsCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForHubsCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsCreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForHubsCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// HubsCreateOrUpdateThenPoll performs HubsCreateOrUpdate then polls until it's completed +func (c WebPubSubClient) HubsCreateOrUpdateThenPoll(ctx context.Context, id HubId, input WebPubSubHub) error { + result, err := c.HubsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing HubsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after HubsCreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForHubsCreateOrUpdate prepares the HubsCreateOrUpdate request. +func (c WebPubSubClient) preparerForHubsCreateOrUpdate(ctx context.Context, id HubId, input WebPubSubHub) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForHubsCreateOrUpdate sends the HubsCreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForHubsCreateOrUpdate(ctx context.Context, req *http.Request) (future HubsCreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubsdelete_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubsdelete_autorest.go new file mode 100644 index 00000000000..da74ad5370e --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubsdelete_autorest.go @@ -0,0 +1,78 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HubsDeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// HubsDelete ... +func (c WebPubSubClient) HubsDelete(ctx context.Context, id HubId) (result HubsDeleteOperationResponse, err error) { + req, err := c.preparerForHubsDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForHubsDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// HubsDeleteThenPoll performs HubsDelete then polls until it's completed +func (c WebPubSubClient) HubsDeleteThenPoll(ctx context.Context, id HubId) error { + result, err := c.HubsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing HubsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after HubsDelete: %+v", err) + } + + return nil +} + +// preparerForHubsDelete prepares the HubsDelete request. +func (c WebPubSubClient) preparerForHubsDelete(ctx context.Context, id HubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForHubsDelete sends the HubsDelete request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForHubsDelete(ctx context.Context, req *http.Request) (future HubsDeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubsget_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubsget_autorest.go new file mode 100644 index 00000000000..201d1f3d226 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubsget_autorest.go @@ -0,0 +1,68 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HubsGetOperationResponse struct { + HttpResponse *http.Response + Model *WebPubSubHub +} + +// HubsGet ... +func (c WebPubSubClient) HubsGet(ctx context.Context, id HubId) (result HubsGetOperationResponse, err error) { + req, err := c.preparerForHubsGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForHubsGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForHubsGet prepares the HubsGet request. +func (c WebPubSubClient) preparerForHubsGet(ctx context.Context, id HubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForHubsGet handles the response to the HubsGet request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForHubsGet(resp *http.Response) (result HubsGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubslist_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubslist_autorest.go new file mode 100644 index 00000000000..ac760eff81e --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_hubslist_autorest.go @@ -0,0 +1,186 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HubsListOperationResponse struct { + HttpResponse *http.Response + Model *[]WebPubSubHub + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (HubsListOperationResponse, error) +} + +type HubsListCompleteResult struct { + Items []WebPubSubHub +} + +func (r HubsListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r HubsListOperationResponse) LoadMore(ctx context.Context) (resp HubsListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// HubsList ... +func (c WebPubSubClient) HubsList(ctx context.Context, id WebPubSubId) (resp HubsListOperationResponse, err error) { + req, err := c.preparerForHubsList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForHubsList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForHubsList prepares the HubsList request. +func (c WebPubSubClient) preparerForHubsList(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/hubs", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForHubsListWithNextLink prepares the HubsList request with the given nextLink token. +func (c WebPubSubClient) preparerForHubsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForHubsList handles the response to the HubsList request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForHubsList(resp *http.Response) (result HubsListOperationResponse, err error) { + type page struct { + Values []WebPubSubHub `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result HubsListOperationResponse, err error) { + req, err := c.preparerForHubsListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForHubsList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "HubsList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// HubsListComplete retrieves all of the results into a single object +func (c WebPubSubClient) HubsListComplete(ctx context.Context, id WebPubSubId) (HubsListCompleteResult, error) { + return c.HubsListCompleteMatchingPredicate(ctx, id, WebPubSubHubOperationPredicate{}) +} + +// HubsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) HubsListCompleteMatchingPredicate(ctx context.Context, id WebPubSubId, predicate WebPubSubHubOperationPredicate) (resp HubsListCompleteResult, err error) { + items := make([]WebPubSubHub, 0) + + page, err := c.HubsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := HubsListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_listbyresourcegroup_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listbyresourcegroup_autorest.go new file mode 100644 index 00000000000..6e5e9ee624f --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]WebPubSubResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []WebPubSubResource +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c WebPubSubClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c WebPubSubClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SignalRService/webPubSub", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c WebPubSubClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []WebPubSubResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c WebPubSubClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, WebPubSubResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate WebPubSubResourceOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]WebPubSubResource, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_listbysubscription_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listbysubscription_autorest.go new file mode 100644 index 00000000000..58dbe5fa507 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listbysubscription_autorest.go @@ -0,0 +1,187 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]WebPubSubResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []WebPubSubResource +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c WebPubSubClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c WebPubSubClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SignalRService/webPubSub", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c WebPubSubClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []WebPubSubResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c WebPubSubClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, WebPubSubResourceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate WebPubSubResourceOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]WebPubSubResource, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_listkeys_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listkeys_autorest.go new file mode 100644 index 00000000000..720b9f34e68 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listkeys_autorest.go @@ -0,0 +1,69 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListKeysOperationResponse struct { + HttpResponse *http.Response + Model *WebPubSubKeys +} + +// ListKeys ... +func (c WebPubSubClient) ListKeys(ctx context.Context, id WebPubSubId) (result ListKeysOperationResponse, err error) { + req, err := c.preparerForListKeys(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListKeys", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListKeys", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListKeys(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListKeys", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListKeys prepares the ListKeys request. +func (c WebPubSubClient) preparerForListKeys(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/listKeys", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListKeys handles the response to the ListKeys request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForListKeys(resp *http.Response) (result ListKeysOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_listskus_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listskus_autorest.go new file mode 100644 index 00000000000..75385a27e31 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_listskus_autorest.go @@ -0,0 +1,69 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListSkusOperationResponse struct { + HttpResponse *http.Response + Model *SkuList +} + +// ListSkus ... +func (c WebPubSubClient) ListSkus(ctx context.Context, id WebPubSubId) (result ListSkusOperationResponse, err error) { + req, err := c.preparerForListSkus(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListSkus", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListSkus", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListSkus(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "ListSkus", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForListSkus prepares the ListSkus request. +func (c WebPubSubClient) preparerForListSkus(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/skus", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListSkus handles the response to the ListSkus request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForListSkus(resp *http.Response) (result ListSkusOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsdelete_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsdelete_autorest.go new file mode 100644 index 00000000000..e2e61479e52 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsdelete_autorest.go @@ -0,0 +1,78 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsDeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// PrivateEndpointConnectionsDelete ... +func (c WebPubSubClient) PrivateEndpointConnectionsDelete(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsDeleteOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForPrivateEndpointConnectionsDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// PrivateEndpointConnectionsDeleteThenPoll performs PrivateEndpointConnectionsDelete then polls until it's completed +func (c WebPubSubClient) PrivateEndpointConnectionsDeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.PrivateEndpointConnectionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing PrivateEndpointConnectionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after PrivateEndpointConnectionsDelete: %+v", err) + } + + return nil +} + +// preparerForPrivateEndpointConnectionsDelete prepares the PrivateEndpointConnectionsDelete request. +func (c WebPubSubClient) preparerForPrivateEndpointConnectionsDelete(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForPrivateEndpointConnectionsDelete sends the PrivateEndpointConnectionsDelete request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForPrivateEndpointConnectionsDelete(ctx context.Context, req *http.Request) (future PrivateEndpointConnectionsDeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsget_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsget_autorest.go new file mode 100644 index 00000000000..01679cb955d --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsget_autorest.go @@ -0,0 +1,68 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsGetOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnection +} + +// PrivateEndpointConnectionsGet ... +func (c WebPubSubClient) PrivateEndpointConnectionsGet(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionsGetOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsGet prepares the PrivateEndpointConnectionsGet request. +func (c WebPubSubClient) preparerForPrivateEndpointConnectionsGet(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsGet handles the response to the PrivateEndpointConnectionsGet request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForPrivateEndpointConnectionsGet(resp *http.Response) (result PrivateEndpointConnectionsGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionslist_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionslist_autorest.go new file mode 100644 index 00000000000..1ee81685347 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionslist_autorest.go @@ -0,0 +1,186 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsListOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateEndpointConnection + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (PrivateEndpointConnectionsListOperationResponse, error) +} + +type PrivateEndpointConnectionsListCompleteResult struct { + Items []PrivateEndpointConnection +} + +func (r PrivateEndpointConnectionsListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r PrivateEndpointConnectionsListOperationResponse) LoadMore(ctx context.Context) (resp PrivateEndpointConnectionsListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// PrivateEndpointConnectionsList ... +func (c WebPubSubClient) PrivateEndpointConnectionsList(ctx context.Context, id WebPubSubId) (resp PrivateEndpointConnectionsListOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForPrivateEndpointConnectionsList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForPrivateEndpointConnectionsList prepares the PrivateEndpointConnectionsList request. +func (c WebPubSubClient) preparerForPrivateEndpointConnectionsList(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForPrivateEndpointConnectionsListWithNextLink prepares the PrivateEndpointConnectionsList request with the given nextLink token. +func (c WebPubSubClient) preparerForPrivateEndpointConnectionsListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsList handles the response to the PrivateEndpointConnectionsList request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForPrivateEndpointConnectionsList(resp *http.Response) (result PrivateEndpointConnectionsListOperationResponse, err error) { + type page struct { + Values []PrivateEndpointConnection `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result PrivateEndpointConnectionsListOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// PrivateEndpointConnectionsListComplete retrieves all of the results into a single object +func (c WebPubSubClient) PrivateEndpointConnectionsListComplete(ctx context.Context, id WebPubSubId) (PrivateEndpointConnectionsListCompleteResult, error) { + return c.PrivateEndpointConnectionsListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// PrivateEndpointConnectionsListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) PrivateEndpointConnectionsListCompleteMatchingPredicate(ctx context.Context, id WebPubSubId, predicate PrivateEndpointConnectionOperationPredicate) (resp PrivateEndpointConnectionsListCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + page, err := c.PrivateEndpointConnectionsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := PrivateEndpointConnectionsListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsupdate_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsupdate_autorest.go new file mode 100644 index 00000000000..dd813e5b147 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privateendpointconnectionsupdate_autorest.go @@ -0,0 +1,69 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsUpdateOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnection +} + +// PrivateEndpointConnectionsUpdate ... +func (c WebPubSubClient) PrivateEndpointConnectionsUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateOperationResponse, err error) { + req, err := c.preparerForPrivateEndpointConnectionsUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateEndpointConnectionsUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateEndpointConnectionsUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForPrivateEndpointConnectionsUpdate prepares the PrivateEndpointConnectionsUpdate request. +func (c WebPubSubClient) preparerForPrivateEndpointConnectionsUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateEndpointConnectionsUpdate handles the response to the PrivateEndpointConnectionsUpdate request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForPrivateEndpointConnectionsUpdate(resp *http.Response) (result PrivateEndpointConnectionsUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_privatelinkresourceslist_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privatelinkresourceslist_autorest.go new file mode 100644 index 00000000000..1ddc3adc529 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_privatelinkresourceslist_autorest.go @@ -0,0 +1,186 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesListOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateLinkResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (PrivateLinkResourcesListOperationResponse, error) +} + +type PrivateLinkResourcesListCompleteResult struct { + Items []PrivateLinkResource +} + +func (r PrivateLinkResourcesListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r PrivateLinkResourcesListOperationResponse) LoadMore(ctx context.Context) (resp PrivateLinkResourcesListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// PrivateLinkResourcesList ... +func (c WebPubSubClient) PrivateLinkResourcesList(ctx context.Context, id WebPubSubId) (resp PrivateLinkResourcesListOperationResponse, err error) { + req, err := c.preparerForPrivateLinkResourcesList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateLinkResourcesList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateLinkResourcesList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForPrivateLinkResourcesList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateLinkResourcesList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForPrivateLinkResourcesList prepares the PrivateLinkResourcesList request. +func (c WebPubSubClient) preparerForPrivateLinkResourcesList(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForPrivateLinkResourcesListWithNextLink prepares the PrivateLinkResourcesList request with the given nextLink token. +func (c WebPubSubClient) preparerForPrivateLinkResourcesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForPrivateLinkResourcesList handles the response to the PrivateLinkResourcesList request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForPrivateLinkResourcesList(resp *http.Response) (result PrivateLinkResourcesListOperationResponse, err error) { + type page struct { + Values []PrivateLinkResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result PrivateLinkResourcesListOperationResponse, err error) { + req, err := c.preparerForPrivateLinkResourcesListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateLinkResourcesList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateLinkResourcesList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForPrivateLinkResourcesList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "PrivateLinkResourcesList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// PrivateLinkResourcesListComplete retrieves all of the results into a single object +func (c WebPubSubClient) PrivateLinkResourcesListComplete(ctx context.Context, id WebPubSubId) (PrivateLinkResourcesListCompleteResult, error) { + return c.PrivateLinkResourcesListCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// PrivateLinkResourcesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) PrivateLinkResourcesListCompleteMatchingPredicate(ctx context.Context, id WebPubSubId, predicate PrivateLinkResourceOperationPredicate) (resp PrivateLinkResourcesListCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + page, err := c.PrivateLinkResourcesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := PrivateLinkResourcesListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_regeneratekey_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_regeneratekey_autorest.go new file mode 100644 index 00000000000..f020b148e9d --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_regeneratekey_autorest.go @@ -0,0 +1,79 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// RegenerateKey ... +func (c WebPubSubClient) RegenerateKey(ctx context.Context, id WebPubSubId, input RegenerateKeyParameters) (result RegenerateKeyOperationResponse, err error) { + req, err := c.preparerForRegenerateKey(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "RegenerateKey", nil, "Failure preparing request") + return + } + + result, err = c.senderForRegenerateKey(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "RegenerateKey", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RegenerateKeyThenPoll performs RegenerateKey then polls until it's completed +func (c WebPubSubClient) RegenerateKeyThenPoll(ctx context.Context, id WebPubSubId, input RegenerateKeyParameters) error { + result, err := c.RegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after RegenerateKey: %+v", err) + } + + return nil +} + +// preparerForRegenerateKey prepares the RegenerateKey request. +func (c WebPubSubClient) preparerForRegenerateKey(ctx context.Context, id WebPubSubId, input RegenerateKeyParameters) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/regenerateKey", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRegenerateKey sends the RegenerateKey request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForRegenerateKey(ctx context.Context, req *http.Request) (future RegenerateKeyOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_restart_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_restart_autorest.go new file mode 100644 index 00000000000..472b5281352 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_restart_autorest.go @@ -0,0 +1,78 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestartOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Restart ... +func (c WebPubSubClient) Restart(ctx context.Context, id WebPubSubId) (result RestartOperationResponse, err error) { + req, err := c.preparerForRestart(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Restart", nil, "Failure preparing request") + return + } + + result, err = c.senderForRestart(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Restart", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// RestartThenPoll performs Restart then polls until it's completed +func (c WebPubSubClient) RestartThenPoll(ctx context.Context, id WebPubSubId) error { + result, err := c.Restart(ctx, id) + if err != nil { + return fmt.Errorf("performing Restart: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Restart: %+v", err) + } + + return nil +} + +// preparerForRestart prepares the Restart request. +func (c WebPubSubClient) preparerForRestart(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/restart", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForRestart sends the Restart request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForRestart(ctx context.Context, req *http.Request) (future RestartOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcescreateorupdate_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcescreateorupdate_autorest.go new file mode 100644 index 00000000000..f1ac7645475 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcescreateorupdate_autorest.go @@ -0,0 +1,79 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedPrivateLinkResourcesCreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// SharedPrivateLinkResourcesCreateOrUpdate ... +func (c WebPubSubClient) SharedPrivateLinkResourcesCreateOrUpdate(ctx context.Context, id SharedPrivateLinkResourceId, input SharedPrivateLinkResource) (result SharedPrivateLinkResourcesCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForSharedPrivateLinkResourcesCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesCreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForSharedPrivateLinkResourcesCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// SharedPrivateLinkResourcesCreateOrUpdateThenPoll performs SharedPrivateLinkResourcesCreateOrUpdate then polls until it's completed +func (c WebPubSubClient) SharedPrivateLinkResourcesCreateOrUpdateThenPoll(ctx context.Context, id SharedPrivateLinkResourceId, input SharedPrivateLinkResource) error { + result, err := c.SharedPrivateLinkResourcesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SharedPrivateLinkResourcesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after SharedPrivateLinkResourcesCreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForSharedPrivateLinkResourcesCreateOrUpdate prepares the SharedPrivateLinkResourcesCreateOrUpdate request. +func (c WebPubSubClient) preparerForSharedPrivateLinkResourcesCreateOrUpdate(ctx context.Context, id SharedPrivateLinkResourceId, input SharedPrivateLinkResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForSharedPrivateLinkResourcesCreateOrUpdate sends the SharedPrivateLinkResourcesCreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForSharedPrivateLinkResourcesCreateOrUpdate(ctx context.Context, req *http.Request) (future SharedPrivateLinkResourcesCreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcesdelete_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcesdelete_autorest.go new file mode 100644 index 00000000000..2a78d27a8b8 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcesdelete_autorest.go @@ -0,0 +1,78 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedPrivateLinkResourcesDeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// SharedPrivateLinkResourcesDelete ... +func (c WebPubSubClient) SharedPrivateLinkResourcesDelete(ctx context.Context, id SharedPrivateLinkResourceId) (result SharedPrivateLinkResourcesDeleteOperationResponse, err error) { + req, err := c.preparerForSharedPrivateLinkResourcesDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForSharedPrivateLinkResourcesDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// SharedPrivateLinkResourcesDeleteThenPoll performs SharedPrivateLinkResourcesDelete then polls until it's completed +func (c WebPubSubClient) SharedPrivateLinkResourcesDeleteThenPoll(ctx context.Context, id SharedPrivateLinkResourceId) error { + result, err := c.SharedPrivateLinkResourcesDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing SharedPrivateLinkResourcesDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after SharedPrivateLinkResourcesDelete: %+v", err) + } + + return nil +} + +// preparerForSharedPrivateLinkResourcesDelete prepares the SharedPrivateLinkResourcesDelete request. +func (c WebPubSubClient) preparerForSharedPrivateLinkResourcesDelete(ctx context.Context, id SharedPrivateLinkResourceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForSharedPrivateLinkResourcesDelete sends the SharedPrivateLinkResourcesDelete request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForSharedPrivateLinkResourcesDelete(ctx context.Context, req *http.Request) (future SharedPrivateLinkResourcesDeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcesget_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcesget_autorest.go new file mode 100644 index 00000000000..8ad0ec32f17 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourcesget_autorest.go @@ -0,0 +1,68 @@ +package webpubsub + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedPrivateLinkResourcesGetOperationResponse struct { + HttpResponse *http.Response + Model *SharedPrivateLinkResource +} + +// SharedPrivateLinkResourcesGet ... +func (c WebPubSubClient) SharedPrivateLinkResourcesGet(ctx context.Context, id SharedPrivateLinkResourceId) (result SharedPrivateLinkResourcesGetOperationResponse, err error) { + req, err := c.preparerForSharedPrivateLinkResourcesGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSharedPrivateLinkResourcesGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSharedPrivateLinkResourcesGet prepares the SharedPrivateLinkResourcesGet request. +func (c WebPubSubClient) preparerForSharedPrivateLinkResourcesGet(ctx context.Context, id SharedPrivateLinkResourceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSharedPrivateLinkResourcesGet handles the response to the SharedPrivateLinkResourcesGet request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForSharedPrivateLinkResourcesGet(resp *http.Response) (result SharedPrivateLinkResourcesGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourceslist_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourceslist_autorest.go new file mode 100644 index 00000000000..3210645f02c --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_sharedprivatelinkresourceslist_autorest.go @@ -0,0 +1,186 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedPrivateLinkResourcesListOperationResponse struct { + HttpResponse *http.Response + Model *[]SharedPrivateLinkResource + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (SharedPrivateLinkResourcesListOperationResponse, error) +} + +type SharedPrivateLinkResourcesListCompleteResult struct { + Items []SharedPrivateLinkResource +} + +func (r SharedPrivateLinkResourcesListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r SharedPrivateLinkResourcesListOperationResponse) LoadMore(ctx context.Context) (resp SharedPrivateLinkResourcesListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// SharedPrivateLinkResourcesList ... +func (c WebPubSubClient) SharedPrivateLinkResourcesList(ctx context.Context, id WebPubSubId) (resp SharedPrivateLinkResourcesListOperationResponse, err error) { + req, err := c.preparerForSharedPrivateLinkResourcesList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForSharedPrivateLinkResourcesList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForSharedPrivateLinkResourcesList prepares the SharedPrivateLinkResourcesList request. +func (c WebPubSubClient) preparerForSharedPrivateLinkResourcesList(ctx context.Context, id WebPubSubId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/sharedPrivateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForSharedPrivateLinkResourcesListWithNextLink prepares the SharedPrivateLinkResourcesList request with the given nextLink token. +func (c WebPubSubClient) preparerForSharedPrivateLinkResourcesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSharedPrivateLinkResourcesList handles the response to the SharedPrivateLinkResourcesList request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForSharedPrivateLinkResourcesList(resp *http.Response) (result SharedPrivateLinkResourcesListOperationResponse, err error) { + type page struct { + Values []SharedPrivateLinkResource `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result SharedPrivateLinkResourcesListOperationResponse, err error) { + req, err := c.preparerForSharedPrivateLinkResourcesListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSharedPrivateLinkResourcesList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "SharedPrivateLinkResourcesList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// SharedPrivateLinkResourcesListComplete retrieves all of the results into a single object +func (c WebPubSubClient) SharedPrivateLinkResourcesListComplete(ctx context.Context, id WebPubSubId) (SharedPrivateLinkResourcesListCompleteResult, error) { + return c.SharedPrivateLinkResourcesListCompleteMatchingPredicate(ctx, id, SharedPrivateLinkResourceOperationPredicate{}) +} + +// SharedPrivateLinkResourcesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) SharedPrivateLinkResourcesListCompleteMatchingPredicate(ctx context.Context, id WebPubSubId, predicate SharedPrivateLinkResourceOperationPredicate) (resp SharedPrivateLinkResourcesListCompleteResult, err error) { + items := make([]SharedPrivateLinkResource, 0) + + page, err := c.SharedPrivateLinkResourcesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := SharedPrivateLinkResourcesListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_update_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_update_autorest.go new file mode 100644 index 00000000000..849c6e6b9a6 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_update_autorest.go @@ -0,0 +1,79 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// 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 polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c WebPubSubClient) Update(ctx context.Context, id WebPubSubId, input WebPubSubResource) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c WebPubSubClient) UpdateThenPoll(ctx context.Context, id WebPubSubId, input WebPubSubResource) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c WebPubSubClient) preparerForUpdate(ctx context.Context, id WebPubSubId, input WebPubSubResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c WebPubSubClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/method_usageslist_autorest.go b/resource-manager/webpubsub/2023-02-01/webpubsub/method_usageslist_autorest.go new file mode 100644 index 00000000000..7d4593e77ff --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/method_usageslist_autorest.go @@ -0,0 +1,186 @@ +package webpubsub + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsagesListOperationResponse struct { + HttpResponse *http.Response + Model *[]SignalRServiceUsage + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (UsagesListOperationResponse, error) +} + +type UsagesListCompleteResult struct { + Items []SignalRServiceUsage +} + +func (r UsagesListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r UsagesListOperationResponse) LoadMore(ctx context.Context) (resp UsagesListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// UsagesList ... +func (c WebPubSubClient) UsagesList(ctx context.Context, id LocationId) (resp UsagesListOperationResponse, err error) { + req, err := c.preparerForUsagesList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "UsagesList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "UsagesList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForUsagesList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "UsagesList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForUsagesList prepares the UsagesList request. +func (c WebPubSubClient) preparerForUsagesList(ctx context.Context, id LocationId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/usages", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForUsagesListWithNextLink prepares the UsagesList request with the given nextLink token. +func (c WebPubSubClient) preparerForUsagesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUsagesList handles the response to the UsagesList request. The method always +// closes the http.Response Body. +func (c WebPubSubClient) responderForUsagesList(resp *http.Response) (result UsagesListOperationResponse, err error) { + type page struct { + Values []SignalRServiceUsage `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result UsagesListOperationResponse, err error) { + req, err := c.preparerForUsagesListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "UsagesList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "UsagesList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUsagesList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "webpubsub.WebPubSubClient", "UsagesList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// UsagesListComplete retrieves all of the results into a single object +func (c WebPubSubClient) UsagesListComplete(ctx context.Context, id LocationId) (UsagesListCompleteResult, error) { + return c.UsagesListCompleteMatchingPredicate(ctx, id, SignalRServiceUsageOperationPredicate{}) +} + +// UsagesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c WebPubSubClient) UsagesListCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate SignalRServiceUsageOperationPredicate) (resp UsagesListCompleteResult, err error) { + items := make([]SignalRServiceUsage, 0) + + page, err := c.UsagesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := UsagesListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_customcertificate.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customcertificate.go new file mode 100644 index 00000000000..34ae5c01616 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customcertificate.go @@ -0,0 +1,16 @@ +package webpubsub + +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 CustomCertificate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties CustomCertificateProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_customcertificateproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customcertificateproperties.go new file mode 100644 index 00000000000..575e62cf8db --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customcertificateproperties.go @@ -0,0 +1,11 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificateProperties struct { + KeyVaultBaseUri string `json:"keyVaultBaseUri"` + KeyVaultSecretName string `json:"keyVaultSecretName"` + KeyVaultSecretVersion *string `json:"keyVaultSecretVersion,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_customdomain.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customdomain.go new file mode 100644 index 00000000000..88b7f901e11 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customdomain.go @@ -0,0 +1,16 @@ +package webpubsub + +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 CustomDomain struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties CustomDomainProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_customdomainproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customdomainproperties.go new file mode 100644 index 00000000000..9d174af7c37 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_customdomainproperties.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainProperties struct { + CustomCertificate ResourceReference `json:"customCertificate"` + DomainName string `json:"domainName"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventhandler.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventhandler.go new file mode 100644 index 00000000000..40e7c23a86c --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventhandler.go @@ -0,0 +1,11 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventHandler struct { + Auth *UpstreamAuthSettings `json:"auth,omitempty"` + SystemEvents *[]string `json:"systemEvents,omitempty"` + UrlTemplate string `json:"urlTemplate"` + UserEventPattern *string `json:"userEventPattern,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventhubendpoint.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventhubendpoint.go new file mode 100644 index 00000000000..b4b3bfbb021 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventhubendpoint.go @@ -0,0 +1,42 @@ +package webpubsub + +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 _ EventListenerEndpoint = EventHubEndpoint{} + +type EventHubEndpoint struct { + EventHubName string `json:"eventHubName"` + FullyQualifiedNamespace string `json:"fullyQualifiedNamespace"` + + // Fields inherited from EventListenerEndpoint +} + +var _ json.Marshaler = EventHubEndpoint{} + +func (s EventHubEndpoint) MarshalJSON() ([]byte, error) { + type wrapper EventHubEndpoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling EventHubEndpoint: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling EventHubEndpoint: %+v", err) + } + decoded["type"] = "EventHub" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling EventHubEndpoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistener.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistener.go new file mode 100644 index 00000000000..90cf91c8ab5 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistener.go @@ -0,0 +1,41 @@ +package webpubsub + +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 EventListener struct { + Endpoint EventListenerEndpoint `json:"endpoint"` + Filter EventListenerFilter `json:"filter"` +} + +var _ json.Unmarshaler = &EventListener{} + +func (s *EventListener) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EventListener into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["endpoint"]; ok { + impl, err := unmarshalEventListenerEndpointImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Endpoint' for 'EventListener': %+v", err) + } + s.Endpoint = impl + } + + if v, ok := temp["filter"]; ok { + impl, err := unmarshalEventListenerFilterImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Filter' for 'EventListener': %+v", err) + } + s.Filter = impl + } + return nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistenerendpoint.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistenerendpoint.go new file mode 100644 index 00000000000..27ebf7eb798 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistenerendpoint.go @@ -0,0 +1,48 @@ +package webpubsub + +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 EventListenerEndpoint interface { +} + +func unmarshalEventListenerEndpointImplementation(input []byte) (EventListenerEndpoint, 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 EventListenerEndpoint into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "EventHub") { + var out EventHubEndpoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into EventHubEndpoint: %+v", err) + } + return out, nil + } + + type RawEventListenerEndpointImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawEventListenerEndpointImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistenerfilter.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistenerfilter.go new file mode 100644 index 00000000000..e51f84c201e --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventlistenerfilter.go @@ -0,0 +1,48 @@ +package webpubsub + +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 EventListenerFilter interface { +} + +func unmarshalEventListenerFilterImplementation(input []byte) (EventListenerFilter, 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 EventListenerFilter into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "EventName") { + var out EventNameFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into EventNameFilter: %+v", err) + } + return out, nil + } + + type RawEventListenerFilterImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawEventListenerFilterImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventnamefilter.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventnamefilter.go new file mode 100644 index 00000000000..463f1dc90e6 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_eventnamefilter.go @@ -0,0 +1,42 @@ +package webpubsub + +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 _ EventListenerFilter = EventNameFilter{} + +type EventNameFilter struct { + SystemEvents *[]string `json:"systemEvents,omitempty"` + UserEventPattern *string `json:"userEventPattern,omitempty"` + + // Fields inherited from EventListenerFilter +} + +var _ json.Marshaler = EventNameFilter{} + +func (s EventNameFilter) MarshalJSON() ([]byte, error) { + type wrapper EventNameFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling EventNameFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling EventNameFilter: %+v", err) + } + decoded["type"] = "EventName" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling EventNameFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_livetracecategory.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_livetracecategory.go new file mode 100644 index 00000000000..ff3f83b52fd --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_livetracecategory.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LiveTraceCategory struct { + Enabled *string `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_livetraceconfiguration.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_livetraceconfiguration.go new file mode 100644 index 00000000000..77ef6113750 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_livetraceconfiguration.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LiveTraceConfiguration struct { + Categories *[]LiveTraceCategory `json:"categories,omitempty"` + Enabled *string `json:"enabled,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_managedidentitysettings.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_managedidentitysettings.go new file mode 100644 index 00000000000..b7f74ab307d --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_managedidentitysettings.go @@ -0,0 +1,8 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentitySettings struct { + Resource *string `json:"resource,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_nameavailability.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_nameavailability.go new file mode 100644 index 00000000000..0fe7d3a1e28 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_nameavailability.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameAvailability struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_nameavailabilityparameters.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_nameavailabilityparameters.go new file mode 100644 index 00000000000..25cb3ef8050 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_nameavailabilityparameters.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameAvailabilityParameters struct { + Name string `json:"name"` + Type string `json:"type"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_networkacl.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_networkacl.go new file mode 100644 index 00000000000..094d10f8585 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_networkacl.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkACL struct { + Allow *[]WebPubSubRequestType `json:"allow,omitempty"` + Deny *[]WebPubSubRequestType `json:"deny,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpoint.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpoint.go new file mode 100644 index 00000000000..8f4efa3fed6 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpoint.go @@ -0,0 +1,8 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointacl.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointacl.go new file mode 100644 index 00000000000..f67306d29fc --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointacl.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointACL struct { + Allow *[]WebPubSubRequestType `json:"allow,omitempty"` + Deny *[]WebPubSubRequestType `json:"deny,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointconnection.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointconnection.go new file mode 100644 index 00000000000..aa992a97737 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package webpubsub + +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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointconnectionproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..33dbc1679d1 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkresource.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkresource.go new file mode 100644 index 00000000000..577389fd752 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkresourceproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..b5a4a0b2bff --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkresourceproperties.go @@ -0,0 +1,11 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` + ShareablePrivateLinkResourceTypes *[]ShareablePrivateLinkResourceType `json:"shareablePrivateLinkResourceTypes,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkserviceconnectionstate.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..8fc24854c88 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateLinkServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_regeneratekeyparameters.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_regeneratekeyparameters.go new file mode 100644 index 00000000000..ba779dc889c --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_regeneratekeyparameters.go @@ -0,0 +1,8 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyParameters struct { + KeyType *KeyType `json:"keyType,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcelogcategory.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcelogcategory.go new file mode 100644 index 00000000000..d0c22062b89 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcelogcategory.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceLogCategory struct { + Enabled *string `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcelogconfiguration.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcelogconfiguration.go new file mode 100644 index 00000000000..32bc381d5e3 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcelogconfiguration.go @@ -0,0 +1,8 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceLogConfiguration struct { + Categories *[]ResourceLogCategory `json:"categories,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcereference.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcereference.go new file mode 100644 index 00000000000..840024a75cb --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcereference.go @@ -0,0 +1,8 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceReference struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcesku.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcesku.go new file mode 100644 index 00000000000..d8c057983d9 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_resourcesku.go @@ -0,0 +1,12 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSku struct { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *WebPubSubSkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_shareableprivatelinkresourceproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_shareableprivatelinkresourceproperties.go new file mode 100644 index 00000000000..087f82ce696 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_shareableprivatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShareablePrivateLinkResourceProperties struct { + Description *string `json:"description,omitempty"` + GroupId *string `json:"groupId,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_shareableprivatelinkresourcetype.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_shareableprivatelinkresourcetype.go new file mode 100644 index 00000000000..28dca622f86 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_shareableprivatelinkresourcetype.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShareablePrivateLinkResourceType struct { + Name *string `json:"name,omitempty"` + Properties *ShareablePrivateLinkResourceProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_sharedprivatelinkresource.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_sharedprivatelinkresource.go new file mode 100644 index 00000000000..c88fe5206b6 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_sharedprivatelinkresource.go @@ -0,0 +1,16 @@ +package webpubsub + +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 SharedPrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SharedPrivateLinkResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_sharedprivatelinkresourceproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_sharedprivatelinkresourceproperties.go new file mode 100644 index 00000000000..2dc1a04a7f0 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_sharedprivatelinkresourceproperties.go @@ -0,0 +1,12 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedPrivateLinkResourceProperties struct { + GroupId string `json:"groupId"` + PrivateLinkResourceId string `json:"privateLinkResourceId"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RequestMessage *string `json:"requestMessage,omitempty"` + Status *SharedPrivateLinkResourceStatus `json:"status,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_signalrserviceusage.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_signalrserviceusage.go new file mode 100644 index 00000000000..be99716017d --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_signalrserviceusage.go @@ -0,0 +1,12 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRServiceUsage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Id *string `json:"id,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *SignalRServiceUsageName `json:"name,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_signalrserviceusagename.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_signalrserviceusagename.go new file mode 100644 index 00000000000..5a9e390b6e0 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_signalrserviceusagename.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SignalRServiceUsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_sku.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_sku.go new file mode 100644 index 00000000000..e1b1b8cca15 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_sku.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *SkuCapacity `json:"capacity,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_skucapacity.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_skucapacity.go new file mode 100644 index 00000000000..40b1840f099 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_skucapacity.go @@ -0,0 +1,12 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuCapacity struct { + AllowedValues *[]int64 `json:"allowedValues,omitempty"` + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + ScaleType *ScaleType `json:"scaleType,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_skulist.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_skulist.go new file mode 100644 index 00000000000..8dd63ac3713 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_skulist.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuList struct { + NextLink *string `json:"nextLink,omitempty"` + Value *[]Sku `json:"value,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_upstreamauthsettings.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_upstreamauthsettings.go new file mode 100644 index 00000000000..14040c68d7b --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_upstreamauthsettings.go @@ -0,0 +1,9 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpstreamAuthSettings struct { + ManagedIdentity *ManagedIdentitySettings `json:"managedIdentity,omitempty"` + Type *UpstreamAuthType `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubhub.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubhub.go new file mode 100644 index 00000000000..be327da6dd0 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubhub.go @@ -0,0 +1,16 @@ +package webpubsub + +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 WebPubSubHub struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties WebPubSubHubProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubhubproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubhubproperties.go new file mode 100644 index 00000000000..60acfd8ca0e --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubhubproperties.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebPubSubHubProperties struct { + AnonymousConnectPolicy *string `json:"anonymousConnectPolicy,omitempty"` + EventHandlers *[]EventHandler `json:"eventHandlers,omitempty"` + EventListeners *[]EventListener `json:"eventListeners,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubkeys.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubkeys.go new file mode 100644 index 00000000000..3b4c98384f0 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubkeys.go @@ -0,0 +1,11 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebPubSubKeys struct { + PrimaryConnectionString *string `json:"primaryConnectionString,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryConnectionString *string `json:"secondaryConnectionString,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubnetworkacls.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubnetworkacls.go new file mode 100644 index 00000000000..47f42ef26eb --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubnetworkacls.go @@ -0,0 +1,10 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebPubSubNetworkACLs struct { + DefaultAction *ACLAction `json:"defaultAction,omitempty"` + PrivateEndpoints *[]PrivateEndpointACL `json:"privateEndpoints,omitempty"` + PublicNetwork *NetworkACL `json:"publicNetwork,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubproperties.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubproperties.go new file mode 100644 index 00000000000..86cec717990 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubproperties.go @@ -0,0 +1,23 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebPubSubProperties struct { + DisableAadAuth *bool `json:"disableAadAuth,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + ExternalIP *string `json:"externalIP,omitempty"` + HostName *string `json:"hostName,omitempty"` + HostNamePrefix *string `json:"hostNamePrefix,omitempty"` + LiveTraceConfiguration *LiveTraceConfiguration `json:"liveTraceConfiguration,omitempty"` + NetworkACLs *WebPubSubNetworkACLs `json:"networkACLs,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *string `json:"publicNetworkAccess,omitempty"` + PublicPort *int64 `json:"publicPort,omitempty"` + ResourceLogConfiguration *ResourceLogConfiguration `json:"resourceLogConfiguration,omitempty"` + ServerPort *int64 `json:"serverPort,omitempty"` + SharedPrivateLinkResources *[]SharedPrivateLinkResource `json:"sharedPrivateLinkResources,omitempty"` + Tls *WebPubSubTlsSettings `json:"tls,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubresource.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubresource.go new file mode 100644 index 00000000000..31f8716c177 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubresource.go @@ -0,0 +1,21 @@ +package webpubsub + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebPubSubResource struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemOrUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WebPubSubProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubtlssettings.go b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubtlssettings.go new file mode 100644 index 00000000000..86fe02ce896 --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/model_webpubsubtlssettings.go @@ -0,0 +1,8 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebPubSubTlsSettings struct { + ClientCertEnabled *bool `json:"clientCertEnabled,omitempty"` +} diff --git a/resource-manager/webpubsub/2023-02-01/webpubsub/predicates.go b/resource-manager/webpubsub/2023-02-01/webpubsub/predicates.go new file mode 100644 index 00000000000..4e24b2d5a6c --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/predicates.go @@ -0,0 +1,198 @@ +package webpubsub + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomCertificateOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CustomCertificateOperationPredicate) Matches(input CustomCertificate) 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 CustomDomainOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CustomDomainOperationPredicate) Matches(input CustomDomain) 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 PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} + +type SharedPrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SharedPrivateLinkResourceOperationPredicate) Matches(input SharedPrivateLinkResource) 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 SignalRServiceUsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 + Unit *string +} + +func (p SignalRServiceUsageOperationPredicate) Matches(input SignalRServiceUsage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil && *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Limit != nil && (input.Limit == nil && *p.Limit != *input.Limit) { + return false + } + + if p.Unit != nil && (input.Unit == nil && *p.Unit != *input.Unit) { + return false + } + + return true +} + +type WebPubSubHubOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WebPubSubHubOperationPredicate) Matches(input WebPubSubHub) 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 WebPubSubResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p WebPubSubResourceOperationPredicate) Matches(input WebPubSubResource) bool { + + 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/webpubsub/2023-02-01/webpubsub/version.go b/resource-manager/webpubsub/2023-02-01/webpubsub/version.go new file mode 100644 index 00000000000..1d23e8c8c4a --- /dev/null +++ b/resource-manager/webpubsub/2023-02-01/webpubsub/version.go @@ -0,0 +1,12 @@ +package webpubsub + +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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/webpubsub/%s", defaultApiVersion) +}