diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/README.md b/resource-manager/cdn/2024-02-01/afdcustomdomains/README.md new file mode 100644 index 00000000000..3a4d65af610 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdcustomdomains` Documentation + +The `afdcustomdomains` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/afdcustomdomains" +``` + + +### Client Initialization + +```go +client := afdcustomdomains.NewAFDCustomDomainsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AFDCustomDomainsClient.Create` + +```go +ctx := context.TODO() +id := afdcustomdomains.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "customDomainValue") + +payload := afdcustomdomains.AFDDomain{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDCustomDomainsClient.Delete` + +```go +ctx := context.TODO() +id := afdcustomdomains.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "customDomainValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDCustomDomainsClient.Get` + +```go +ctx := context.TODO() +id := afdcustomdomains.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "customDomainValue") + +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: `AFDCustomDomainsClient.ListByProfile` + +```go +ctx := context.TODO() +id := afdcustomdomains.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AFDCustomDomainsClient.RefreshValidationToken` + +```go +ctx := context.TODO() +id := afdcustomdomains.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "customDomainValue") + +if err := client.RefreshValidationTokenThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDCustomDomainsClient.Update` + +```go +ctx := context.TODO() +id := afdcustomdomains.NewCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "customDomainValue") + +payload := afdcustomdomains.AFDDomainUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/client.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/client.go new file mode 100644 index 00000000000..6a549fd9f0a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/client.go @@ -0,0 +1,26 @@ +package afdcustomdomains + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDCustomDomainsClient struct { + Client *resourcemanager.Client +} + +func NewAFDCustomDomainsClientWithBaseURI(sdkApi sdkEnv.Api) (*AFDCustomDomainsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "afdcustomdomains", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AFDCustomDomainsClient: %+v", err) + } + + return &AFDCustomDomainsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/constants.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/constants.go new file mode 100644 index 00000000000..c0d8c92ef84 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/constants.go @@ -0,0 +1,254 @@ +package afdcustomdomains + +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 AfdCertificateType string + +const ( + AfdCertificateTypeAzureFirstPartyManagedCertificate AfdCertificateType = "AzureFirstPartyManagedCertificate" + AfdCertificateTypeCustomerCertificate AfdCertificateType = "CustomerCertificate" + AfdCertificateTypeManagedCertificate AfdCertificateType = "ManagedCertificate" +) + +func PossibleValuesForAfdCertificateType() []string { + return []string{ + string(AfdCertificateTypeAzureFirstPartyManagedCertificate), + string(AfdCertificateTypeCustomerCertificate), + string(AfdCertificateTypeManagedCertificate), + } +} + +func (s *AfdCertificateType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdCertificateType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdCertificateType(input string) (*AfdCertificateType, error) { + vals := map[string]AfdCertificateType{ + "azurefirstpartymanagedcertificate": AfdCertificateTypeAzureFirstPartyManagedCertificate, + "customercertificate": AfdCertificateTypeCustomerCertificate, + "managedcertificate": AfdCertificateTypeManagedCertificate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdCertificateType(input) + return &out, nil +} + +type AfdMinimumTlsVersion string + +const ( + AfdMinimumTlsVersionTLSOneTwo AfdMinimumTlsVersion = "TLS12" + AfdMinimumTlsVersionTLSOneZero AfdMinimumTlsVersion = "TLS10" +) + +func PossibleValuesForAfdMinimumTlsVersion() []string { + return []string{ + string(AfdMinimumTlsVersionTLSOneTwo), + string(AfdMinimumTlsVersionTLSOneZero), + } +} + +func (s *AfdMinimumTlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdMinimumTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdMinimumTlsVersion(input string) (*AfdMinimumTlsVersion, error) { + vals := map[string]AfdMinimumTlsVersion{ + "tls12": AfdMinimumTlsVersionTLSOneTwo, + "tls10": AfdMinimumTlsVersionTLSOneZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdMinimumTlsVersion(input) + return &out, nil +} + +type AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type DomainValidationState string + +const ( + DomainValidationStateApproved DomainValidationState = "Approved" + DomainValidationStateInternalError DomainValidationState = "InternalError" + DomainValidationStatePending DomainValidationState = "Pending" + DomainValidationStatePendingRevalidation DomainValidationState = "PendingRevalidation" + DomainValidationStateRefreshingValidationToken DomainValidationState = "RefreshingValidationToken" + DomainValidationStateRejected DomainValidationState = "Rejected" + DomainValidationStateSubmitting DomainValidationState = "Submitting" + DomainValidationStateTimedOut DomainValidationState = "TimedOut" + DomainValidationStateUnknown DomainValidationState = "Unknown" +) + +func PossibleValuesForDomainValidationState() []string { + return []string{ + string(DomainValidationStateApproved), + string(DomainValidationStateInternalError), + string(DomainValidationStatePending), + string(DomainValidationStatePendingRevalidation), + string(DomainValidationStateRefreshingValidationToken), + string(DomainValidationStateRejected), + string(DomainValidationStateSubmitting), + string(DomainValidationStateTimedOut), + string(DomainValidationStateUnknown), + } +} + +func (s *DomainValidationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDomainValidationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDomainValidationState(input string) (*DomainValidationState, error) { + vals := map[string]DomainValidationState{ + "approved": DomainValidationStateApproved, + "internalerror": DomainValidationStateInternalError, + "pending": DomainValidationStatePending, + "pendingrevalidation": DomainValidationStatePendingRevalidation, + "refreshingvalidationtoken": DomainValidationStateRefreshingValidationToken, + "rejected": DomainValidationStateRejected, + "submitting": DomainValidationStateSubmitting, + "timedout": DomainValidationStateTimedOut, + "unknown": DomainValidationStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DomainValidationState(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/id_customdomain.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_customdomain.go new file mode 100644 index 00000000000..c6809a1c165 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_customdomain.go @@ -0,0 +1,139 @@ +package afdcustomdomains + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CustomDomainId{}) +} + +var _ resourceids.ResourceId = &CustomDomainId{} + +// CustomDomainId is a struct representing the Resource ID for a Custom Domain +type CustomDomainId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + CustomDomainName string +} + +// NewCustomDomainID returns a new CustomDomainId struct +func NewCustomDomainID(subscriptionId string, resourceGroupName string, profileName string, customDomainName string) CustomDomainId { + return CustomDomainId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + 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) + } + + id := CustomDomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + 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) + } + + id := CustomDomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CustomDomainId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.CustomDomainName, ok = input.Parsed["customDomainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "customDomainName", input) + } + + return 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.CDN/profiles/%s/customDomains/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + 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("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Custom Domain Name: %q", id.CustomDomainName), + } + return fmt.Sprintf("Custom Domain (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/id_customdomain_test.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_customdomain_test.go new file mode 100644 index 00000000000..88766acca45 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_customdomain_test.go @@ -0,0 +1,327 @@ +package afdcustomdomains + +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", "profileValue", "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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + 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", "profileValue", "customDomainValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/customDomains", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/customDomains/customDomainValue", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/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.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/customDomains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/cUsToMdOmAiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/customDomains/customDomainValue", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/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.cDn/pRoFiLeS/pRoFiLeVaLuE/cUsToMdOmAiNs/cUsToMdOmAiNvAlUe", + Expected: &CustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + 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.cDn/pRoFiLeS/pRoFiLeVaLuE/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.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + 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/cdn/2024-02-01/afdcustomdomains/id_profile.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_profile.go new file mode 100644 index 00000000000..669ae065a03 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_profile.go @@ -0,0 +1,130 @@ +package afdcustomdomains + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/id_profile_test.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_profile_test.go new file mode 100644 index 00000000000..9458d88fc71 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/id_profile_test.go @@ -0,0 +1,282 @@ +package afdcustomdomains + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/afdcustomdomains/method_create.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_create.go new file mode 100644 index 00000000000..ae549ab66f3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_create.go @@ -0,0 +1,76 @@ +package afdcustomdomains + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AFDDomain +} + +// Create ... +func (c AFDCustomDomainsClient) Create(ctx context.Context, id CustomDomainId, input AFDDomain) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c AFDCustomDomainsClient) CreateThenPoll(ctx context.Context, id CustomDomainId, input AFDDomain) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/method_delete.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_delete.go new file mode 100644 index 00000000000..0bc3be82915 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_delete.go @@ -0,0 +1,71 @@ +package afdcustomdomains + +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 AFDCustomDomainsClient) Delete(ctx context.Context, id CustomDomainId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c AFDCustomDomainsClient) DeleteThenPoll(ctx context.Context, id CustomDomainId) 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/cdn/2024-02-01/afdcustomdomains/method_get.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_get.go new file mode 100644 index 00000000000..8766771338f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_get.go @@ -0,0 +1,54 @@ +package afdcustomdomains + +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 *AFDDomain +} + +// Get ... +func (c AFDCustomDomainsClient) Get(ctx context.Context, id CustomDomainId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AFDDomain + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/method_listbyprofile.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_listbyprofile.go new file mode 100644 index 00000000000..3519a246ca5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_listbyprofile.go @@ -0,0 +1,105 @@ +package afdcustomdomains + +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 ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AFDDomain +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []AFDDomain +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c AFDCustomDomainsClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + 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 *[]AFDDomain `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c AFDCustomDomainsClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, AFDDomainOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AFDCustomDomainsClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate AFDDomainOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]AFDDomain, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/method_refreshvalidationtoken.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_refreshvalidationtoken.go new file mode 100644 index 00000000000..e6247385e47 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_refreshvalidationtoken.go @@ -0,0 +1,70 @@ +package afdcustomdomains + +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 RefreshValidationTokenOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// RefreshValidationToken ... +func (c AFDCustomDomainsClient) RefreshValidationToken(ctx context.Context, id CustomDomainId) (result RefreshValidationTokenOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshValidationToken", 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 +} + +// RefreshValidationTokenThenPoll performs RefreshValidationToken then polls until it's completed +func (c AFDCustomDomainsClient) RefreshValidationTokenThenPoll(ctx context.Context, id CustomDomainId) error { + result, err := c.RefreshValidationToken(ctx, id) + if err != nil { + return fmt.Errorf("performing RefreshValidationToken: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RefreshValidationToken: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/method_update.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_update.go new file mode 100644 index 00000000000..b2841d6e1c0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/method_update.go @@ -0,0 +1,75 @@ +package afdcustomdomains + +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 + Model *AFDDomain +} + +// Update ... +func (c AFDCustomDomainsClient) Update(ctx context.Context, id CustomDomainId, input AFDDomainUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c AFDCustomDomainsClient) UpdateThenPoll(ctx context.Context, id CustomDomainId, input AFDDomainUpdateParameters) 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/cdn/2024-02-01/afdcustomdomains/model_afddomain.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomain.go new file mode 100644 index 00000000000..05cb918cf11 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomain.go @@ -0,0 +1,16 @@ +package afdcustomdomains + +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 AFDDomain struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AFDDomainProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainhttpsparameters.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainhttpsparameters.go new file mode 100644 index 00000000000..e05940ce72e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainhttpsparameters.go @@ -0,0 +1,10 @@ +package afdcustomdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDDomainHTTPSParameters struct { + CertificateType AfdCertificateType `json:"certificateType"` + MinimumTlsVersion *AfdMinimumTlsVersion `json:"minimumTlsVersion,omitempty"` + Secret *ResourceReference `json:"secret,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainproperties.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainproperties.go new file mode 100644 index 00000000000..b6cd1d3ab9f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainproperties.go @@ -0,0 +1,17 @@ +package afdcustomdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDDomainProperties struct { + AzureDnsZone *ResourceReference `json:"azureDnsZone,omitempty"` + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + DomainValidationState *DomainValidationState `json:"domainValidationState,omitempty"` + ExtendedProperties *map[string]string `json:"extendedProperties,omitempty"` + HostName string `json:"hostName"` + PreValidatedCustomDomainResourceId *ResourceReference `json:"preValidatedCustomDomainResourceId,omitempty"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` + TlsSettings *AFDDomainHTTPSParameters `json:"tlsSettings,omitempty"` + ValidationProperties *DomainValidationProperties `json:"validationProperties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainupdateparameters.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainupdateparameters.go new file mode 100644 index 00000000000..47b41476862 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainupdateparameters.go @@ -0,0 +1,8 @@ +package afdcustomdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDDomainUpdateParameters struct { + Properties *AFDDomainUpdatePropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainupdatepropertiesparameters.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainupdatepropertiesparameters.go new file mode 100644 index 00000000000..031b13ae2f7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_afddomainupdatepropertiesparameters.go @@ -0,0 +1,11 @@ +package afdcustomdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDDomainUpdatePropertiesParameters struct { + AzureDnsZone *ResourceReference `json:"azureDnsZone,omitempty"` + PreValidatedCustomDomainResourceId *ResourceReference `json:"preValidatedCustomDomainResourceId,omitempty"` + ProfileName *string `json:"profileName,omitempty"` + TlsSettings *AFDDomainHTTPSParameters `json:"tlsSettings,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/model_domainvalidationproperties.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_domainvalidationproperties.go new file mode 100644 index 00000000000..7a0f09cd6af --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_domainvalidationproperties.go @@ -0,0 +1,9 @@ +package afdcustomdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainValidationProperties struct { + ExpirationDate *string `json:"expirationDate,omitempty"` + ValidationToken *string `json:"validationToken,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdcustomdomains/model_resourcereference.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_resourcereference.go new file mode 100644 index 00000000000..be573730686 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/model_resourcereference.go @@ -0,0 +1,8 @@ +package afdcustomdomains + +// 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/cdn/2024-02-01/afdcustomdomains/predicates.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/predicates.go new file mode 100644 index 00000000000..91e0235faea --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/predicates.go @@ -0,0 +1,27 @@ +package afdcustomdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDDomainOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AFDDomainOperationPredicate) Matches(input AFDDomain) 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/cdn/2024-02-01/afdcustomdomains/version.go b/resource-manager/cdn/2024-02-01/afdcustomdomains/version.go new file mode 100644 index 00000000000..7a1d1ed0969 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdcustomdomains/version.go @@ -0,0 +1,12 @@ +package afdcustomdomains + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/afdcustomdomains/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/README.md b/resource-manager/cdn/2024-02-01/afdendpoints/README.md new file mode 100644 index 00000000000..6d09aecad4f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/README.md @@ -0,0 +1,154 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdendpoints` Documentation + +The `afdendpoints` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/afdendpoints" +``` + + +### Client Initialization + +```go +client := afdendpoints.NewAFDEndpointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AFDEndpointsClient.Create` + +```go +ctx := context.TODO() +id := afdendpoints.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +payload := afdendpoints.AFDEndpoint{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDEndpointsClient.Delete` + +```go +ctx := context.TODO() +id := afdendpoints.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDEndpointsClient.Get` + +```go +ctx := context.TODO() +id := afdendpoints.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +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: `AFDEndpointsClient.ListByProfile` + +```go +ctx := context.TODO() +id := afdendpoints.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AFDEndpointsClient.ListResourceUsage` + +```go +ctx := context.TODO() +id := afdendpoints.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +// alternatively `client.ListResourceUsage(ctx, id)` can be used to do batched pagination +items, err := client.ListResourceUsageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AFDEndpointsClient.PurgeContent` + +```go +ctx := context.TODO() +id := afdendpoints.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +payload := afdendpoints.AfdPurgeParameters{ + // ... +} + + +if err := client.PurgeContentThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDEndpointsClient.Update` + +```go +ctx := context.TODO() +id := afdendpoints.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +payload := afdendpoints.AFDEndpointUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDEndpointsClient.ValidateCustomDomain` + +```go +ctx := context.TODO() +id := afdendpoints.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +payload := afdendpoints.ValidateCustomDomainInput{ + // ... +} + + +read, err := client.ValidateCustomDomain(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/cdn/2024-02-01/afdendpoints/client.go b/resource-manager/cdn/2024-02-01/afdendpoints/client.go new file mode 100644 index 00000000000..b5eabfb7133 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/client.go @@ -0,0 +1,26 @@ +package afdendpoints + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDEndpointsClient struct { + Client *resourcemanager.Client +} + +func NewAFDEndpointsClientWithBaseURI(sdkApi sdkEnv.Api) (*AFDEndpointsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "afdendpoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AFDEndpointsClient: %+v", err) + } + + return &AFDEndpointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/constants.go b/resource-manager/cdn/2024-02-01/afdendpoints/constants.go new file mode 100644 index 00000000000..870818f8770 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/constants.go @@ -0,0 +1,233 @@ +package afdendpoints + +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 AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type AutoGeneratedDomainNameLabelScope string + +const ( + AutoGeneratedDomainNameLabelScopeNoReuse AutoGeneratedDomainNameLabelScope = "NoReuse" + AutoGeneratedDomainNameLabelScopeResourceGroupReuse AutoGeneratedDomainNameLabelScope = "ResourceGroupReuse" + AutoGeneratedDomainNameLabelScopeSubscriptionReuse AutoGeneratedDomainNameLabelScope = "SubscriptionReuse" + AutoGeneratedDomainNameLabelScopeTenantReuse AutoGeneratedDomainNameLabelScope = "TenantReuse" +) + +func PossibleValuesForAutoGeneratedDomainNameLabelScope() []string { + return []string{ + string(AutoGeneratedDomainNameLabelScopeNoReuse), + string(AutoGeneratedDomainNameLabelScopeResourceGroupReuse), + string(AutoGeneratedDomainNameLabelScopeSubscriptionReuse), + string(AutoGeneratedDomainNameLabelScopeTenantReuse), + } +} + +func (s *AutoGeneratedDomainNameLabelScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoGeneratedDomainNameLabelScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoGeneratedDomainNameLabelScope(input string) (*AutoGeneratedDomainNameLabelScope, error) { + vals := map[string]AutoGeneratedDomainNameLabelScope{ + "noreuse": AutoGeneratedDomainNameLabelScopeNoReuse, + "resourcegroupreuse": AutoGeneratedDomainNameLabelScopeResourceGroupReuse, + "subscriptionreuse": AutoGeneratedDomainNameLabelScopeSubscriptionReuse, + "tenantreuse": AutoGeneratedDomainNameLabelScopeTenantReuse, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoGeneratedDomainNameLabelScope(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type EnabledState string + +const ( + EnabledStateDisabled EnabledState = "Disabled" + EnabledStateEnabled EnabledState = "Enabled" +) + +func PossibleValuesForEnabledState() []string { + return []string{ + string(EnabledStateDisabled), + string(EnabledStateEnabled), + } +} + +func (s *EnabledState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEnabledState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEnabledState(input string) (*EnabledState, error) { + vals := map[string]EnabledState{ + "disabled": EnabledStateDisabled, + "enabled": EnabledStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnabledState(input) + return &out, nil +} + +type UsageUnit string + +const ( + UsageUnitCount UsageUnit = "Count" +) + +func PossibleValuesForUsageUnit() []string { + return []string{ + string(UsageUnitCount), + } +} + +func (s *UsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUsageUnit(input string) (*UsageUnit, error) { + vals := map[string]UsageUnit{ + "count": UsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsageUnit(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/id_afdendpoint.go b/resource-manager/cdn/2024-02-01/afdendpoints/id_afdendpoint.go new file mode 100644 index 00000000000..29b5ba92c77 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/id_afdendpoint.go @@ -0,0 +1,139 @@ +package afdendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AfdEndpointId{}) +} + +var _ resourceids.ResourceId = &AfdEndpointId{} + +// AfdEndpointId is a struct representing the Resource ID for a Afd Endpoint +type AfdEndpointId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + AfdEndpointName string +} + +// NewAfdEndpointID returns a new AfdEndpointId struct +func NewAfdEndpointID(subscriptionId string, resourceGroupName string, profileName string, afdEndpointName string) AfdEndpointId { + return AfdEndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + AfdEndpointName: afdEndpointName, + } +} + +// ParseAfdEndpointID parses 'input' into a AfdEndpointId +func ParseAfdEndpointID(input string) (*AfdEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&AfdEndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AfdEndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAfdEndpointIDInsensitively parses 'input' case-insensitively into a AfdEndpointId +// note: this method should only be used for API response data and not user input +func ParseAfdEndpointIDInsensitively(input string) (*AfdEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&AfdEndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AfdEndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AfdEndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.AfdEndpointName, ok = input.Parsed["afdEndpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "afdEndpointName", input) + } + + return nil +} + +// ValidateAfdEndpointID checks that 'input' can be parsed as a Afd Endpoint ID +func ValidateAfdEndpointID(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 := ParseAfdEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Afd Endpoint ID +func (id AfdEndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/afdEndpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.AfdEndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Afd Endpoint ID +func (id AfdEndpointId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticAfdEndpoints", "afdEndpoints", "afdEndpoints"), + resourceids.UserSpecifiedSegment("afdEndpointName", "afdEndpointValue"), + } +} + +// String returns a human-readable description of this Afd Endpoint ID +func (id AfdEndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Afd Endpoint Name: %q", id.AfdEndpointName), + } + return fmt.Sprintf("Afd Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/id_afdendpoint_test.go b/resource-manager/cdn/2024-02-01/afdendpoints/id_afdendpoint_test.go new file mode 100644 index 00000000000..edcfdc20040 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/id_afdendpoint_test.go @@ -0,0 +1,327 @@ +package afdendpoints + +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 = &AfdEndpointId{} + +func TestNewAfdEndpointID(t *testing.T) { + id := NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.AfdEndpointName != "afdEndpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'AfdEndpointName'", id.AfdEndpointName, "afdEndpointValue") + } +} + +func TestFormatAfdEndpointID(t *testing.T) { + actual := NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAfdEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AfdEndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue", + Expected: &AfdEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + AfdEndpointName: "afdEndpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAfdEndpointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.AfdEndpointName != v.Expected.AfdEndpointName { + t.Fatalf("Expected %q but got %q for AfdEndpointName", v.Expected.AfdEndpointName, actual.AfdEndpointName) + } + + } +} + +func TestParseAfdEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AfdEndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue", + Expected: &AfdEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + AfdEndpointName: "afdEndpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE", + Expected: &AfdEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + AfdEndpointName: "aFdEnDpOiNtVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAfdEndpointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.AfdEndpointName != v.Expected.AfdEndpointName { + t.Fatalf("Expected %q but got %q for AfdEndpointName", v.Expected.AfdEndpointName, actual.AfdEndpointName) + } + + } +} + +func TestSegmentsForAfdEndpointId(t *testing.T) { + segments := AfdEndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AfdEndpointId 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/cdn/2024-02-01/afdendpoints/id_profile.go b/resource-manager/cdn/2024-02-01/afdendpoints/id_profile.go new file mode 100644 index 00000000000..3dce33f381f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/id_profile.go @@ -0,0 +1,130 @@ +package afdendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/id_profile_test.go b/resource-manager/cdn/2024-02-01/afdendpoints/id_profile_test.go new file mode 100644 index 00000000000..1e12c4a1076 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/id_profile_test.go @@ -0,0 +1,282 @@ +package afdendpoints + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/afdendpoints/method_create.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_create.go new file mode 100644 index 00000000000..ed1dd57cf10 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_create.go @@ -0,0 +1,76 @@ +package afdendpoints + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AFDEndpoint +} + +// Create ... +func (c AFDEndpointsClient) Create(ctx context.Context, id AfdEndpointId, input AFDEndpoint) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c AFDEndpointsClient) CreateThenPoll(ctx context.Context, id AfdEndpointId, input AFDEndpoint) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/method_delete.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_delete.go new file mode 100644 index 00000000000..008d9ba504a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_delete.go @@ -0,0 +1,71 @@ +package afdendpoints + +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 AFDEndpointsClient) Delete(ctx context.Context, id AfdEndpointId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c AFDEndpointsClient) DeleteThenPoll(ctx context.Context, id AfdEndpointId) 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/cdn/2024-02-01/afdendpoints/method_get.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_get.go new file mode 100644 index 00000000000..ed42cdc807c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_get.go @@ -0,0 +1,54 @@ +package afdendpoints + +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 *AFDEndpoint +} + +// Get ... +func (c AFDEndpointsClient) Get(ctx context.Context, id AfdEndpointId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AFDEndpoint + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/method_listbyprofile.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_listbyprofile.go new file mode 100644 index 00000000000..328db4641b9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_listbyprofile.go @@ -0,0 +1,105 @@ +package afdendpoints + +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 ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AFDEndpoint +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []AFDEndpoint +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c AFDEndpointsClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + Path: fmt.Sprintf("%s/afdEndpoints", 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 *[]AFDEndpoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c AFDEndpointsClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, AFDEndpointOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AFDEndpointsClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate AFDEndpointOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]AFDEndpoint, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/method_listresourceusage.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_listresourceusage.go new file mode 100644 index 00000000000..9d0e7501447 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_listresourceusage.go @@ -0,0 +1,105 @@ +package afdendpoints + +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 ListResourceUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ListResourceUsageCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ListResourceUsageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListResourceUsageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListResourceUsage ... +func (c AFDEndpointsClient) ListResourceUsage(ctx context.Context, id AfdEndpointId) (result ListResourceUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListResourceUsageCustomPager{}, + 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 *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourceUsageComplete retrieves all the results into a single object +func (c AFDEndpointsClient) ListResourceUsageComplete(ctx context.Context, id AfdEndpointId) (ListResourceUsageCompleteResult, error) { + return c.ListResourceUsageCompleteMatchingPredicate(ctx, id, UsageOperationPredicate{}) +} + +// ListResourceUsageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AFDEndpointsClient) ListResourceUsageCompleteMatchingPredicate(ctx context.Context, id AfdEndpointId, predicate UsageOperationPredicate) (result ListResourceUsageCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.ListResourceUsage(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListResourceUsageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/method_purgecontent.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_purgecontent.go new file mode 100644 index 00000000000..266d22c7ea2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_purgecontent.go @@ -0,0 +1,74 @@ +package afdendpoints + +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 PurgeContentOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// PurgeContent ... +func (c AFDEndpointsClient) PurgeContent(ctx context.Context, id AfdEndpointId, input AfdPurgeParameters) (result PurgeContentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/purge", 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 +} + +// PurgeContentThenPoll performs PurgeContent then polls until it's completed +func (c AFDEndpointsClient) PurgeContentThenPoll(ctx context.Context, id AfdEndpointId, input AfdPurgeParameters) error { + result, err := c.PurgeContent(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PurgeContent: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PurgeContent: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/method_update.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_update.go new file mode 100644 index 00000000000..911a2a70823 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_update.go @@ -0,0 +1,75 @@ +package afdendpoints + +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 + Model *AFDEndpoint +} + +// Update ... +func (c AFDEndpointsClient) Update(ctx context.Context, id AfdEndpointId, input AFDEndpointUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c AFDEndpointsClient) UpdateThenPoll(ctx context.Context, id AfdEndpointId, input AFDEndpointUpdateParameters) 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/cdn/2024-02-01/afdendpoints/method_validatecustomdomain.go b/resource-manager/cdn/2024-02-01/afdendpoints/method_validatecustomdomain.go new file mode 100644 index 00000000000..df026ead56c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/method_validatecustomdomain.go @@ -0,0 +1,59 @@ +package afdendpoints + +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 ValidateCustomDomainOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ValidateCustomDomainOutput +} + +// ValidateCustomDomain ... +func (c AFDEndpointsClient) ValidateCustomDomain(ctx context.Context, id AfdEndpointId, input ValidateCustomDomainInput) (result ValidateCustomDomainOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateCustomDomain", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ValidateCustomDomainOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpoint.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpoint.go new file mode 100644 index 00000000000..fe851cca60c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpoint.go @@ -0,0 +1,18 @@ +package afdendpoints + +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 AFDEndpoint struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *AFDEndpointProperties `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/cdn/2024-02-01/afdendpoints/model_afdendpointproperties.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointproperties.go new file mode 100644 index 00000000000..9a02413671c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointproperties.go @@ -0,0 +1,13 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDEndpointProperties struct { + AutoGeneratedDomainNameLabelScope *AutoGeneratedDomainNameLabelScope `json:"autoGeneratedDomainNameLabelScope,omitempty"` + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + EnabledState *EnabledState `json:"enabledState,omitempty"` + HostName *string `json:"hostName,omitempty"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointpropertiesupdateparameters.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointpropertiesupdateparameters.go new file mode 100644 index 00000000000..8611ce0d850 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointpropertiesupdateparameters.go @@ -0,0 +1,9 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDEndpointPropertiesUpdateParameters struct { + EnabledState *EnabledState `json:"enabledState,omitempty"` + ProfileName *string `json:"profileName,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointupdateparameters.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointupdateparameters.go new file mode 100644 index 00000000000..5d6b6ab8d5b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdendpointupdateparameters.go @@ -0,0 +1,9 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDEndpointUpdateParameters struct { + Properties *AFDEndpointPropertiesUpdateParameters `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_afdpurgeparameters.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdpurgeparameters.go new file mode 100644 index 00000000000..7fa33e59b86 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_afdpurgeparameters.go @@ -0,0 +1,9 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AfdPurgeParameters struct { + ContentPaths []string `json:"contentPaths"` + Domains *[]string `json:"domains,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_usage.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_usage.go new file mode 100644 index 00000000000..e1410730af5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_usage.go @@ -0,0 +1,12 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Usage struct { + CurrentValue int64 `json:"currentValue"` + Id *string `json:"id,omitempty"` + Limit int64 `json:"limit"` + Name UsageName `json:"name"` + Unit UsageUnit `json:"unit"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_usagename.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_usagename.go new file mode 100644 index 00000000000..e00d7fba315 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_usagename.go @@ -0,0 +1,9 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_validatecustomdomaininput.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_validatecustomdomaininput.go new file mode 100644 index 00000000000..cdd8ec4488e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_validatecustomdomaininput.go @@ -0,0 +1,8 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateCustomDomainInput struct { + HostName string `json:"hostName"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/model_validatecustomdomainoutput.go b/resource-manager/cdn/2024-02-01/afdendpoints/model_validatecustomdomainoutput.go new file mode 100644 index 00000000000..2aedfdc5b18 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/model_validatecustomdomainoutput.go @@ -0,0 +1,10 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateCustomDomainOutput struct { + CustomDomainValidated *bool `json:"customDomainValidated,omitempty"` + Message *string `json:"message,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/predicates.go b/resource-manager/cdn/2024-02-01/afdendpoints/predicates.go new file mode 100644 index 00000000000..f8a26db0ed7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/predicates.go @@ -0,0 +1,55 @@ +package afdendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDEndpointOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p AFDEndpointOperationPredicate) Matches(input AFDEndpoint) 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 UsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.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 && *p.Limit != input.Limit { + return false + } + + return true +} diff --git a/resource-manager/cdn/2024-02-01/afdendpoints/version.go b/resource-manager/cdn/2024-02-01/afdendpoints/version.go new file mode 100644 index 00000000000..55ceae64174 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdendpoints/version.go @@ -0,0 +1,12 @@ +package afdendpoints + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/afdendpoints/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/README.md b/resource-manager/cdn/2024-02-01/afdorigingroups/README.md new file mode 100644 index 00000000000..99acb89dff5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdorigingroups` Documentation + +The `afdorigingroups` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/afdorigingroups" +``` + + +### Client Initialization + +```go +client := afdorigingroups.NewAFDOriginGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AFDOriginGroupsClient.Create` + +```go +ctx := context.TODO() +id := afdorigingroups.NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + +payload := afdorigingroups.AFDOriginGroup{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDOriginGroupsClient.Delete` + +```go +ctx := context.TODO() +id := afdorigingroups.NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDOriginGroupsClient.Get` + +```go +ctx := context.TODO() +id := afdorigingroups.NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + +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: `AFDOriginGroupsClient.ListByProfile` + +```go +ctx := context.TODO() +id := afdorigingroups.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AFDOriginGroupsClient.ListResourceUsage` + +```go +ctx := context.TODO() +id := afdorigingroups.NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + +// alternatively `client.ListResourceUsage(ctx, id)` can be used to do batched pagination +items, err := client.ListResourceUsageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AFDOriginGroupsClient.Update` + +```go +ctx := context.TODO() +id := afdorigingroups.NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + +payload := afdorigingroups.AFDOriginGroupUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/client.go b/resource-manager/cdn/2024-02-01/afdorigingroups/client.go new file mode 100644 index 00000000000..ec82a218f9e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/client.go @@ -0,0 +1,26 @@ +package afdorigingroups + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginGroupsClient struct { + Client *resourcemanager.Client +} + +func NewAFDOriginGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*AFDOriginGroupsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "afdorigingroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AFDOriginGroupsClient: %+v", err) + } + + return &AFDOriginGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/constants.go b/resource-manager/cdn/2024-02-01/afdorigingroups/constants.go new file mode 100644 index 00000000000..88b86252913 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/constants.go @@ -0,0 +1,274 @@ +package afdorigingroups + +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 AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type EnabledState string + +const ( + EnabledStateDisabled EnabledState = "Disabled" + EnabledStateEnabled EnabledState = "Enabled" +) + +func PossibleValuesForEnabledState() []string { + return []string{ + string(EnabledStateDisabled), + string(EnabledStateEnabled), + } +} + +func (s *EnabledState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEnabledState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEnabledState(input string) (*EnabledState, error) { + vals := map[string]EnabledState{ + "disabled": EnabledStateDisabled, + "enabled": EnabledStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnabledState(input) + return &out, nil +} + +type HealthProbeRequestType string + +const ( + HealthProbeRequestTypeGET HealthProbeRequestType = "GET" + HealthProbeRequestTypeHEAD HealthProbeRequestType = "HEAD" + HealthProbeRequestTypeNotSet HealthProbeRequestType = "NotSet" +) + +func PossibleValuesForHealthProbeRequestType() []string { + return []string{ + string(HealthProbeRequestTypeGET), + string(HealthProbeRequestTypeHEAD), + string(HealthProbeRequestTypeNotSet), + } +} + +func (s *HealthProbeRequestType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthProbeRequestType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthProbeRequestType(input string) (*HealthProbeRequestType, error) { + vals := map[string]HealthProbeRequestType{ + "get": HealthProbeRequestTypeGET, + "head": HealthProbeRequestTypeHEAD, + "notset": HealthProbeRequestTypeNotSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthProbeRequestType(input) + return &out, nil +} + +type ProbeProtocol string + +const ( + ProbeProtocolHTTP ProbeProtocol = "Http" + ProbeProtocolHTTPS ProbeProtocol = "Https" + ProbeProtocolNotSet ProbeProtocol = "NotSet" +) + +func PossibleValuesForProbeProtocol() []string { + return []string{ + string(ProbeProtocolHTTP), + string(ProbeProtocolHTTPS), + string(ProbeProtocolNotSet), + } +} + +func (s *ProbeProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProbeProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProbeProtocol(input string) (*ProbeProtocol, error) { + vals := map[string]ProbeProtocol{ + "http": ProbeProtocolHTTP, + "https": ProbeProtocolHTTPS, + "notset": ProbeProtocolNotSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProbeProtocol(input) + return &out, nil +} + +type UsageUnit string + +const ( + UsageUnitCount UsageUnit = "Count" +) + +func PossibleValuesForUsageUnit() []string { + return []string{ + string(UsageUnitCount), + } +} + +func (s *UsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUsageUnit(input string) (*UsageUnit, error) { + vals := map[string]UsageUnit{ + "count": UsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsageUnit(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/id_origingroup.go b/resource-manager/cdn/2024-02-01/afdorigingroups/id_origingroup.go new file mode 100644 index 00000000000..ad339ceaf26 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/id_origingroup.go @@ -0,0 +1,139 @@ +package afdorigingroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OriginGroupId{}) +} + +var _ resourceids.ResourceId = &OriginGroupId{} + +// OriginGroupId is a struct representing the Resource ID for a Origin Group +type OriginGroupId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + OriginGroupName string +} + +// NewOriginGroupID returns a new OriginGroupId struct +func NewOriginGroupID(subscriptionId string, resourceGroupName string, profileName string, originGroupName string) OriginGroupId { + return OriginGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + OriginGroupName: originGroupName, + } +} + +// ParseOriginGroupID parses 'input' into a OriginGroupId +func ParseOriginGroupID(input string) (*OriginGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOriginGroupIDInsensitively parses 'input' case-insensitively into a OriginGroupId +// note: this method should only be used for API response data and not user input +func ParseOriginGroupIDInsensitively(input string) (*OriginGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OriginGroupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.OriginGroupName, ok = input.Parsed["originGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "originGroupName", input) + } + + return nil +} + +// ValidateOriginGroupID checks that 'input' can be parsed as a Origin Group ID +func ValidateOriginGroupID(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 := ParseOriginGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Origin Group ID +func (id OriginGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/originGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.OriginGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Origin Group ID +func (id OriginGroupId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticOriginGroups", "originGroups", "originGroups"), + resourceids.UserSpecifiedSegment("originGroupName", "originGroupValue"), + } +} + +// String returns a human-readable description of this Origin Group ID +func (id OriginGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Origin Group Name: %q", id.OriginGroupName), + } + return fmt.Sprintf("Origin Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/id_origingroup_test.go b/resource-manager/cdn/2024-02-01/afdorigingroups/id_origingroup_test.go new file mode 100644 index 00000000000..12838122ff6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/id_origingroup_test.go @@ -0,0 +1,327 @@ +package afdorigingroups + +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 = &OriginGroupId{} + +func TestNewOriginGroupID(t *testing.T) { + id := NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.OriginGroupName != "originGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'OriginGroupName'", id.OriginGroupName, "originGroupValue") + } +} + +func TestFormatOriginGroupID(t *testing.T) { + actual := NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOriginGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginGroupId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue", + Expected: &OriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + OriginGroupName: "originGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + } +} + +func TestParseOriginGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginGroupId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue", + Expected: &OriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + OriginGroupName: "originGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE", + Expected: &OriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + OriginGroupName: "oRiGiNgRoUpVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + } +} + +func TestSegmentsForOriginGroupId(t *testing.T) { + segments := OriginGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OriginGroupId 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/cdn/2024-02-01/afdorigingroups/id_profile.go b/resource-manager/cdn/2024-02-01/afdorigingroups/id_profile.go new file mode 100644 index 00000000000..a2b6923f1ec --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/id_profile.go @@ -0,0 +1,130 @@ +package afdorigingroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/id_profile_test.go b/resource-manager/cdn/2024-02-01/afdorigingroups/id_profile_test.go new file mode 100644 index 00000000000..b45a69b67be --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/id_profile_test.go @@ -0,0 +1,282 @@ +package afdorigingroups + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/afdorigingroups/method_create.go b/resource-manager/cdn/2024-02-01/afdorigingroups/method_create.go new file mode 100644 index 00000000000..5538fb9d110 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/method_create.go @@ -0,0 +1,76 @@ +package afdorigingroups + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AFDOriginGroup +} + +// Create ... +func (c AFDOriginGroupsClient) Create(ctx context.Context, id OriginGroupId, input AFDOriginGroup) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c AFDOriginGroupsClient) CreateThenPoll(ctx context.Context, id OriginGroupId, input AFDOriginGroup) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/method_delete.go b/resource-manager/cdn/2024-02-01/afdorigingroups/method_delete.go new file mode 100644 index 00000000000..c95a6000a7e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/method_delete.go @@ -0,0 +1,71 @@ +package afdorigingroups + +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 AFDOriginGroupsClient) Delete(ctx context.Context, id OriginGroupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c AFDOriginGroupsClient) DeleteThenPoll(ctx context.Context, id OriginGroupId) 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/cdn/2024-02-01/afdorigingroups/method_get.go b/resource-manager/cdn/2024-02-01/afdorigingroups/method_get.go new file mode 100644 index 00000000000..a47441c5980 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/method_get.go @@ -0,0 +1,54 @@ +package afdorigingroups + +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 *AFDOriginGroup +} + +// Get ... +func (c AFDOriginGroupsClient) Get(ctx context.Context, id OriginGroupId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AFDOriginGroup + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/method_listbyprofile.go b/resource-manager/cdn/2024-02-01/afdorigingroups/method_listbyprofile.go new file mode 100644 index 00000000000..41c9b62d2bf --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/method_listbyprofile.go @@ -0,0 +1,105 @@ +package afdorigingroups + +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 ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AFDOriginGroup +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []AFDOriginGroup +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c AFDOriginGroupsClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + Path: fmt.Sprintf("%s/originGroups", 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 *[]AFDOriginGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c AFDOriginGroupsClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, AFDOriginGroupOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AFDOriginGroupsClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate AFDOriginGroupOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]AFDOriginGroup, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/method_listresourceusage.go b/resource-manager/cdn/2024-02-01/afdorigingroups/method_listresourceusage.go new file mode 100644 index 00000000000..bd98ba2d547 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/method_listresourceusage.go @@ -0,0 +1,105 @@ +package afdorigingroups + +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 ListResourceUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ListResourceUsageCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ListResourceUsageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListResourceUsageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListResourceUsage ... +func (c AFDOriginGroupsClient) ListResourceUsage(ctx context.Context, id OriginGroupId) (result ListResourceUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListResourceUsageCustomPager{}, + 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 *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourceUsageComplete retrieves all the results into a single object +func (c AFDOriginGroupsClient) ListResourceUsageComplete(ctx context.Context, id OriginGroupId) (ListResourceUsageCompleteResult, error) { + return c.ListResourceUsageCompleteMatchingPredicate(ctx, id, UsageOperationPredicate{}) +} + +// ListResourceUsageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AFDOriginGroupsClient) ListResourceUsageCompleteMatchingPredicate(ctx context.Context, id OriginGroupId, predicate UsageOperationPredicate) (result ListResourceUsageCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.ListResourceUsage(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListResourceUsageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/method_update.go b/resource-manager/cdn/2024-02-01/afdorigingroups/method_update.go new file mode 100644 index 00000000000..caad347178d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/method_update.go @@ -0,0 +1,75 @@ +package afdorigingroups + +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 + Model *AFDOriginGroup +} + +// Update ... +func (c AFDOriginGroupsClient) Update(ctx context.Context, id OriginGroupId, input AFDOriginGroupUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c AFDOriginGroupsClient) UpdateThenPoll(ctx context.Context, id OriginGroupId, input AFDOriginGroupUpdateParameters) 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/cdn/2024-02-01/afdorigingroups/model_afdorigingroup.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroup.go new file mode 100644 index 00000000000..4ca3aa687ba --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroup.go @@ -0,0 +1,16 @@ +package afdorigingroups + +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 AFDOriginGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AFDOriginGroupProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupproperties.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupproperties.go new file mode 100644 index 00000000000..c4ffcea699b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupproperties.go @@ -0,0 +1,14 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginGroupProperties struct { + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + HealthProbeSettings *HealthProbeParameters `json:"healthProbeSettings,omitempty"` + LoadBalancingSettings *LoadBalancingSettingsParameters `json:"loadBalancingSettings,omitempty"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` + SessionAffinityState *EnabledState `json:"sessionAffinityState,omitempty"` + TrafficRestorationTimeToHealedOrNewEndpointsInMinutes *int64 `json:"trafficRestorationTimeToHealedOrNewEndpointsInMinutes,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupupdateparameters.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupupdateparameters.go new file mode 100644 index 00000000000..907c42b1e77 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupupdateparameters.go @@ -0,0 +1,8 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginGroupUpdateParameters struct { + Properties *AFDOriginGroupUpdatePropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupupdatepropertiesparameters.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupupdatepropertiesparameters.go new file mode 100644 index 00000000000..0cbb49b9466 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_afdorigingroupupdatepropertiesparameters.go @@ -0,0 +1,12 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginGroupUpdatePropertiesParameters struct { + HealthProbeSettings *HealthProbeParameters `json:"healthProbeSettings,omitempty"` + LoadBalancingSettings *LoadBalancingSettingsParameters `json:"loadBalancingSettings,omitempty"` + ProfileName *string `json:"profileName,omitempty"` + SessionAffinityState *EnabledState `json:"sessionAffinityState,omitempty"` + TrafficRestorationTimeToHealedOrNewEndpointsInMinutes *int64 `json:"trafficRestorationTimeToHealedOrNewEndpointsInMinutes,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/model_healthprobeparameters.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_healthprobeparameters.go new file mode 100644 index 00000000000..987e8ba933d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_healthprobeparameters.go @@ -0,0 +1,11 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthProbeParameters struct { + ProbeIntervalInSeconds *int64 `json:"probeIntervalInSeconds,omitempty"` + ProbePath *string `json:"probePath,omitempty"` + ProbeProtocol *ProbeProtocol `json:"probeProtocol,omitempty"` + ProbeRequestType *HealthProbeRequestType `json:"probeRequestType,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/model_loadbalancingsettingsparameters.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_loadbalancingsettingsparameters.go new file mode 100644 index 00000000000..989f3fe3dd8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_loadbalancingsettingsparameters.go @@ -0,0 +1,10 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoadBalancingSettingsParameters struct { + AdditionalLatencyInMilliseconds *int64 `json:"additionalLatencyInMilliseconds,omitempty"` + SampleSize *int64 `json:"sampleSize,omitempty"` + SuccessfulSamplesRequired *int64 `json:"successfulSamplesRequired,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/model_usage.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_usage.go new file mode 100644 index 00000000000..eaf251c8972 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_usage.go @@ -0,0 +1,12 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Usage struct { + CurrentValue int64 `json:"currentValue"` + Id *string `json:"id,omitempty"` + Limit int64 `json:"limit"` + Name UsageName `json:"name"` + Unit UsageUnit `json:"unit"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/model_usagename.go b/resource-manager/cdn/2024-02-01/afdorigingroups/model_usagename.go new file mode 100644 index 00000000000..28c2628adc3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/model_usagename.go @@ -0,0 +1,9 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/predicates.go b/resource-manager/cdn/2024-02-01/afdorigingroups/predicates.go new file mode 100644 index 00000000000..24de95a48e3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/predicates.go @@ -0,0 +1,50 @@ +package afdorigingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AFDOriginGroupOperationPredicate) Matches(input AFDOriginGroup) 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 UsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.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 && *p.Limit != input.Limit { + return false + } + + return true +} diff --git a/resource-manager/cdn/2024-02-01/afdorigingroups/version.go b/resource-manager/cdn/2024-02-01/afdorigingroups/version.go new file mode 100644 index 00000000000..3926c50c841 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigingroups/version.go @@ -0,0 +1,12 @@ +package afdorigingroups + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/afdorigingroups/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/README.md b/resource-manager/cdn/2024-02-01/afdorigins/README.md new file mode 100644 index 00000000000..a5f6ffdbf40 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdorigins` Documentation + +The `afdorigins` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/afdorigins" +``` + + +### Client Initialization + +```go +client := afdorigins.NewAFDOriginsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AFDOriginsClient.Create` + +```go +ctx := context.TODO() +id := afdorigins.NewOriginGroupOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue", "originValue") + +payload := afdorigins.AFDOrigin{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDOriginsClient.Delete` + +```go +ctx := context.TODO() +id := afdorigins.NewOriginGroupOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue", "originValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDOriginsClient.Get` + +```go +ctx := context.TODO() +id := afdorigins.NewOriginGroupOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue", "originValue") + +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: `AFDOriginsClient.ListByOriginGroup` + +```go +ctx := context.TODO() +id := afdorigins.NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + +// alternatively `client.ListByOriginGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByOriginGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AFDOriginsClient.Update` + +```go +ctx := context.TODO() +id := afdorigins.NewOriginGroupOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue", "originValue") + +payload := afdorigins.AFDOriginUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/afdorigins/client.go b/resource-manager/cdn/2024-02-01/afdorigins/client.go new file mode 100644 index 00000000000..827e240817b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/client.go @@ -0,0 +1,26 @@ +package afdorigins + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginsClient struct { + Client *resourcemanager.Client +} + +func NewAFDOriginsClientWithBaseURI(sdkApi sdkEnv.Api) (*AFDOriginsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "afdorigins", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AFDOriginsClient: %+v", err) + } + + return &AFDOriginsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/constants.go b/resource-manager/cdn/2024-02-01/afdorigins/constants.go new file mode 100644 index 00000000000..78f584111ad --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/constants.go @@ -0,0 +1,198 @@ +package afdorigins + +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 AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type EnabledState string + +const ( + EnabledStateDisabled EnabledState = "Disabled" + EnabledStateEnabled EnabledState = "Enabled" +) + +func PossibleValuesForEnabledState() []string { + return []string{ + string(EnabledStateDisabled), + string(EnabledStateEnabled), + } +} + +func (s *EnabledState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEnabledState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEnabledState(input string) (*EnabledState, error) { + vals := map[string]EnabledState{ + "disabled": EnabledStateDisabled, + "enabled": EnabledStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnabledState(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 (s *SharedPrivateLinkResourceStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSharedPrivateLinkResourceStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/id_origingroup.go b/resource-manager/cdn/2024-02-01/afdorigins/id_origingroup.go new file mode 100644 index 00000000000..e8a907fc239 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/id_origingroup.go @@ -0,0 +1,139 @@ +package afdorigins + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OriginGroupId{}) +} + +var _ resourceids.ResourceId = &OriginGroupId{} + +// OriginGroupId is a struct representing the Resource ID for a Origin Group +type OriginGroupId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + OriginGroupName string +} + +// NewOriginGroupID returns a new OriginGroupId struct +func NewOriginGroupID(subscriptionId string, resourceGroupName string, profileName string, originGroupName string) OriginGroupId { + return OriginGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + OriginGroupName: originGroupName, + } +} + +// ParseOriginGroupID parses 'input' into a OriginGroupId +func ParseOriginGroupID(input string) (*OriginGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOriginGroupIDInsensitively parses 'input' case-insensitively into a OriginGroupId +// note: this method should only be used for API response data and not user input +func ParseOriginGroupIDInsensitively(input string) (*OriginGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OriginGroupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.OriginGroupName, ok = input.Parsed["originGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "originGroupName", input) + } + + return nil +} + +// ValidateOriginGroupID checks that 'input' can be parsed as a Origin Group ID +func ValidateOriginGroupID(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 := ParseOriginGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Origin Group ID +func (id OriginGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/originGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.OriginGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Origin Group ID +func (id OriginGroupId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticOriginGroups", "originGroups", "originGroups"), + resourceids.UserSpecifiedSegment("originGroupName", "originGroupValue"), + } +} + +// String returns a human-readable description of this Origin Group ID +func (id OriginGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Origin Group Name: %q", id.OriginGroupName), + } + return fmt.Sprintf("Origin Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/id_origingroup_test.go b/resource-manager/cdn/2024-02-01/afdorigins/id_origingroup_test.go new file mode 100644 index 00000000000..1f37ee3b948 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/id_origingroup_test.go @@ -0,0 +1,327 @@ +package afdorigins + +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 = &OriginGroupId{} + +func TestNewOriginGroupID(t *testing.T) { + id := NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.OriginGroupName != "originGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'OriginGroupName'", id.OriginGroupName, "originGroupValue") + } +} + +func TestFormatOriginGroupID(t *testing.T) { + actual := NewOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOriginGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginGroupId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue", + Expected: &OriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + OriginGroupName: "originGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + } +} + +func TestParseOriginGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginGroupId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue", + Expected: &OriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + OriginGroupName: "originGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE", + Expected: &OriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + OriginGroupName: "oRiGiNgRoUpVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + } +} + +func TestSegmentsForOriginGroupId(t *testing.T) { + segments := OriginGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OriginGroupId 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/cdn/2024-02-01/afdorigins/id_origingrouporigin.go b/resource-manager/cdn/2024-02-01/afdorigins/id_origingrouporigin.go new file mode 100644 index 00000000000..87ede480894 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/id_origingrouporigin.go @@ -0,0 +1,148 @@ +package afdorigins + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OriginGroupOriginId{}) +} + +var _ resourceids.ResourceId = &OriginGroupOriginId{} + +// OriginGroupOriginId is a struct representing the Resource ID for a Origin Group Origin +type OriginGroupOriginId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + OriginGroupName string + OriginName string +} + +// NewOriginGroupOriginID returns a new OriginGroupOriginId struct +func NewOriginGroupOriginID(subscriptionId string, resourceGroupName string, profileName string, originGroupName string, originName string) OriginGroupOriginId { + return OriginGroupOriginId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + OriginGroupName: originGroupName, + OriginName: originName, + } +} + +// ParseOriginGroupOriginID parses 'input' into a OriginGroupOriginId +func ParseOriginGroupOriginID(input string) (*OriginGroupOriginId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginGroupOriginId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginGroupOriginId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOriginGroupOriginIDInsensitively parses 'input' case-insensitively into a OriginGroupOriginId +// note: this method should only be used for API response data and not user input +func ParseOriginGroupOriginIDInsensitively(input string) (*OriginGroupOriginId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginGroupOriginId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginGroupOriginId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OriginGroupOriginId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.OriginGroupName, ok = input.Parsed["originGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "originGroupName", input) + } + + if id.OriginName, ok = input.Parsed["originName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "originName", input) + } + + return nil +} + +// ValidateOriginGroupOriginID checks that 'input' can be parsed as a Origin Group Origin ID +func ValidateOriginGroupOriginID(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 := ParseOriginGroupOriginID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Origin Group Origin ID +func (id OriginGroupOriginId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/originGroups/%s/origins/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.OriginGroupName, id.OriginName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Origin Group Origin ID +func (id OriginGroupOriginId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticOriginGroups", "originGroups", "originGroups"), + resourceids.UserSpecifiedSegment("originGroupName", "originGroupValue"), + resourceids.StaticSegment("staticOrigins", "origins", "origins"), + resourceids.UserSpecifiedSegment("originName", "originValue"), + } +} + +// String returns a human-readable description of this Origin Group Origin ID +func (id OriginGroupOriginId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Origin Group Name: %q", id.OriginGroupName), + fmt.Sprintf("Origin Name: %q", id.OriginName), + } + return fmt.Sprintf("Origin Group Origin (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/id_origingrouporigin_test.go b/resource-manager/cdn/2024-02-01/afdorigins/id_origingrouporigin_test.go new file mode 100644 index 00000000000..f56d87ab590 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/id_origingrouporigin_test.go @@ -0,0 +1,372 @@ +package afdorigins + +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 = &OriginGroupOriginId{} + +func TestNewOriginGroupOriginID(t *testing.T) { + id := NewOriginGroupOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue", "originValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.OriginGroupName != "originGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'OriginGroupName'", id.OriginGroupName, "originGroupValue") + } + + if id.OriginName != "originValue" { + t.Fatalf("Expected %q but got %q for Segment 'OriginName'", id.OriginName, "originValue") + } +} + +func TestFormatOriginGroupOriginID(t *testing.T) { + actual := NewOriginGroupOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "originGroupValue", "originValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/origins/originValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOriginGroupOriginID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginGroupOriginId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/origins", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/origins/originValue", + Expected: &OriginGroupOriginId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + OriginGroupName: "originGroupValue", + OriginName: "originValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/origins/originValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginGroupOriginID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + if actual.OriginName != v.Expected.OriginName { + t.Fatalf("Expected %q but got %q for OriginName", v.Expected.OriginName, actual.OriginName) + } + + } +} + +func TestParseOriginGroupOriginIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginGroupOriginId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/origins", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE/oRiGiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/origins/originValue", + Expected: &OriginGroupOriginId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + OriginGroupName: "originGroupValue", + OriginName: "originValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/originGroups/originGroupValue/origins/originValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE/oRiGiNs/oRiGiNvAlUe", + Expected: &OriginGroupOriginId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + OriginGroupName: "oRiGiNgRoUpVaLuE", + OriginName: "oRiGiNvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE/oRiGiNs/oRiGiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginGroupOriginIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + if actual.OriginName != v.Expected.OriginName { + t.Fatalf("Expected %q but got %q for OriginName", v.Expected.OriginName, actual.OriginName) + } + + } +} + +func TestSegmentsForOriginGroupOriginId(t *testing.T) { + segments := OriginGroupOriginId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OriginGroupOriginId 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/cdn/2024-02-01/afdorigins/method_create.go b/resource-manager/cdn/2024-02-01/afdorigins/method_create.go new file mode 100644 index 00000000000..77dd05478d0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/method_create.go @@ -0,0 +1,76 @@ +package afdorigins + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AFDOrigin +} + +// Create ... +func (c AFDOriginsClient) Create(ctx context.Context, id OriginGroupOriginId, input AFDOrigin) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c AFDOriginsClient) CreateThenPoll(ctx context.Context, id OriginGroupOriginId, input AFDOrigin) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/method_delete.go b/resource-manager/cdn/2024-02-01/afdorigins/method_delete.go new file mode 100644 index 00000000000..b8373b1a8ae --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/method_delete.go @@ -0,0 +1,71 @@ +package afdorigins + +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 AFDOriginsClient) Delete(ctx context.Context, id OriginGroupOriginId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c AFDOriginsClient) DeleteThenPoll(ctx context.Context, id OriginGroupOriginId) 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/cdn/2024-02-01/afdorigins/method_get.go b/resource-manager/cdn/2024-02-01/afdorigins/method_get.go new file mode 100644 index 00000000000..916389020fd --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/method_get.go @@ -0,0 +1,54 @@ +package afdorigins + +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 *AFDOrigin +} + +// Get ... +func (c AFDOriginsClient) Get(ctx context.Context, id OriginGroupOriginId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AFDOrigin + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/method_listbyorigingroup.go b/resource-manager/cdn/2024-02-01/afdorigins/method_listbyorigingroup.go new file mode 100644 index 00000000000..d1791399e80 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/method_listbyorigingroup.go @@ -0,0 +1,105 @@ +package afdorigins + +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 ListByOriginGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AFDOrigin +} + +type ListByOriginGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []AFDOrigin +} + +type ListByOriginGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByOriginGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByOriginGroup ... +func (c AFDOriginsClient) ListByOriginGroup(ctx context.Context, id OriginGroupId) (result ListByOriginGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByOriginGroupCustomPager{}, + Path: fmt.Sprintf("%s/origins", 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 *[]AFDOrigin `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByOriginGroupComplete retrieves all the results into a single object +func (c AFDOriginsClient) ListByOriginGroupComplete(ctx context.Context, id OriginGroupId) (ListByOriginGroupCompleteResult, error) { + return c.ListByOriginGroupCompleteMatchingPredicate(ctx, id, AFDOriginOperationPredicate{}) +} + +// ListByOriginGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AFDOriginsClient) ListByOriginGroupCompleteMatchingPredicate(ctx context.Context, id OriginGroupId, predicate AFDOriginOperationPredicate) (result ListByOriginGroupCompleteResult, err error) { + items := make([]AFDOrigin, 0) + + resp, err := c.ListByOriginGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByOriginGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/method_update.go b/resource-manager/cdn/2024-02-01/afdorigins/method_update.go new file mode 100644 index 00000000000..ea31f9b396a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/method_update.go @@ -0,0 +1,75 @@ +package afdorigins + +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 + Model *AFDOrigin +} + +// Update ... +func (c AFDOriginsClient) Update(ctx context.Context, id OriginGroupOriginId, input AFDOriginUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c AFDOriginsClient) UpdateThenPoll(ctx context.Context, id OriginGroupOriginId, input AFDOriginUpdateParameters) 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/cdn/2024-02-01/afdorigins/model_afdorigin.go b/resource-manager/cdn/2024-02-01/afdorigins/model_afdorigin.go new file mode 100644 index 00000000000..4ebe2c0ac9d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/model_afdorigin.go @@ -0,0 +1,16 @@ +package afdorigins + +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 AFDOrigin struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AFDOriginProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginproperties.go b/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginproperties.go new file mode 100644 index 00000000000..1fa0dcacb4c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginproperties.go @@ -0,0 +1,20 @@ +package afdorigins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginProperties struct { + AzureOrigin *ResourceReference `json:"azureOrigin,omitempty"` + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + EnabledState *EnabledState `json:"enabledState,omitempty"` + EnforceCertificateNameCheck *bool `json:"enforceCertificateNameCheck,omitempty"` + HTTPPort *int64 `json:"httpPort,omitempty"` + HTTPSPort *int64 `json:"httpsPort,omitempty"` + HostName *string `json:"hostName,omitempty"` + OriginGroupName *string `json:"originGroupName,omitempty"` + OriginHostHeader *string `json:"originHostHeader,omitempty"` + Priority *int64 `json:"priority,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` + SharedPrivateLinkResource *SharedPrivateLinkResourceProperties `json:"sharedPrivateLinkResource,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginupdateparameters.go b/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginupdateparameters.go new file mode 100644 index 00000000000..679950c6d4f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginupdateparameters.go @@ -0,0 +1,8 @@ +package afdorigins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginUpdateParameters struct { + Properties *AFDOriginUpdatePropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginupdatepropertiesparameters.go b/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginupdatepropertiesparameters.go new file mode 100644 index 00000000000..e1f958eac8b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/model_afdoriginupdatepropertiesparameters.go @@ -0,0 +1,18 @@ +package afdorigins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginUpdatePropertiesParameters struct { + AzureOrigin *ResourceReference `json:"azureOrigin,omitempty"` + EnabledState *EnabledState `json:"enabledState,omitempty"` + EnforceCertificateNameCheck *bool `json:"enforceCertificateNameCheck,omitempty"` + HTTPPort *int64 `json:"httpPort,omitempty"` + HTTPSPort *int64 `json:"httpsPort,omitempty"` + HostName *string `json:"hostName,omitempty"` + OriginGroupName *string `json:"originGroupName,omitempty"` + OriginHostHeader *string `json:"originHostHeader,omitempty"` + Priority *int64 `json:"priority,omitempty"` + SharedPrivateLinkResource *SharedPrivateLinkResourceProperties `json:"sharedPrivateLinkResource,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/model_resourcereference.go b/resource-manager/cdn/2024-02-01/afdorigins/model_resourcereference.go new file mode 100644 index 00000000000..5314652c752 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/model_resourcereference.go @@ -0,0 +1,8 @@ +package afdorigins + +// 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/cdn/2024-02-01/afdorigins/model_sharedprivatelinkresourceproperties.go b/resource-manager/cdn/2024-02-01/afdorigins/model_sharedprivatelinkresourceproperties.go new file mode 100644 index 00000000000..e8a77e5c8c7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/model_sharedprivatelinkresourceproperties.go @@ -0,0 +1,12 @@ +package afdorigins + +// 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,omitempty"` + PrivateLink *ResourceReference `json:"privateLink,omitempty"` + PrivateLinkLocation *string `json:"privateLinkLocation,omitempty"` + RequestMessage *string `json:"requestMessage,omitempty"` + Status *SharedPrivateLinkResourceStatus `json:"status,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdorigins/predicates.go b/resource-manager/cdn/2024-02-01/afdorigins/predicates.go new file mode 100644 index 00000000000..44ceab3f730 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/predicates.go @@ -0,0 +1,27 @@ +package afdorigins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDOriginOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AFDOriginOperationPredicate) Matches(input AFDOrigin) 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/cdn/2024-02-01/afdorigins/version.go b/resource-manager/cdn/2024-02-01/afdorigins/version.go new file mode 100644 index 00000000000..1528239f732 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdorigins/version.go @@ -0,0 +1,12 @@ +package afdorigins + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/afdorigins/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/README.md b/resource-manager/cdn/2024-02-01/afdprofiles/README.md new file mode 100644 index 00000000000..bc980cfe692 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdprofiles` Documentation + +The `afdprofiles` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/afdprofiles" +``` + + +### Client Initialization + +```go +client := afdprofiles.NewAFDProfilesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AFDProfilesClient.CheckEndpointNameAvailability` + +```go +ctx := context.TODO() +id := afdprofiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +payload := afdprofiles.CheckEndpointNameAvailabilityInput{ + // ... +} + + +read, err := client.CheckEndpointNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AFDProfilesClient.CheckHostNameAvailability` + +```go +ctx := context.TODO() +id := afdprofiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +payload := afdprofiles.CheckHostNameAvailabilityInput{ + // ... +} + + +read, err := client.CheckHostNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AFDProfilesClient.ListResourceUsage` + +```go +ctx := context.TODO() +id := afdprofiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListResourceUsage(ctx, id)` can be used to do batched pagination +items, err := client.ListResourceUsageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AFDProfilesClient.Upgrade` + +```go +ctx := context.TODO() +id := afdprofiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +payload := afdprofiles.ProfileUpgradeParameters{ + // ... +} + + +if err := client.UpgradeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AFDProfilesClient.ValidateSecret` + +```go +ctx := context.TODO() +id := afdprofiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +payload := afdprofiles.ValidateSecretInput{ + // ... +} + + +read, err := client.ValidateSecret(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/cdn/2024-02-01/afdprofiles/client.go b/resource-manager/cdn/2024-02-01/afdprofiles/client.go new file mode 100644 index 00000000000..cec01830433 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/client.go @@ -0,0 +1,26 @@ +package afdprofiles + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AFDProfilesClient struct { + Client *resourcemanager.Client +} + +func NewAFDProfilesClientWithBaseURI(sdkApi sdkEnv.Api) (*AFDProfilesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "afdprofiles", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AFDProfilesClient: %+v", err) + } + + return &AFDProfilesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/constants.go b/resource-manager/cdn/2024-02-01/afdprofiles/constants.go new file mode 100644 index 00000000000..c6ab80b56dd --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/constants.go @@ -0,0 +1,580 @@ +package afdprofiles + +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 AutoGeneratedDomainNameLabelScope string + +const ( + AutoGeneratedDomainNameLabelScopeNoReuse AutoGeneratedDomainNameLabelScope = "NoReuse" + AutoGeneratedDomainNameLabelScopeResourceGroupReuse AutoGeneratedDomainNameLabelScope = "ResourceGroupReuse" + AutoGeneratedDomainNameLabelScopeSubscriptionReuse AutoGeneratedDomainNameLabelScope = "SubscriptionReuse" + AutoGeneratedDomainNameLabelScopeTenantReuse AutoGeneratedDomainNameLabelScope = "TenantReuse" +) + +func PossibleValuesForAutoGeneratedDomainNameLabelScope() []string { + return []string{ + string(AutoGeneratedDomainNameLabelScopeNoReuse), + string(AutoGeneratedDomainNameLabelScopeResourceGroupReuse), + string(AutoGeneratedDomainNameLabelScopeSubscriptionReuse), + string(AutoGeneratedDomainNameLabelScopeTenantReuse), + } +} + +func (s *AutoGeneratedDomainNameLabelScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoGeneratedDomainNameLabelScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoGeneratedDomainNameLabelScope(input string) (*AutoGeneratedDomainNameLabelScope, error) { + vals := map[string]AutoGeneratedDomainNameLabelScope{ + "noreuse": AutoGeneratedDomainNameLabelScopeNoReuse, + "resourcegroupreuse": AutoGeneratedDomainNameLabelScopeResourceGroupReuse, + "subscriptionreuse": AutoGeneratedDomainNameLabelScopeSubscriptionReuse, + "tenantreuse": AutoGeneratedDomainNameLabelScopeTenantReuse, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoGeneratedDomainNameLabelScope(input) + return &out, nil +} + +type ProfileProvisioningState string + +const ( + ProfileProvisioningStateCreating ProfileProvisioningState = "Creating" + ProfileProvisioningStateDeleting ProfileProvisioningState = "Deleting" + ProfileProvisioningStateFailed ProfileProvisioningState = "Failed" + ProfileProvisioningStateSucceeded ProfileProvisioningState = "Succeeded" + ProfileProvisioningStateUpdating ProfileProvisioningState = "Updating" +) + +func PossibleValuesForProfileProvisioningState() []string { + return []string{ + string(ProfileProvisioningStateCreating), + string(ProfileProvisioningStateDeleting), + string(ProfileProvisioningStateFailed), + string(ProfileProvisioningStateSucceeded), + string(ProfileProvisioningStateUpdating), + } +} + +func (s *ProfileProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileProvisioningState(input string) (*ProfileProvisioningState, error) { + vals := map[string]ProfileProvisioningState{ + "creating": ProfileProvisioningStateCreating, + "deleting": ProfileProvisioningStateDeleting, + "failed": ProfileProvisioningStateFailed, + "succeeded": ProfileProvisioningStateSucceeded, + "updating": ProfileProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileProvisioningState(input) + return &out, nil +} + +type ProfileResourceState string + +const ( + ProfileResourceStateAbortingMigration ProfileResourceState = "AbortingMigration" + ProfileResourceStateActive ProfileResourceState = "Active" + ProfileResourceStateCommittingMigration ProfileResourceState = "CommittingMigration" + ProfileResourceStateCreating ProfileResourceState = "Creating" + ProfileResourceStateDeleting ProfileResourceState = "Deleting" + ProfileResourceStateDisabled ProfileResourceState = "Disabled" + ProfileResourceStateMigrated ProfileResourceState = "Migrated" + ProfileResourceStateMigrating ProfileResourceState = "Migrating" + ProfileResourceStatePendingMigrationCommit ProfileResourceState = "PendingMigrationCommit" +) + +func PossibleValuesForProfileResourceState() []string { + return []string{ + string(ProfileResourceStateAbortingMigration), + string(ProfileResourceStateActive), + string(ProfileResourceStateCommittingMigration), + string(ProfileResourceStateCreating), + string(ProfileResourceStateDeleting), + string(ProfileResourceStateDisabled), + string(ProfileResourceStateMigrated), + string(ProfileResourceStateMigrating), + string(ProfileResourceStatePendingMigrationCommit), + } +} + +func (s *ProfileResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileResourceState(input string) (*ProfileResourceState, error) { + vals := map[string]ProfileResourceState{ + "abortingmigration": ProfileResourceStateAbortingMigration, + "active": ProfileResourceStateActive, + "committingmigration": ProfileResourceStateCommittingMigration, + "creating": ProfileResourceStateCreating, + "deleting": ProfileResourceStateDeleting, + "disabled": ProfileResourceStateDisabled, + "migrated": ProfileResourceStateMigrated, + "migrating": ProfileResourceStateMigrating, + "pendingmigrationcommit": ProfileResourceStatePendingMigrationCommit, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileResourceState(input) + return &out, nil +} + +type ProfileScrubbingState string + +const ( + ProfileScrubbingStateDisabled ProfileScrubbingState = "Disabled" + ProfileScrubbingStateEnabled ProfileScrubbingState = "Enabled" +) + +func PossibleValuesForProfileScrubbingState() []string { + return []string{ + string(ProfileScrubbingStateDisabled), + string(ProfileScrubbingStateEnabled), + } +} + +func (s *ProfileScrubbingState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileScrubbingState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileScrubbingState(input string) (*ProfileScrubbingState, error) { + vals := map[string]ProfileScrubbingState{ + "disabled": ProfileScrubbingStateDisabled, + "enabled": ProfileScrubbingStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileScrubbingState(input) + return &out, nil +} + +type ResourceType string + +const ( + ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints ResourceType = "Microsoft.Cdn/Profiles/AfdEndpoints" + ResourceTypeMicrosoftPointCdnProfilesEndpoints ResourceType = "Microsoft.Cdn/Profiles/Endpoints" +) + +func PossibleValuesForResourceType() []string { + return []string{ + string(ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints), + string(ResourceTypeMicrosoftPointCdnProfilesEndpoints), + } +} + +func (s *ResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceType(input string) (*ResourceType, error) { + vals := map[string]ResourceType{ + "microsoft.cdn/profiles/afdendpoints": ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints, + "microsoft.cdn/profiles/endpoints": ResourceTypeMicrosoftPointCdnProfilesEndpoints, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceType(input) + return &out, nil +} + +type ScrubbingRuleEntryMatchOperator string + +const ( + ScrubbingRuleEntryMatchOperatorEqualsAny ScrubbingRuleEntryMatchOperator = "EqualsAny" +) + +func PossibleValuesForScrubbingRuleEntryMatchOperator() []string { + return []string{ + string(ScrubbingRuleEntryMatchOperatorEqualsAny), + } +} + +func (s *ScrubbingRuleEntryMatchOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryMatchOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryMatchOperator(input string) (*ScrubbingRuleEntryMatchOperator, error) { + vals := map[string]ScrubbingRuleEntryMatchOperator{ + "equalsany": ScrubbingRuleEntryMatchOperatorEqualsAny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryMatchOperator(input) + return &out, nil +} + +type ScrubbingRuleEntryMatchVariable string + +const ( + ScrubbingRuleEntryMatchVariableQueryStringArgNames ScrubbingRuleEntryMatchVariable = "QueryStringArgNames" + ScrubbingRuleEntryMatchVariableRequestIPAddress ScrubbingRuleEntryMatchVariable = "RequestIPAddress" + ScrubbingRuleEntryMatchVariableRequestUri ScrubbingRuleEntryMatchVariable = "RequestUri" +) + +func PossibleValuesForScrubbingRuleEntryMatchVariable() []string { + return []string{ + string(ScrubbingRuleEntryMatchVariableQueryStringArgNames), + string(ScrubbingRuleEntryMatchVariableRequestIPAddress), + string(ScrubbingRuleEntryMatchVariableRequestUri), + } +} + +func (s *ScrubbingRuleEntryMatchVariable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryMatchVariable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryMatchVariable(input string) (*ScrubbingRuleEntryMatchVariable, error) { + vals := map[string]ScrubbingRuleEntryMatchVariable{ + "querystringargnames": ScrubbingRuleEntryMatchVariableQueryStringArgNames, + "requestipaddress": ScrubbingRuleEntryMatchVariableRequestIPAddress, + "requesturi": ScrubbingRuleEntryMatchVariableRequestUri, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryMatchVariable(input) + return &out, nil +} + +type ScrubbingRuleEntryState string + +const ( + ScrubbingRuleEntryStateDisabled ScrubbingRuleEntryState = "Disabled" + ScrubbingRuleEntryStateEnabled ScrubbingRuleEntryState = "Enabled" +) + +func PossibleValuesForScrubbingRuleEntryState() []string { + return []string{ + string(ScrubbingRuleEntryStateDisabled), + string(ScrubbingRuleEntryStateEnabled), + } +} + +func (s *ScrubbingRuleEntryState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryState(input string) (*ScrubbingRuleEntryState, error) { + vals := map[string]ScrubbingRuleEntryState{ + "disabled": ScrubbingRuleEntryStateDisabled, + "enabled": ScrubbingRuleEntryStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryState(input) + return &out, nil +} + +type SecretType string + +const ( + SecretTypeAzureFirstPartyManagedCertificate SecretType = "AzureFirstPartyManagedCertificate" + SecretTypeCustomerCertificate SecretType = "CustomerCertificate" + SecretTypeManagedCertificate SecretType = "ManagedCertificate" + SecretTypeUrlSigningKey SecretType = "UrlSigningKey" +) + +func PossibleValuesForSecretType() []string { + return []string{ + string(SecretTypeAzureFirstPartyManagedCertificate), + string(SecretTypeCustomerCertificate), + string(SecretTypeManagedCertificate), + string(SecretTypeUrlSigningKey), + } +} + +func (s *SecretType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretType(input string) (*SecretType, error) { + vals := map[string]SecretType{ + "azurefirstpartymanagedcertificate": SecretTypeAzureFirstPartyManagedCertificate, + "customercertificate": SecretTypeCustomerCertificate, + "managedcertificate": SecretTypeManagedCertificate, + "urlsigningkey": SecretTypeUrlSigningKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretType(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameCustomVerizon SkuName = "Custom_Verizon" + SkuNamePremiumAzureFrontDoor SkuName = "Premium_AzureFrontDoor" + SkuNamePremiumVerizon SkuName = "Premium_Verizon" + SkuNameStandardAkamai SkuName = "Standard_Akamai" + SkuNameStandardAvgBandWidthChinaCdn SkuName = "Standard_AvgBandWidth_ChinaCdn" + SkuNameStandardAzureFrontDoor SkuName = "Standard_AzureFrontDoor" + SkuNameStandardChinaCdn SkuName = "Standard_ChinaCdn" + SkuNameStandardMicrosoft SkuName = "Standard_Microsoft" + SkuNameStandardNineFiveFiveBandWidthChinaCdn SkuName = "Standard_955BandWidth_ChinaCdn" + SkuNameStandardPlusAvgBandWidthChinaCdn SkuName = "StandardPlus_AvgBandWidth_ChinaCdn" + SkuNameStandardPlusChinaCdn SkuName = "StandardPlus_ChinaCdn" + SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn SkuName = "StandardPlus_955BandWidth_ChinaCdn" + SkuNameStandardVerizon SkuName = "Standard_Verizon" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameCustomVerizon), + string(SkuNamePremiumAzureFrontDoor), + string(SkuNamePremiumVerizon), + string(SkuNameStandardAkamai), + string(SkuNameStandardAvgBandWidthChinaCdn), + string(SkuNameStandardAzureFrontDoor), + string(SkuNameStandardChinaCdn), + string(SkuNameStandardMicrosoft), + string(SkuNameStandardNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardPlusAvgBandWidthChinaCdn), + string(SkuNameStandardPlusChinaCdn), + string(SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardVerizon), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "custom_verizon": SkuNameCustomVerizon, + "premium_azurefrontdoor": SkuNamePremiumAzureFrontDoor, + "premium_verizon": SkuNamePremiumVerizon, + "standard_akamai": SkuNameStandardAkamai, + "standard_avgbandwidth_chinacdn": SkuNameStandardAvgBandWidthChinaCdn, + "standard_azurefrontdoor": SkuNameStandardAzureFrontDoor, + "standard_chinacdn": SkuNameStandardChinaCdn, + "standard_microsoft": SkuNameStandardMicrosoft, + "standard_955bandwidth_chinacdn": SkuNameStandardNineFiveFiveBandWidthChinaCdn, + "standardplus_avgbandwidth_chinacdn": SkuNameStandardPlusAvgBandWidthChinaCdn, + "standardplus_chinacdn": SkuNameStandardPlusChinaCdn, + "standardplus_955bandwidth_chinacdn": SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn, + "standard_verizon": SkuNameStandardVerizon, + } + 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 Status string + +const ( + StatusAccessDenied Status = "AccessDenied" + StatusCertificateExpired Status = "CertificateExpired" + StatusInvalid Status = "Invalid" + StatusValid Status = "Valid" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusAccessDenied), + string(StatusCertificateExpired), + string(StatusInvalid), + string(StatusValid), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "accessdenied": StatusAccessDenied, + "certificateexpired": StatusCertificateExpired, + "invalid": StatusInvalid, + "valid": StatusValid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} + +type UsageUnit string + +const ( + UsageUnitCount UsageUnit = "Count" +) + +func PossibleValuesForUsageUnit() []string { + return []string{ + string(UsageUnitCount), + } +} + +func (s *UsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUsageUnit(input string) (*UsageUnit, error) { + vals := map[string]UsageUnit{ + "count": UsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsageUnit(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/id_profile.go b/resource-manager/cdn/2024-02-01/afdprofiles/id_profile.go new file mode 100644 index 00000000000..9b0ea1eab5d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/id_profile.go @@ -0,0 +1,130 @@ +package afdprofiles + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/id_profile_test.go b/resource-manager/cdn/2024-02-01/afdprofiles/id_profile_test.go new file mode 100644 index 00000000000..12fc61892f2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/id_profile_test.go @@ -0,0 +1,282 @@ +package afdprofiles + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/afdprofiles/method_checkendpointnameavailability.go b/resource-manager/cdn/2024-02-01/afdprofiles/method_checkendpointnameavailability.go new file mode 100644 index 00000000000..cc1efdc6606 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/method_checkendpointnameavailability.go @@ -0,0 +1,59 @@ +package afdprofiles + +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 CheckEndpointNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckEndpointNameAvailabilityOutput +} + +// CheckEndpointNameAvailability ... +func (c AFDProfilesClient) CheckEndpointNameAvailability(ctx context.Context, id ProfileId, input CheckEndpointNameAvailabilityInput) (result CheckEndpointNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkEndpointNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckEndpointNameAvailabilityOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/method_checkhostnameavailability.go b/resource-manager/cdn/2024-02-01/afdprofiles/method_checkhostnameavailability.go new file mode 100644 index 00000000000..383339f47cf --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/method_checkhostnameavailability.go @@ -0,0 +1,59 @@ +package afdprofiles + +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 CheckHostNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityOutput +} + +// CheckHostNameAvailability ... +func (c AFDProfilesClient) CheckHostNameAvailability(ctx context.Context, id ProfileId, input CheckHostNameAvailabilityInput) (result CheckHostNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkHostNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/method_listresourceusage.go b/resource-manager/cdn/2024-02-01/afdprofiles/method_listresourceusage.go new file mode 100644 index 00000000000..e0cb859dc7e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/method_listresourceusage.go @@ -0,0 +1,105 @@ +package afdprofiles + +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 ListResourceUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ListResourceUsageCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ListResourceUsageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListResourceUsageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListResourceUsage ... +func (c AFDProfilesClient) ListResourceUsage(ctx context.Context, id ProfileId) (result ListResourceUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListResourceUsageCustomPager{}, + 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 *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourceUsageComplete retrieves all the results into a single object +func (c AFDProfilesClient) ListResourceUsageComplete(ctx context.Context, id ProfileId) (ListResourceUsageCompleteResult, error) { + return c.ListResourceUsageCompleteMatchingPredicate(ctx, id, UsageOperationPredicate{}) +} + +// ListResourceUsageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AFDProfilesClient) ListResourceUsageCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate UsageOperationPredicate) (result ListResourceUsageCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.ListResourceUsage(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListResourceUsageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/method_upgrade.go b/resource-manager/cdn/2024-02-01/afdprofiles/method_upgrade.go new file mode 100644 index 00000000000..42c2540b228 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/method_upgrade.go @@ -0,0 +1,75 @@ +package afdprofiles + +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 UpgradeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Profile +} + +// Upgrade ... +func (c AFDProfilesClient) Upgrade(ctx context.Context, id ProfileId, input ProfileUpgradeParameters) (result UpgradeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/upgrade", 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 +} + +// UpgradeThenPoll performs Upgrade then polls until it's completed +func (c AFDProfilesClient) UpgradeThenPoll(ctx context.Context, id ProfileId, input ProfileUpgradeParameters) error { + result, err := c.Upgrade(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Upgrade: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Upgrade: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/method_validatesecret.go b/resource-manager/cdn/2024-02-01/afdprofiles/method_validatesecret.go new file mode 100644 index 00000000000..387261b66c0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/method_validatesecret.go @@ -0,0 +1,59 @@ +package afdprofiles + +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 ValidateSecretOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ValidateSecretOutput +} + +// ValidateSecret ... +func (c AFDProfilesClient) ValidateSecret(ctx context.Context, id ProfileId, input ValidateSecretInput) (result ValidateSecretOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateSecret", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ValidateSecretOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_checkendpointnameavailabilityinput.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_checkendpointnameavailabilityinput.go new file mode 100644 index 00000000000..96f0f41765e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_checkendpointnameavailabilityinput.go @@ -0,0 +1,10 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckEndpointNameAvailabilityInput struct { + AutoGeneratedDomainNameLabelScope *AutoGeneratedDomainNameLabelScope `json:"autoGeneratedDomainNameLabelScope,omitempty"` + Name string `json:"name"` + Type ResourceType `json:"type"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_checkendpointnameavailabilityoutput.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_checkendpointnameavailabilityoutput.go new file mode 100644 index 00000000000..0be9e951f73 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_checkendpointnameavailabilityoutput.go @@ -0,0 +1,11 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckEndpointNameAvailabilityOutput struct { + AvailableHostname *string `json:"availableHostname,omitempty"` + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_checkhostnameavailabilityinput.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_checkhostnameavailabilityinput.go new file mode 100644 index 00000000000..b8248d20fbb --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_checkhostnameavailabilityinput.go @@ -0,0 +1,8 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckHostNameAvailabilityInput struct { + HostName string `json:"hostName"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_checknameavailabilityoutput.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_checknameavailabilityoutput.go new file mode 100644 index 00000000000..18e961a7842 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_checknameavailabilityoutput.go @@ -0,0 +1,10 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOutput struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_profile.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_profile.go new file mode 100644 index 00000000000..f2093113bb4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_profile.go @@ -0,0 +1,22 @@ +package afdprofiles + +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 Profile struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ProfileProperties `json:"properties,omitempty"` + Sku Sku `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_profilechangeskuwafmapping.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_profilechangeskuwafmapping.go new file mode 100644 index 00000000000..1e289e8c1fb --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_profilechangeskuwafmapping.go @@ -0,0 +1,9 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileChangeSkuWafMapping struct { + ChangeToWafPolicy ResourceReference `json:"changeToWafPolicy"` + SecurityPolicyName string `json:"securityPolicyName"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_profilelogscrubbing.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_profilelogscrubbing.go new file mode 100644 index 00000000000..6f89bfd997b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_profilelogscrubbing.go @@ -0,0 +1,9 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileLogScrubbing struct { + ScrubbingRules *[]ProfileScrubbingRules `json:"scrubbingRules,omitempty"` + State *ProfileScrubbingState `json:"state,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_profileproperties.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_profileproperties.go new file mode 100644 index 00000000000..72356670dfc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_profileproperties.go @@ -0,0 +1,13 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileProperties struct { + ExtendedProperties *map[string]string `json:"extendedProperties,omitempty"` + FrontDoorId *string `json:"frontDoorId,omitempty"` + LogScrubbing *ProfileLogScrubbing `json:"logScrubbing,omitempty"` + OriginResponseTimeoutSeconds *int64 `json:"originResponseTimeoutSeconds,omitempty"` + ProvisioningState *ProfileProvisioningState `json:"provisioningState,omitempty"` + ResourceState *ProfileResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_profilescrubbingrules.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_profilescrubbingrules.go new file mode 100644 index 00000000000..332a2f30281 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_profilescrubbingrules.go @@ -0,0 +1,11 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileScrubbingRules struct { + MatchVariable ScrubbingRuleEntryMatchVariable `json:"matchVariable"` + Selector *string `json:"selector,omitempty"` + SelectorMatchOperator ScrubbingRuleEntryMatchOperator `json:"selectorMatchOperator"` + State *ScrubbingRuleEntryState `json:"state,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_profileupgradeparameters.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_profileupgradeparameters.go new file mode 100644 index 00000000000..2fe3ac4982d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_profileupgradeparameters.go @@ -0,0 +1,8 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileUpgradeParameters struct { + WafMappingList []ProfileChangeSkuWafMapping `json:"wafMappingList"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_resourcereference.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_resourcereference.go new file mode 100644 index 00000000000..6444e52fde2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_resourcereference.go @@ -0,0 +1,8 @@ +package afdprofiles + +// 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/cdn/2024-02-01/afdprofiles/model_sku.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_sku.go new file mode 100644 index 00000000000..cb55c9a874a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_sku.go @@ -0,0 +1,8 @@ +package afdprofiles + +// 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 { + Name *SkuName `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_usage.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_usage.go new file mode 100644 index 00000000000..7cc8e126873 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_usage.go @@ -0,0 +1,12 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Usage struct { + CurrentValue int64 `json:"currentValue"` + Id *string `json:"id,omitempty"` + Limit int64 `json:"limit"` + Name UsageName `json:"name"` + Unit UsageUnit `json:"unit"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_usagename.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_usagename.go new file mode 100644 index 00000000000..5540d53cdd5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_usagename.go @@ -0,0 +1,9 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_validatesecretinput.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_validatesecretinput.go new file mode 100644 index 00000000000..d4e3198b21a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_validatesecretinput.go @@ -0,0 +1,10 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateSecretInput struct { + SecretSource ResourceReference `json:"secretSource"` + SecretType SecretType `json:"secretType"` + SecretVersion *string `json:"secretVersion,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/model_validatesecretoutput.go b/resource-manager/cdn/2024-02-01/afdprofiles/model_validatesecretoutput.go new file mode 100644 index 00000000000..6a68c34cdd4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/model_validatesecretoutput.go @@ -0,0 +1,9 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateSecretOutput struct { + Message *string `json:"message,omitempty"` + Status *Status `json:"status,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/predicates.go b/resource-manager/cdn/2024-02-01/afdprofiles/predicates.go new file mode 100644 index 00000000000..0642e103835 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/predicates.go @@ -0,0 +1,27 @@ +package afdprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.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 && *p.Limit != input.Limit { + return false + } + + return true +} diff --git a/resource-manager/cdn/2024-02-01/afdprofiles/version.go b/resource-manager/cdn/2024-02-01/afdprofiles/version.go new file mode 100644 index 00000000000..7c747c1ea9f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/afdprofiles/version.go @@ -0,0 +1,12 @@ +package afdprofiles + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/afdprofiles/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/checkendpointnameavailability/README.md b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/README.md new file mode 100644 index 00000000000..c8c26894341 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checkendpointnameavailability` Documentation + +The `checkendpointnameavailability` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checkendpointnameavailability" +``` + + +### Client Initialization + +```go +client := checkendpointnameavailability.NewCheckEndpointNameAvailabilityClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CheckEndpointNameAvailabilityClient.CheckEndpointNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := checkendpointnameavailability.CheckEndpointNameAvailabilityInput{ + // ... +} + + +read, err := client.CheckEndpointNameAvailability(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/cdn/2024-02-01/checkendpointnameavailability/client.go b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/client.go new file mode 100644 index 00000000000..1c01b225a53 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/client.go @@ -0,0 +1,26 @@ +package checkendpointnameavailability + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckEndpointNameAvailabilityClient struct { + Client *resourcemanager.Client +} + +func NewCheckEndpointNameAvailabilityClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckEndpointNameAvailabilityClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checkendpointnameavailability", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckEndpointNameAvailabilityClient: %+v", err) + } + + return &CheckEndpointNameAvailabilityClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/checkendpointnameavailability/constants.go b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/constants.go new file mode 100644 index 00000000000..0197e78fa00 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/constants.go @@ -0,0 +1,98 @@ +package checkendpointnameavailability + +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 AutoGeneratedDomainNameLabelScope string + +const ( + AutoGeneratedDomainNameLabelScopeNoReuse AutoGeneratedDomainNameLabelScope = "NoReuse" + AutoGeneratedDomainNameLabelScopeResourceGroupReuse AutoGeneratedDomainNameLabelScope = "ResourceGroupReuse" + AutoGeneratedDomainNameLabelScopeSubscriptionReuse AutoGeneratedDomainNameLabelScope = "SubscriptionReuse" + AutoGeneratedDomainNameLabelScopeTenantReuse AutoGeneratedDomainNameLabelScope = "TenantReuse" +) + +func PossibleValuesForAutoGeneratedDomainNameLabelScope() []string { + return []string{ + string(AutoGeneratedDomainNameLabelScopeNoReuse), + string(AutoGeneratedDomainNameLabelScopeResourceGroupReuse), + string(AutoGeneratedDomainNameLabelScopeSubscriptionReuse), + string(AutoGeneratedDomainNameLabelScopeTenantReuse), + } +} + +func (s *AutoGeneratedDomainNameLabelScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoGeneratedDomainNameLabelScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoGeneratedDomainNameLabelScope(input string) (*AutoGeneratedDomainNameLabelScope, error) { + vals := map[string]AutoGeneratedDomainNameLabelScope{ + "noreuse": AutoGeneratedDomainNameLabelScopeNoReuse, + "resourcegroupreuse": AutoGeneratedDomainNameLabelScopeResourceGroupReuse, + "subscriptionreuse": AutoGeneratedDomainNameLabelScopeSubscriptionReuse, + "tenantreuse": AutoGeneratedDomainNameLabelScopeTenantReuse, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoGeneratedDomainNameLabelScope(input) + return &out, nil +} + +type ResourceType string + +const ( + ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints ResourceType = "Microsoft.Cdn/Profiles/AfdEndpoints" + ResourceTypeMicrosoftPointCdnProfilesEndpoints ResourceType = "Microsoft.Cdn/Profiles/Endpoints" +) + +func PossibleValuesForResourceType() []string { + return []string{ + string(ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints), + string(ResourceTypeMicrosoftPointCdnProfilesEndpoints), + } +} + +func (s *ResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceType(input string) (*ResourceType, error) { + vals := map[string]ResourceType{ + "microsoft.cdn/profiles/afdendpoints": ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints, + "microsoft.cdn/profiles/endpoints": ResourceTypeMicrosoftPointCdnProfilesEndpoints, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceType(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/checkendpointnameavailability/method_checkendpointnameavailability.go b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/method_checkendpointnameavailability.go new file mode 100644 index 00000000000..590bf2a4f1b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/method_checkendpointnameavailability.go @@ -0,0 +1,60 @@ +package checkendpointnameavailability + +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 CheckEndpointNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckEndpointNameAvailabilityOutput +} + +// CheckEndpointNameAvailability ... +func (c CheckEndpointNameAvailabilityClient) CheckEndpointNameAvailability(ctx context.Context, id commonids.ResourceGroupId, input CheckEndpointNameAvailabilityInput) (result CheckEndpointNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/checkEndpointNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckEndpointNameAvailabilityOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/checkendpointnameavailability/model_checkendpointnameavailabilityinput.go b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/model_checkendpointnameavailabilityinput.go new file mode 100644 index 00000000000..381cce48b2f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/model_checkendpointnameavailabilityinput.go @@ -0,0 +1,10 @@ +package checkendpointnameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckEndpointNameAvailabilityInput struct { + AutoGeneratedDomainNameLabelScope *AutoGeneratedDomainNameLabelScope `json:"autoGeneratedDomainNameLabelScope,omitempty"` + Name string `json:"name"` + Type ResourceType `json:"type"` +} diff --git a/resource-manager/cdn/2024-02-01/checkendpointnameavailability/model_checkendpointnameavailabilityoutput.go b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/model_checkendpointnameavailabilityoutput.go new file mode 100644 index 00000000000..b78fec5b55e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/model_checkendpointnameavailabilityoutput.go @@ -0,0 +1,11 @@ +package checkendpointnameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckEndpointNameAvailabilityOutput struct { + AvailableHostname *string `json:"availableHostname,omitempty"` + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/checkendpointnameavailability/version.go b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/version.go new file mode 100644 index 00000000000..4ee2fc2654e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checkendpointnameavailability/version.go @@ -0,0 +1,12 @@ +package checkendpointnameavailability + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/checkendpointnameavailability/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailability/README.md b/resource-manager/cdn/2024-02-01/checknameavailability/README.md new file mode 100644 index 00000000000..7f0daa8039b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailability/README.md @@ -0,0 +1,40 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checknameavailability` Documentation + +The `checknameavailability` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/checknameavailability" +``` + + +### Client Initialization + +```go +client := checknameavailability.NewCheckNameAvailabilityClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CheckNameAvailabilityClient.CheckNameAvailability` + +```go +ctx := context.TODO() + +payload := checknameavailability.CheckNameAvailabilityInput{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, 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/cdn/2024-02-01/checknameavailability/client.go b/resource-manager/cdn/2024-02-01/checknameavailability/client.go new file mode 100644 index 00000000000..9991e58a518 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailability/client.go @@ -0,0 +1,26 @@ +package checknameavailability + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityClient struct { + Client *resourcemanager.Client +} + +func NewCheckNameAvailabilityClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckNameAvailabilityClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checknameavailability", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckNameAvailabilityClient: %+v", err) + } + + return &CheckNameAvailabilityClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailability/constants.go b/resource-manager/cdn/2024-02-01/checknameavailability/constants.go new file mode 100644 index 00000000000..bf58e64a60c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailability/constants.go @@ -0,0 +1,51 @@ +package checknameavailability + +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 ResourceType string + +const ( + ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints ResourceType = "Microsoft.Cdn/Profiles/AfdEndpoints" + ResourceTypeMicrosoftPointCdnProfilesEndpoints ResourceType = "Microsoft.Cdn/Profiles/Endpoints" +) + +func PossibleValuesForResourceType() []string { + return []string{ + string(ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints), + string(ResourceTypeMicrosoftPointCdnProfilesEndpoints), + } +} + +func (s *ResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceType(input string) (*ResourceType, error) { + vals := map[string]ResourceType{ + "microsoft.cdn/profiles/afdendpoints": ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints, + "microsoft.cdn/profiles/endpoints": ResourceTypeMicrosoftPointCdnProfilesEndpoints, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceType(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailability/method_checknameavailability.go b/resource-manager/cdn/2024-02-01/checknameavailability/method_checknameavailability.go new file mode 100644 index 00000000000..b28294ab3c4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailability/method_checknameavailability.go @@ -0,0 +1,58 @@ +package checknameavailability + +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 CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityOutput +} + +// CheckNameAvailability ... +func (c CheckNameAvailabilityClient) CheckNameAvailability(ctx context.Context, input CheckNameAvailabilityInput) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: "/providers/Microsoft.CDN/checkNameAvailability", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailability/model_checknameavailabilityinput.go b/resource-manager/cdn/2024-02-01/checknameavailability/model_checknameavailabilityinput.go new file mode 100644 index 00000000000..36311e975a8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailability/model_checknameavailabilityinput.go @@ -0,0 +1,9 @@ +package checknameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityInput struct { + Name string `json:"name"` + Type ResourceType `json:"type"` +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailability/model_checknameavailabilityoutput.go b/resource-manager/cdn/2024-02-01/checknameavailability/model_checknameavailabilityoutput.go new file mode 100644 index 00000000000..8b591ca1f86 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailability/model_checknameavailabilityoutput.go @@ -0,0 +1,10 @@ +package checknameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOutput struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailability/version.go b/resource-manager/cdn/2024-02-01/checknameavailability/version.go new file mode 100644 index 00000000000..e43d7329c52 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailability/version.go @@ -0,0 +1,12 @@ +package checknameavailability + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/checknameavailability/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/README.md b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/README.md new file mode 100644 index 00000000000..8026ffe1b10 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription` Documentation + +The `checknameavailabilitywithsubscription` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription" +``` + + +### Client Initialization + +```go +client := checknameavailabilitywithsubscription.NewCheckNameAvailabilityWithSubscriptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CheckNameAvailabilityWithSubscriptionClient.CheckNameAvailabilityWithSubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := checknameavailabilitywithsubscription.CheckNameAvailabilityInput{ + // ... +} + + +read, err := client.CheckNameAvailabilityWithSubscription(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/cdn/2024-02-01/checknameavailabilitywithsubscription/client.go b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/client.go new file mode 100644 index 00000000000..e11f1cb5bb7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/client.go @@ -0,0 +1,26 @@ +package checknameavailabilitywithsubscription + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityWithSubscriptionClient struct { + Client *resourcemanager.Client +} + +func NewCheckNameAvailabilityWithSubscriptionClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckNameAvailabilityWithSubscriptionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checknameavailabilitywithsubscription", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckNameAvailabilityWithSubscriptionClient: %+v", err) + } + + return &CheckNameAvailabilityWithSubscriptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/constants.go b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/constants.go new file mode 100644 index 00000000000..8dc9ec77e49 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/constants.go @@ -0,0 +1,51 @@ +package checknameavailabilitywithsubscription + +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 ResourceType string + +const ( + ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints ResourceType = "Microsoft.Cdn/Profiles/AfdEndpoints" + ResourceTypeMicrosoftPointCdnProfilesEndpoints ResourceType = "Microsoft.Cdn/Profiles/Endpoints" +) + +func PossibleValuesForResourceType() []string { + return []string{ + string(ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints), + string(ResourceTypeMicrosoftPointCdnProfilesEndpoints), + } +} + +func (s *ResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceType(input string) (*ResourceType, error) { + vals := map[string]ResourceType{ + "microsoft.cdn/profiles/afdendpoints": ResourceTypeMicrosoftPointCdnProfilesAfdEndpoints, + "microsoft.cdn/profiles/endpoints": ResourceTypeMicrosoftPointCdnProfilesEndpoints, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceType(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/method_checknameavailabilitywithsubscription.go b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/method_checknameavailabilitywithsubscription.go new file mode 100644 index 00000000000..4a64e35db14 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/method_checknameavailabilitywithsubscription.go @@ -0,0 +1,60 @@ +package checknameavailabilitywithsubscription + +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 CheckNameAvailabilityWithSubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityOutput +} + +// CheckNameAvailabilityWithSubscription ... +func (c CheckNameAvailabilityWithSubscriptionClient) CheckNameAvailabilityWithSubscription(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailabilityInput) (result CheckNameAvailabilityWithSubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/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 + } + + var model CheckNameAvailabilityOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/model_checknameavailabilityinput.go b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/model_checknameavailabilityinput.go new file mode 100644 index 00000000000..5025305279a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/model_checknameavailabilityinput.go @@ -0,0 +1,9 @@ +package checknameavailabilitywithsubscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityInput struct { + Name string `json:"name"` + Type ResourceType `json:"type"` +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/model_checknameavailabilityoutput.go b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/model_checknameavailabilityoutput.go new file mode 100644 index 00000000000..9c0781a0b16 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/model_checknameavailabilityoutput.go @@ -0,0 +1,10 @@ +package checknameavailabilitywithsubscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOutput struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/version.go b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/version.go new file mode 100644 index 00000000000..7b16c79f7b4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription/version.go @@ -0,0 +1,12 @@ +package checknameavailabilitywithsubscription + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/checknameavailabilitywithsubscription/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/client.go b/resource-manager/cdn/2024-02-01/client.go new file mode 100644 index 00000000000..0c42b62c68f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/client.go @@ -0,0 +1,235 @@ +package v2024_02_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdcustomdomains" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdendpoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdorigingroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdorigins" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/afdprofiles" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checkendpointnameavailability" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checknameavailability" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/checknameavailabilitywithsubscription" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/customdomains" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/edgenodes" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/endpoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/loganalytics" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/origingroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/origins" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/routes" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/rules" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/rulesets" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/secrets" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/validateprobe" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/wafloganalytics" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AFDCustomDomains *afdcustomdomains.AFDCustomDomainsClient + AFDEndpoints *afdendpoints.AFDEndpointsClient + AFDOriginGroups *afdorigingroups.AFDOriginGroupsClient + AFDOrigins *afdorigins.AFDOriginsClient + AFDProfiles *afdprofiles.AFDProfilesClient + CheckEndpointNameAvailability *checkendpointnameavailability.CheckEndpointNameAvailabilityClient + CheckNameAvailability *checknameavailability.CheckNameAvailabilityClient + CheckNameAvailabilityWithSubscription *checknameavailabilitywithsubscription.CheckNameAvailabilityWithSubscriptionClient + CustomDomains *customdomains.CustomDomainsClient + Edgenodes *edgenodes.EdgenodesClient + Endpoints *endpoints.EndpointsClient + LogAnalytics *loganalytics.LogAnalyticsClient + OriginGroups *origingroups.OriginGroupsClient + Origins *origins.OriginsClient + Profiles *profiles.ProfilesClient + Routes *routes.RoutesClient + RuleSets *rulesets.RuleSetsClient + Rules *rules.RulesClient + Secrets *secrets.SecretsClient + SecurityPolicies *securitypolicies.SecurityPoliciesClient + ValidateProbe *validateprobe.ValidateProbeClient + WafLogAnalytics *wafloganalytics.WafLogAnalyticsClient + WebApplicationFirewallManagedRuleSets *webapplicationfirewallmanagedrulesets.WebApplicationFirewallManagedRuleSetsClient + WebApplicationFirewallPolicies *webapplicationfirewallpolicies.WebApplicationFirewallPoliciesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + aFDCustomDomainsClient, err := afdcustomdomains.NewAFDCustomDomainsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AFDCustomDomains client: %+v", err) + } + configureFunc(aFDCustomDomainsClient.Client) + + aFDEndpointsClient, err := afdendpoints.NewAFDEndpointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AFDEndpoints client: %+v", err) + } + configureFunc(aFDEndpointsClient.Client) + + aFDOriginGroupsClient, err := afdorigingroups.NewAFDOriginGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AFDOriginGroups client: %+v", err) + } + configureFunc(aFDOriginGroupsClient.Client) + + aFDOriginsClient, err := afdorigins.NewAFDOriginsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AFDOrigins client: %+v", err) + } + configureFunc(aFDOriginsClient.Client) + + aFDProfilesClient, err := afdprofiles.NewAFDProfilesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AFDProfiles client: %+v", err) + } + configureFunc(aFDProfilesClient.Client) + + checkEndpointNameAvailabilityClient, err := checkendpointnameavailability.NewCheckEndpointNameAvailabilityClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckEndpointNameAvailability client: %+v", err) + } + configureFunc(checkEndpointNameAvailabilityClient.Client) + + checkNameAvailabilityClient, err := checknameavailability.NewCheckNameAvailabilityClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckNameAvailability client: %+v", err) + } + configureFunc(checkNameAvailabilityClient.Client) + + checkNameAvailabilityWithSubscriptionClient, err := checknameavailabilitywithsubscription.NewCheckNameAvailabilityWithSubscriptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckNameAvailabilityWithSubscription client: %+v", err) + } + configureFunc(checkNameAvailabilityWithSubscriptionClient.Client) + + customDomainsClient, err := customdomains.NewCustomDomainsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CustomDomains client: %+v", err) + } + configureFunc(customDomainsClient.Client) + + edgenodesClient, err := edgenodes.NewEdgenodesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Edgenodes client: %+v", err) + } + configureFunc(edgenodesClient.Client) + + endpointsClient, err := endpoints.NewEndpointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Endpoints client: %+v", err) + } + configureFunc(endpointsClient.Client) + + logAnalyticsClient, err := loganalytics.NewLogAnalyticsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LogAnalytics client: %+v", err) + } + configureFunc(logAnalyticsClient.Client) + + originGroupsClient, err := origingroups.NewOriginGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building OriginGroups client: %+v", err) + } + configureFunc(originGroupsClient.Client) + + originsClient, err := origins.NewOriginsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Origins client: %+v", err) + } + configureFunc(originsClient.Client) + + profilesClient, err := profiles.NewProfilesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Profiles client: %+v", err) + } + configureFunc(profilesClient.Client) + + routesClient, err := routes.NewRoutesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Routes client: %+v", err) + } + configureFunc(routesClient.Client) + + ruleSetsClient, err := rulesets.NewRuleSetsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RuleSets client: %+v", err) + } + configureFunc(ruleSetsClient.Client) + + rulesClient, err := rules.NewRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Rules client: %+v", err) + } + configureFunc(rulesClient.Client) + + secretsClient, err := secrets.NewSecretsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Secrets client: %+v", err) + } + configureFunc(secretsClient.Client) + + securityPoliciesClient, err := securitypolicies.NewSecurityPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityPolicies client: %+v", err) + } + configureFunc(securityPoliciesClient.Client) + + validateProbeClient, err := validateprobe.NewValidateProbeClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ValidateProbe client: %+v", err) + } + configureFunc(validateProbeClient.Client) + + wafLogAnalyticsClient, err := wafloganalytics.NewWafLogAnalyticsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WafLogAnalytics client: %+v", err) + } + configureFunc(wafLogAnalyticsClient.Client) + + webApplicationFirewallManagedRuleSetsClient, err := webapplicationfirewallmanagedrulesets.NewWebApplicationFirewallManagedRuleSetsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WebApplicationFirewallManagedRuleSets client: %+v", err) + } + configureFunc(webApplicationFirewallManagedRuleSetsClient.Client) + + webApplicationFirewallPoliciesClient, err := webapplicationfirewallpolicies.NewWebApplicationFirewallPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WebApplicationFirewallPolicies client: %+v", err) + } + configureFunc(webApplicationFirewallPoliciesClient.Client) + + return &Client{ + AFDCustomDomains: aFDCustomDomainsClient, + AFDEndpoints: aFDEndpointsClient, + AFDOriginGroups: aFDOriginGroupsClient, + AFDOrigins: aFDOriginsClient, + AFDProfiles: aFDProfilesClient, + CheckEndpointNameAvailability: checkEndpointNameAvailabilityClient, + CheckNameAvailability: checkNameAvailabilityClient, + CheckNameAvailabilityWithSubscription: checkNameAvailabilityWithSubscriptionClient, + CustomDomains: customDomainsClient, + Edgenodes: edgenodesClient, + Endpoints: endpointsClient, + LogAnalytics: logAnalyticsClient, + OriginGroups: originGroupsClient, + Origins: originsClient, + Profiles: profilesClient, + Routes: routesClient, + RuleSets: ruleSetsClient, + Rules: rulesClient, + Secrets: secretsClient, + SecurityPolicies: securityPoliciesClient, + ValidateProbe: validateProbeClient, + WafLogAnalytics: wafLogAnalyticsClient, + WebApplicationFirewallManagedRuleSets: webApplicationFirewallManagedRuleSetsClient, + WebApplicationFirewallPolicies: webApplicationFirewallPoliciesClient, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/README.md b/resource-manager/cdn/2024-02-01/customdomains/README.md new file mode 100644 index 00000000000..e8406094c23 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/customdomains` Documentation + +The `customdomains` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/customdomains" +``` + + +### Client Initialization + +```go +client := customdomains.NewCustomDomainsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CustomDomainsClient.Create` + +```go +ctx := context.TODO() +id := customdomains.NewEndpointCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "customDomainValue") + +payload := customdomains.CustomDomainParameters{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CustomDomainsClient.Delete` + +```go +ctx := context.TODO() +id := customdomains.NewEndpointCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "customDomainValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CustomDomainsClient.DisableCustomHTTPS` + +```go +ctx := context.TODO() +id := customdomains.NewEndpointCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "customDomainValue") + +if err := client.DisableCustomHTTPSThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CustomDomainsClient.EnableCustomHTTPS` + +```go +ctx := context.TODO() +id := customdomains.NewEndpointCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "customDomainValue") + +payload := customdomains.CustomDomainHTTPSParameters{ + // ... +} + + +if err := client.EnableCustomHTTPSThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CustomDomainsClient.Get` + +```go +ctx := context.TODO() +id := customdomains.NewEndpointCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "customDomainValue") + +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: `CustomDomainsClient.ListByEndpoint` + +```go +ctx := context.TODO() +id := customdomains.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +// alternatively `client.ListByEndpoint(ctx, id)` can be used to do batched pagination +items, err := client.ListByEndpointComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cdn/2024-02-01/customdomains/client.go b/resource-manager/cdn/2024-02-01/customdomains/client.go new file mode 100644 index 00000000000..771ff4b2d98 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/client.go @@ -0,0 +1,26 @@ +package customdomains + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainsClient struct { + Client *resourcemanager.Client +} + +func NewCustomDomainsClientWithBaseURI(sdkApi sdkEnv.Api) (*CustomDomainsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "customdomains", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CustomDomainsClient: %+v", err) + } + + return &CustomDomainsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/constants.go b/resource-manager/cdn/2024-02-01/customdomains/constants.go new file mode 100644 index 00000000000..c61f7162c73 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/constants.go @@ -0,0 +1,453 @@ +package customdomains + +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 CertificateSource string + +const ( + CertificateSourceAzureKeyVault CertificateSource = "AzureKeyVault" + CertificateSourceCdn CertificateSource = "Cdn" +) + +func PossibleValuesForCertificateSource() []string { + return []string{ + string(CertificateSourceAzureKeyVault), + string(CertificateSourceCdn), + } +} + +func (s *CertificateSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateSource(input string) (*CertificateSource, error) { + vals := map[string]CertificateSource{ + "azurekeyvault": CertificateSourceAzureKeyVault, + "cdn": CertificateSourceCdn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateSource(input) + return &out, nil +} + +type CertificateSourceParametersType string + +const ( + CertificateSourceParametersTypeCdnCertificateSourceParameters CertificateSourceParametersType = "CdnCertificateSourceParameters" + CertificateSourceParametersTypeKeyVaultCertificateSourceParameters CertificateSourceParametersType = "KeyVaultCertificateSourceParameters" +) + +func PossibleValuesForCertificateSourceParametersType() []string { + return []string{ + string(CertificateSourceParametersTypeCdnCertificateSourceParameters), + string(CertificateSourceParametersTypeKeyVaultCertificateSourceParameters), + } +} + +func (s *CertificateSourceParametersType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateSourceParametersType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateSourceParametersType(input string) (*CertificateSourceParametersType, error) { + vals := map[string]CertificateSourceParametersType{ + "cdncertificatesourceparameters": CertificateSourceParametersTypeCdnCertificateSourceParameters, + "keyvaultcertificatesourceparameters": CertificateSourceParametersTypeKeyVaultCertificateSourceParameters, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateSourceParametersType(input) + return &out, nil +} + +type CertificateType string + +const ( + CertificateTypeDedicated CertificateType = "Dedicated" + CertificateTypeShared CertificateType = "Shared" +) + +func PossibleValuesForCertificateType() []string { + return []string{ + string(CertificateTypeDedicated), + string(CertificateTypeShared), + } +} + +func (s *CertificateType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateType(input string) (*CertificateType, error) { + vals := map[string]CertificateType{ + "dedicated": CertificateTypeDedicated, + "shared": CertificateTypeShared, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateType(input) + return &out, nil +} + +type CustomDomainResourceState string + +const ( + CustomDomainResourceStateActive CustomDomainResourceState = "Active" + CustomDomainResourceStateCreating CustomDomainResourceState = "Creating" + CustomDomainResourceStateDeleting CustomDomainResourceState = "Deleting" +) + +func PossibleValuesForCustomDomainResourceState() []string { + return []string{ + string(CustomDomainResourceStateActive), + string(CustomDomainResourceStateCreating), + string(CustomDomainResourceStateDeleting), + } +} + +func (s *CustomDomainResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCustomDomainResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCustomDomainResourceState(input string) (*CustomDomainResourceState, error) { + vals := map[string]CustomDomainResourceState{ + "active": CustomDomainResourceStateActive, + "creating": CustomDomainResourceStateCreating, + "deleting": CustomDomainResourceStateDeleting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CustomDomainResourceState(input) + return &out, nil +} + +type CustomHTTPSProvisioningState string + +const ( + CustomHTTPSProvisioningStateDisabled CustomHTTPSProvisioningState = "Disabled" + CustomHTTPSProvisioningStateDisabling CustomHTTPSProvisioningState = "Disabling" + CustomHTTPSProvisioningStateEnabled CustomHTTPSProvisioningState = "Enabled" + CustomHTTPSProvisioningStateEnabling CustomHTTPSProvisioningState = "Enabling" + CustomHTTPSProvisioningStateFailed CustomHTTPSProvisioningState = "Failed" +) + +func PossibleValuesForCustomHTTPSProvisioningState() []string { + return []string{ + string(CustomHTTPSProvisioningStateDisabled), + string(CustomHTTPSProvisioningStateDisabling), + string(CustomHTTPSProvisioningStateEnabled), + string(CustomHTTPSProvisioningStateEnabling), + string(CustomHTTPSProvisioningStateFailed), + } +} + +func (s *CustomHTTPSProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCustomHTTPSProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCustomHTTPSProvisioningState(input string) (*CustomHTTPSProvisioningState, error) { + vals := map[string]CustomHTTPSProvisioningState{ + "disabled": CustomHTTPSProvisioningStateDisabled, + "disabling": CustomHTTPSProvisioningStateDisabling, + "enabled": CustomHTTPSProvisioningStateEnabled, + "enabling": CustomHTTPSProvisioningStateEnabling, + "failed": CustomHTTPSProvisioningStateFailed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CustomHTTPSProvisioningState(input) + return &out, nil +} + +type CustomHTTPSProvisioningSubstate string + +const ( + CustomHTTPSProvisioningSubstateCertificateDeleted CustomHTTPSProvisioningSubstate = "CertificateDeleted" + CustomHTTPSProvisioningSubstateCertificateDeployed CustomHTTPSProvisioningSubstate = "CertificateDeployed" + CustomHTTPSProvisioningSubstateDeletingCertificate CustomHTTPSProvisioningSubstate = "DeletingCertificate" + CustomHTTPSProvisioningSubstateDeployingCertificate CustomHTTPSProvisioningSubstate = "DeployingCertificate" + CustomHTTPSProvisioningSubstateDomainControlValidationRequestApproved CustomHTTPSProvisioningSubstate = "DomainControlValidationRequestApproved" + CustomHTTPSProvisioningSubstateDomainControlValidationRequestRejected CustomHTTPSProvisioningSubstate = "DomainControlValidationRequestRejected" + CustomHTTPSProvisioningSubstateDomainControlValidationRequestTimedOut CustomHTTPSProvisioningSubstate = "DomainControlValidationRequestTimedOut" + CustomHTTPSProvisioningSubstateIssuingCertificate CustomHTTPSProvisioningSubstate = "IssuingCertificate" + CustomHTTPSProvisioningSubstatePendingDomainControlValidationREquestApproval CustomHTTPSProvisioningSubstate = "PendingDomainControlValidationREquestApproval" + CustomHTTPSProvisioningSubstateSubmittingDomainControlValidationRequest CustomHTTPSProvisioningSubstate = "SubmittingDomainControlValidationRequest" +) + +func PossibleValuesForCustomHTTPSProvisioningSubstate() []string { + return []string{ + string(CustomHTTPSProvisioningSubstateCertificateDeleted), + string(CustomHTTPSProvisioningSubstateCertificateDeployed), + string(CustomHTTPSProvisioningSubstateDeletingCertificate), + string(CustomHTTPSProvisioningSubstateDeployingCertificate), + string(CustomHTTPSProvisioningSubstateDomainControlValidationRequestApproved), + string(CustomHTTPSProvisioningSubstateDomainControlValidationRequestRejected), + string(CustomHTTPSProvisioningSubstateDomainControlValidationRequestTimedOut), + string(CustomHTTPSProvisioningSubstateIssuingCertificate), + string(CustomHTTPSProvisioningSubstatePendingDomainControlValidationREquestApproval), + string(CustomHTTPSProvisioningSubstateSubmittingDomainControlValidationRequest), + } +} + +func (s *CustomHTTPSProvisioningSubstate) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCustomHTTPSProvisioningSubstate(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCustomHTTPSProvisioningSubstate(input string) (*CustomHTTPSProvisioningSubstate, error) { + vals := map[string]CustomHTTPSProvisioningSubstate{ + "certificatedeleted": CustomHTTPSProvisioningSubstateCertificateDeleted, + "certificatedeployed": CustomHTTPSProvisioningSubstateCertificateDeployed, + "deletingcertificate": CustomHTTPSProvisioningSubstateDeletingCertificate, + "deployingcertificate": CustomHTTPSProvisioningSubstateDeployingCertificate, + "domaincontrolvalidationrequestapproved": CustomHTTPSProvisioningSubstateDomainControlValidationRequestApproved, + "domaincontrolvalidationrequestrejected": CustomHTTPSProvisioningSubstateDomainControlValidationRequestRejected, + "domaincontrolvalidationrequesttimedout": CustomHTTPSProvisioningSubstateDomainControlValidationRequestTimedOut, + "issuingcertificate": CustomHTTPSProvisioningSubstateIssuingCertificate, + "pendingdomaincontrolvalidationrequestapproval": CustomHTTPSProvisioningSubstatePendingDomainControlValidationREquestApproval, + "submittingdomaincontrolvalidationrequest": CustomHTTPSProvisioningSubstateSubmittingDomainControlValidationRequest, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CustomHTTPSProvisioningSubstate(input) + return &out, nil +} + +type DeleteRule string + +const ( + DeleteRuleNoAction DeleteRule = "NoAction" +) + +func PossibleValuesForDeleteRule() []string { + return []string{ + string(DeleteRuleNoAction), + } +} + +func (s *DeleteRule) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeleteRule(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeleteRule(input string) (*DeleteRule, error) { + vals := map[string]DeleteRule{ + "noaction": DeleteRuleNoAction, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeleteRule(input) + return &out, nil +} + +type MinimumTlsVersion string + +const ( + MinimumTlsVersionNone MinimumTlsVersion = "None" + MinimumTlsVersionTLSOneTwo MinimumTlsVersion = "TLS12" + MinimumTlsVersionTLSOneZero MinimumTlsVersion = "TLS10" +) + +func PossibleValuesForMinimumTlsVersion() []string { + return []string{ + string(MinimumTlsVersionNone), + string(MinimumTlsVersionTLSOneTwo), + string(MinimumTlsVersionTLSOneZero), + } +} + +func (s *MinimumTlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMinimumTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMinimumTlsVersion(input string) (*MinimumTlsVersion, error) { + vals := map[string]MinimumTlsVersion{ + "none": MinimumTlsVersionNone, + "tls12": MinimumTlsVersionTLSOneTwo, + "tls10": MinimumTlsVersionTLSOneZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MinimumTlsVersion(input) + return &out, nil +} + +type ProtocolType string + +const ( + ProtocolTypeIPBased ProtocolType = "IPBased" + ProtocolTypeServerNameIndication ProtocolType = "ServerNameIndication" +) + +func PossibleValuesForProtocolType() []string { + return []string{ + string(ProtocolTypeIPBased), + string(ProtocolTypeServerNameIndication), + } +} + +func (s *ProtocolType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocolType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocolType(input string) (*ProtocolType, error) { + vals := map[string]ProtocolType{ + "ipbased": ProtocolTypeIPBased, + "servernameindication": ProtocolTypeServerNameIndication, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProtocolType(input) + return &out, nil +} + +type UpdateRule string + +const ( + UpdateRuleNoAction UpdateRule = "NoAction" +) + +func PossibleValuesForUpdateRule() []string { + return []string{ + string(UpdateRuleNoAction), + } +} + +func (s *UpdateRule) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdateRule(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUpdateRule(input string) (*UpdateRule, error) { + vals := map[string]UpdateRule{ + "noaction": UpdateRuleNoAction, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpdateRule(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/id_endpoint.go b/resource-manager/cdn/2024-02-01/customdomains/id_endpoint.go new file mode 100644 index 00000000000..7c27c90bda4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/id_endpoint.go @@ -0,0 +1,139 @@ +package customdomains + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&EndpointId{}) +} + +var _ resourceids.ResourceId = &EndpointId{} + +// EndpointId is a struct representing the Resource ID for a Endpoint +type EndpointId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + EndpointName string +} + +// NewEndpointID returns a new EndpointId struct +func NewEndpointID(subscriptionId string, resourceGroupName string, profileName string, endpointName string) EndpointId { + return EndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + EndpointName: endpointName, + } +} + +// ParseEndpointID parses 'input' into a EndpointId +func ParseEndpointID(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEndpointIDInsensitively parses 'input' case-insensitively into a EndpointId +// note: this method should only be used for API response data and not user input +func ParseEndpointIDInsensitively(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.EndpointName, ok = input.Parsed["endpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointName", input) + } + + return nil +} + +// ValidateEndpointID checks that 'input' can be parsed as a Endpoint ID +func ValidateEndpointID(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 := ParseEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Endpoint ID +func (id EndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/endpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.EndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Endpoint ID +func (id EndpointId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticEndpoints", "endpoints", "endpoints"), + resourceids.UserSpecifiedSegment("endpointName", "endpointValue"), + } +} + +// String returns a human-readable description of this Endpoint ID +func (id EndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Endpoint Name: %q", id.EndpointName), + } + return fmt.Sprintf("Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/id_endpoint_test.go b/resource-manager/cdn/2024-02-01/customdomains/id_endpoint_test.go new file mode 100644 index 00000000000..2be2085c289 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/id_endpoint_test.go @@ -0,0 +1,327 @@ +package customdomains + +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 = &EndpointId{} + +func TestNewEndpointID(t *testing.T) { + id := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.EndpointName != "endpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointName'", id.EndpointName, "endpointValue") + } +} + +func TestFormatEndpointID(t *testing.T) { + actual := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestParseEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + EndpointName: "eNdPoInTvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestSegmentsForEndpointId(t *testing.T) { + segments := EndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EndpointId 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/cdn/2024-02-01/customdomains/id_endpointcustomdomain.go b/resource-manager/cdn/2024-02-01/customdomains/id_endpointcustomdomain.go new file mode 100644 index 00000000000..3792be98f38 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/id_endpointcustomdomain.go @@ -0,0 +1,148 @@ +package customdomains + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&EndpointCustomDomainId{}) +} + +var _ resourceids.ResourceId = &EndpointCustomDomainId{} + +// EndpointCustomDomainId is a struct representing the Resource ID for a Endpoint Custom Domain +type EndpointCustomDomainId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + EndpointName string + CustomDomainName string +} + +// NewEndpointCustomDomainID returns a new EndpointCustomDomainId struct +func NewEndpointCustomDomainID(subscriptionId string, resourceGroupName string, profileName string, endpointName string, customDomainName string) EndpointCustomDomainId { + return EndpointCustomDomainId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + EndpointName: endpointName, + CustomDomainName: customDomainName, + } +} + +// ParseEndpointCustomDomainID parses 'input' into a EndpointCustomDomainId +func ParseEndpointCustomDomainID(input string) (*EndpointCustomDomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointCustomDomainId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointCustomDomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEndpointCustomDomainIDInsensitively parses 'input' case-insensitively into a EndpointCustomDomainId +// note: this method should only be used for API response data and not user input +func ParseEndpointCustomDomainIDInsensitively(input string) (*EndpointCustomDomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointCustomDomainId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointCustomDomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EndpointCustomDomainId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.EndpointName, ok = input.Parsed["endpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointName", input) + } + + if id.CustomDomainName, ok = input.Parsed["customDomainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "customDomainName", input) + } + + return nil +} + +// ValidateEndpointCustomDomainID checks that 'input' can be parsed as a Endpoint Custom Domain ID +func ValidateEndpointCustomDomainID(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 := ParseEndpointCustomDomainID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Endpoint Custom Domain ID +func (id EndpointCustomDomainId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/endpoints/%s/customDomains/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.EndpointName, id.CustomDomainName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Endpoint Custom Domain ID +func (id EndpointCustomDomainId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticEndpoints", "endpoints", "endpoints"), + resourceids.UserSpecifiedSegment("endpointName", "endpointValue"), + resourceids.StaticSegment("staticCustomDomains", "customDomains", "customDomains"), + resourceids.UserSpecifiedSegment("customDomainName", "customDomainValue"), + } +} + +// String returns a human-readable description of this Endpoint Custom Domain ID +func (id EndpointCustomDomainId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Endpoint Name: %q", id.EndpointName), + fmt.Sprintf("Custom Domain Name: %q", id.CustomDomainName), + } + return fmt.Sprintf("Endpoint Custom Domain (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/id_endpointcustomdomain_test.go b/resource-manager/cdn/2024-02-01/customdomains/id_endpointcustomdomain_test.go new file mode 100644 index 00000000000..625fe74948d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/id_endpointcustomdomain_test.go @@ -0,0 +1,372 @@ +package customdomains + +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 = &EndpointCustomDomainId{} + +func TestNewEndpointCustomDomainID(t *testing.T) { + id := NewEndpointCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.EndpointName != "endpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointName'", id.EndpointName, "endpointValue") + } + + if id.CustomDomainName != "customDomainValue" { + t.Fatalf("Expected %q but got %q for Segment 'CustomDomainName'", id.CustomDomainName, "customDomainValue") + } +} + +func TestFormatEndpointCustomDomainID(t *testing.T) { + actual := NewEndpointCustomDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "customDomainValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/customDomains/customDomainValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEndpointCustomDomainID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointCustomDomainId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/customDomains", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/customDomains/customDomainValue", + Expected: &EndpointCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/customDomains/customDomainValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointCustomDomainID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + if actual.CustomDomainName != v.Expected.CustomDomainName { + t.Fatalf("Expected %q but got %q for CustomDomainName", v.Expected.CustomDomainName, actual.CustomDomainName) + } + + } +} + +func TestParseEndpointCustomDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointCustomDomainId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/customDomains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/cUsToMdOmAiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/customDomains/customDomainValue", + Expected: &EndpointCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + CustomDomainName: "customDomainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/cUsToMdOmAiNs/cUsToMdOmAiNvAlUe", + Expected: &EndpointCustomDomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + EndpointName: "eNdPoInTvAlUe", + 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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/cUsToMdOmAiNs/cUsToMdOmAiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointCustomDomainIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + if actual.CustomDomainName != v.Expected.CustomDomainName { + t.Fatalf("Expected %q but got %q for CustomDomainName", v.Expected.CustomDomainName, actual.CustomDomainName) + } + + } +} + +func TestSegmentsForEndpointCustomDomainId(t *testing.T) { + segments := EndpointCustomDomainId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EndpointCustomDomainId 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/cdn/2024-02-01/customdomains/method_create.go b/resource-manager/cdn/2024-02-01/customdomains/method_create.go new file mode 100644 index 00000000000..a9e4d357f5d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/method_create.go @@ -0,0 +1,76 @@ +package customdomains + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CustomDomain +} + +// Create ... +func (c CustomDomainsClient) Create(ctx context.Context, id EndpointCustomDomainId, input CustomDomainParameters) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c CustomDomainsClient) CreateThenPoll(ctx context.Context, id EndpointCustomDomainId, input CustomDomainParameters) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/method_delete.go b/resource-manager/cdn/2024-02-01/customdomains/method_delete.go new file mode 100644 index 00000000000..44b72a2da70 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/method_delete.go @@ -0,0 +1,72 @@ +package customdomains + +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 + Model *CustomDomain +} + +// Delete ... +func (c CustomDomainsClient) Delete(ctx context.Context, id EndpointCustomDomainId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c CustomDomainsClient) DeleteThenPoll(ctx context.Context, id EndpointCustomDomainId) 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/cdn/2024-02-01/customdomains/method_disablecustomhttps.go b/resource-manager/cdn/2024-02-01/customdomains/method_disablecustomhttps.go new file mode 100644 index 00000000000..803bf0d371f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/method_disablecustomhttps.go @@ -0,0 +1,71 @@ +package customdomains + +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 DisableCustomHTTPSOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CustomDomain +} + +// DisableCustomHTTPS ... +func (c CustomDomainsClient) DisableCustomHTTPS(ctx context.Context, id EndpointCustomDomainId) (result DisableCustomHTTPSOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/disableCustomHttps", 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 +} + +// DisableCustomHTTPSThenPoll performs DisableCustomHTTPS then polls until it's completed +func (c CustomDomainsClient) DisableCustomHTTPSThenPoll(ctx context.Context, id EndpointCustomDomainId) error { + result, err := c.DisableCustomHTTPS(ctx, id) + if err != nil { + return fmt.Errorf("performing DisableCustomHTTPS: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DisableCustomHTTPS: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/method_enablecustomhttps.go b/resource-manager/cdn/2024-02-01/customdomains/method_enablecustomhttps.go new file mode 100644 index 00000000000..355aba6796c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/method_enablecustomhttps.go @@ -0,0 +1,75 @@ +package customdomains + +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 EnableCustomHTTPSOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CustomDomain +} + +// EnableCustomHTTPS ... +func (c CustomDomainsClient) EnableCustomHTTPS(ctx context.Context, id EndpointCustomDomainId, input CustomDomainHTTPSParameters) (result EnableCustomHTTPSOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/enableCustomHttps", 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 +} + +// EnableCustomHTTPSThenPoll performs EnableCustomHTTPS then polls until it's completed +func (c CustomDomainsClient) EnableCustomHTTPSThenPoll(ctx context.Context, id EndpointCustomDomainId, input CustomDomainHTTPSParameters) error { + result, err := c.EnableCustomHTTPS(ctx, id, input) + if err != nil { + return fmt.Errorf("performing EnableCustomHTTPS: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after EnableCustomHTTPS: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/method_get.go b/resource-manager/cdn/2024-02-01/customdomains/method_get.go new file mode 100644 index 00000000000..62d23a9836e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/method_get.go @@ -0,0 +1,54 @@ +package customdomains + +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 *CustomDomain +} + +// Get ... +func (c CustomDomainsClient) Get(ctx context.Context, id EndpointCustomDomainId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CustomDomain + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/method_listbyendpoint.go b/resource-manager/cdn/2024-02-01/customdomains/method_listbyendpoint.go new file mode 100644 index 00000000000..393f5f431c1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/method_listbyendpoint.go @@ -0,0 +1,105 @@ +package customdomains + +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 ListByEndpointOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CustomDomain +} + +type ListByEndpointCompleteResult struct { + LatestHttpResponse *http.Response + Items []CustomDomain +} + +type ListByEndpointCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByEndpointCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByEndpoint ... +func (c CustomDomainsClient) ListByEndpoint(ctx context.Context, id EndpointId) (result ListByEndpointOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByEndpointCustomPager{}, + 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:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByEndpointComplete retrieves all the results into a single object +func (c CustomDomainsClient) ListByEndpointComplete(ctx context.Context, id EndpointId) (ListByEndpointCompleteResult, error) { + return c.ListByEndpointCompleteMatchingPredicate(ctx, id, CustomDomainOperationPredicate{}) +} + +// ListByEndpointCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CustomDomainsClient) ListByEndpointCompleteMatchingPredicate(ctx context.Context, id EndpointId, predicate CustomDomainOperationPredicate) (result ListByEndpointCompleteResult, err error) { + items := make([]CustomDomain, 0) + + resp, err := c.ListByEndpoint(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByEndpointCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_cdncertificatesourceparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_cdncertificatesourceparameters.go new file mode 100644 index 00000000000..fd9eed5266e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_cdncertificatesourceparameters.go @@ -0,0 +1,41 @@ +package customdomains + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CertificateSourceParameters = CdnCertificateSourceParameters{} + +type CdnCertificateSourceParameters struct { + CertificateType CertificateType `json:"certificateType"` + + // Fields inherited from CertificateSourceParameters +} + +var _ json.Marshaler = CdnCertificateSourceParameters{} + +func (s CdnCertificateSourceParameters) MarshalJSON() ([]byte, error) { + type wrapper CdnCertificateSourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CdnCertificateSourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CdnCertificateSourceParameters: %+v", err) + } + decoded["typeName"] = "CdnCertificateSourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CdnCertificateSourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_cdnmanagedhttpsparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_cdnmanagedhttpsparameters.go new file mode 100644 index 00000000000..2da1b77880c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_cdnmanagedhttpsparameters.go @@ -0,0 +1,43 @@ +package customdomains + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CustomDomainHTTPSParameters = CdnManagedHTTPSParameters{} + +type CdnManagedHTTPSParameters struct { + CertificateSourceParameters CdnCertificateSourceParameters `json:"certificateSourceParameters"` + + // Fields inherited from CustomDomainHTTPSParameters + MinimumTlsVersion *MinimumTlsVersion `json:"minimumTlsVersion,omitempty"` + ProtocolType ProtocolType `json:"protocolType"` +} + +var _ json.Marshaler = CdnManagedHTTPSParameters{} + +func (s CdnManagedHTTPSParameters) MarshalJSON() ([]byte, error) { + type wrapper CdnManagedHTTPSParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CdnManagedHTTPSParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CdnManagedHTTPSParameters: %+v", err) + } + decoded["certificateSource"] = "Cdn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CdnManagedHTTPSParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_certificatesourceparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_certificatesourceparameters.go new file mode 100644 index 00000000000..a255636f0be --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_certificatesourceparameters.go @@ -0,0 +1,61 @@ +package customdomains + +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 CertificateSourceParameters interface { +} + +// RawCertificateSourceParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawCertificateSourceParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalCertificateSourceParametersImplementation(input []byte) (CertificateSourceParameters, 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 CertificateSourceParameters into map[string]interface: %+v", err) + } + + value, ok := temp["typeName"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "CdnCertificateSourceParameters") { + var out CdnCertificateSourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CdnCertificateSourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KeyVaultCertificateSourceParameters") { + var out KeyVaultCertificateSourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KeyVaultCertificateSourceParameters: %+v", err) + } + return out, nil + } + + out := RawCertificateSourceParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_customdomain.go b/resource-manager/cdn/2024-02-01/customdomains/model_customdomain.go new file mode 100644 index 00000000000..540ed3151a2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_customdomain.go @@ -0,0 +1,16 @@ +package customdomains + +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,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_customdomainhttpsparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainhttpsparameters.go new file mode 100644 index 00000000000..de2993085e8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainhttpsparameters.go @@ -0,0 +1,61 @@ +package customdomains + +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 CustomDomainHTTPSParameters interface { +} + +// RawCustomDomainHTTPSParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawCustomDomainHTTPSParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalCustomDomainHTTPSParametersImplementation(input []byte) (CustomDomainHTTPSParameters, 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 CustomDomainHTTPSParameters into map[string]interface: %+v", err) + } + + value, ok := temp["certificateSource"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Cdn") { + var out CdnManagedHTTPSParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CdnManagedHTTPSParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureKeyVault") { + var out UserManagedHTTPSParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UserManagedHTTPSParameters: %+v", err) + } + return out, nil + } + + out := RawCustomDomainHTTPSParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_customdomainparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainparameters.go new file mode 100644 index 00000000000..a7dd7e903c9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainparameters.go @@ -0,0 +1,8 @@ +package customdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainParameters struct { + Properties *CustomDomainPropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_customdomainproperties.go b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainproperties.go new file mode 100644 index 00000000000..14e3cc0f4aa --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainproperties.go @@ -0,0 +1,50 @@ +package customdomains + +import ( + "encoding/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 CustomDomainProperties struct { + CustomHTTPSParameters CustomDomainHTTPSParameters `json:"customHttpsParameters"` + CustomHTTPSProvisioningState *CustomHTTPSProvisioningState `json:"customHttpsProvisioningState,omitempty"` + CustomHTTPSProvisioningSubstate *CustomHTTPSProvisioningSubstate `json:"customHttpsProvisioningSubstate,omitempty"` + HostName string `json:"hostName"` + ProvisioningState *CustomHTTPSProvisioningState `json:"provisioningState,omitempty"` + ResourceState *CustomDomainResourceState `json:"resourceState,omitempty"` + ValidationData *string `json:"validationData,omitempty"` +} + +var _ json.Unmarshaler = &CustomDomainProperties{} + +func (s *CustomDomainProperties) UnmarshalJSON(bytes []byte) error { + type alias CustomDomainProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into CustomDomainProperties: %+v", err) + } + + s.CustomHTTPSProvisioningState = decoded.CustomHTTPSProvisioningState + s.CustomHTTPSProvisioningSubstate = decoded.CustomHTTPSProvisioningSubstate + s.HostName = decoded.HostName + s.ProvisioningState = decoded.ProvisioningState + s.ResourceState = decoded.ResourceState + s.ValidationData = decoded.ValidationData + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CustomDomainProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["customHttpsParameters"]; ok { + impl, err := unmarshalCustomDomainHTTPSParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CustomHTTPSParameters' for 'CustomDomainProperties': %+v", err) + } + s.CustomHTTPSParameters = impl + } + return nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_customdomainpropertiesparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainpropertiesparameters.go new file mode 100644 index 00000000000..07f04d94e8d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_customdomainpropertiesparameters.go @@ -0,0 +1,8 @@ +package customdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomainPropertiesParameters struct { + HostName string `json:"hostName"` +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_keyvaultcertificatesourceparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_keyvaultcertificatesourceparameters.go new file mode 100644 index 00000000000..a8b3dbe158f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_keyvaultcertificatesourceparameters.go @@ -0,0 +1,47 @@ +package customdomains + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CertificateSourceParameters = KeyVaultCertificateSourceParameters{} + +type KeyVaultCertificateSourceParameters struct { + DeleteRule DeleteRule `json:"deleteRule"` + ResourceGroupName string `json:"resourceGroupName"` + SecretName string `json:"secretName"` + SecretVersion *string `json:"secretVersion,omitempty"` + SubscriptionId string `json:"subscriptionId"` + UpdateRule UpdateRule `json:"updateRule"` + VaultName string `json:"vaultName"` + + // Fields inherited from CertificateSourceParameters +} + +var _ json.Marshaler = KeyVaultCertificateSourceParameters{} + +func (s KeyVaultCertificateSourceParameters) MarshalJSON() ([]byte, error) { + type wrapper KeyVaultCertificateSourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KeyVaultCertificateSourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KeyVaultCertificateSourceParameters: %+v", err) + } + decoded["typeName"] = "KeyVaultCertificateSourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KeyVaultCertificateSourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/model_usermanagedhttpsparameters.go b/resource-manager/cdn/2024-02-01/customdomains/model_usermanagedhttpsparameters.go new file mode 100644 index 00000000000..03e6e54faef --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/model_usermanagedhttpsparameters.go @@ -0,0 +1,43 @@ +package customdomains + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CustomDomainHTTPSParameters = UserManagedHTTPSParameters{} + +type UserManagedHTTPSParameters struct { + CertificateSourceParameters KeyVaultCertificateSourceParameters `json:"certificateSourceParameters"` + + // Fields inherited from CustomDomainHTTPSParameters + MinimumTlsVersion *MinimumTlsVersion `json:"minimumTlsVersion,omitempty"` + ProtocolType ProtocolType `json:"protocolType"` +} + +var _ json.Marshaler = UserManagedHTTPSParameters{} + +func (s UserManagedHTTPSParameters) MarshalJSON() ([]byte, error) { + type wrapper UserManagedHTTPSParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UserManagedHTTPSParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UserManagedHTTPSParameters: %+v", err) + } + decoded["certificateSource"] = "AzureKeyVault" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UserManagedHTTPSParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/predicates.go b/resource-manager/cdn/2024-02-01/customdomains/predicates.go new file mode 100644 index 00000000000..1baf6f506dd --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/predicates.go @@ -0,0 +1,27 @@ +package customdomains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +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 +} diff --git a/resource-manager/cdn/2024-02-01/customdomains/version.go b/resource-manager/cdn/2024-02-01/customdomains/version.go new file mode 100644 index 00000000000..c78fd083472 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/customdomains/version.go @@ -0,0 +1,12 @@ +package customdomains + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/customdomains/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/edgenodes/README.md b/resource-manager/cdn/2024-02-01/edgenodes/README.md new file mode 100644 index 00000000000..4351cde776a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/edgenodes` Documentation + +The `edgenodes` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/edgenodes" +``` + + +### Client Initialization + +```go +client := edgenodes.NewEdgenodesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EdgenodesClient.List` + +```go +ctx := context.TODO() + + +// alternatively `client.List(ctx)` can be used to do batched pagination +items, err := client.ListComplete(ctx) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cdn/2024-02-01/edgenodes/client.go b/resource-manager/cdn/2024-02-01/edgenodes/client.go new file mode 100644 index 00000000000..eb808ef096d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/client.go @@ -0,0 +1,26 @@ +package edgenodes + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EdgenodesClient struct { + Client *resourcemanager.Client +} + +func NewEdgenodesClientWithBaseURI(sdkApi sdkEnv.Api) (*EdgenodesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "edgenodes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EdgenodesClient: %+v", err) + } + + return &EdgenodesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/edgenodes/method_list.go b/resource-manager/cdn/2024-02-01/edgenodes/method_list.go new file mode 100644 index 00000000000..fd492ed7009 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/method_list.go @@ -0,0 +1,105 @@ +package edgenodes + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EdgeNode +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EdgeNode +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c EdgenodesClient) List(ctx context.Context) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: "/providers/Microsoft.CDN/edgenodes", + } + + 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 *[]EdgeNode `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c EdgenodesClient) ListComplete(ctx context.Context) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, EdgeNodeOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EdgenodesClient) ListCompleteMatchingPredicate(ctx context.Context, predicate EdgeNodeOperationPredicate) (result ListCompleteResult, err error) { + items := make([]EdgeNode, 0) + + resp, err := c.List(ctx) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/edgenodes/model_cidripaddress.go b/resource-manager/cdn/2024-02-01/edgenodes/model_cidripaddress.go new file mode 100644 index 00000000000..abac7b4c8ec --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/model_cidripaddress.go @@ -0,0 +1,9 @@ +package edgenodes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CidrIPAddress struct { + BaseIPAddress *string `json:"baseIpAddress,omitempty"` + PrefixLength *int64 `json:"prefixLength,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/edgenodes/model_edgenode.go b/resource-manager/cdn/2024-02-01/edgenodes/model_edgenode.go new file mode 100644 index 00000000000..8024e313b47 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/model_edgenode.go @@ -0,0 +1,16 @@ +package edgenodes + +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 EdgeNode struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EdgeNodeProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/edgenodes/model_edgenodeproperties.go b/resource-manager/cdn/2024-02-01/edgenodes/model_edgenodeproperties.go new file mode 100644 index 00000000000..e5374afca1b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/model_edgenodeproperties.go @@ -0,0 +1,8 @@ +package edgenodes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EdgeNodeProperties struct { + IPAddressGroups []IPAddressGroup `json:"ipAddressGroups"` +} diff --git a/resource-manager/cdn/2024-02-01/edgenodes/model_ipaddressgroup.go b/resource-manager/cdn/2024-02-01/edgenodes/model_ipaddressgroup.go new file mode 100644 index 00000000000..0736eeabf64 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/model_ipaddressgroup.go @@ -0,0 +1,10 @@ +package edgenodes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPAddressGroup struct { + DeliveryRegion *string `json:"deliveryRegion,omitempty"` + IPv4Addresses *[]CidrIPAddress `json:"ipv4Addresses,omitempty"` + IPv6Addresses *[]CidrIPAddress `json:"ipv6Addresses,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/edgenodes/predicates.go b/resource-manager/cdn/2024-02-01/edgenodes/predicates.go new file mode 100644 index 00000000000..db221c0d1b6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/predicates.go @@ -0,0 +1,27 @@ +package edgenodes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EdgeNodeOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p EdgeNodeOperationPredicate) Matches(input EdgeNode) 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/cdn/2024-02-01/edgenodes/version.go b/resource-manager/cdn/2024-02-01/edgenodes/version.go new file mode 100644 index 00000000000..0739bbe351c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/edgenodes/version.go @@ -0,0 +1,12 @@ +package edgenodes + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/edgenodes/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/README.md b/resource-manager/cdn/2024-02-01/endpoints/README.md new file mode 100644 index 00000000000..bb63973257d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/README.md @@ -0,0 +1,195 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/endpoints` Documentation + +The `endpoints` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/endpoints" +``` + + +### Client Initialization + +```go +client := endpoints.NewEndpointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EndpointsClient.Create` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +payload := endpoints.Endpoint{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EndpointsClient.Delete` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EndpointsClient.Get` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +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: `EndpointsClient.ListByProfile` + +```go +ctx := context.TODO() +id := endpoints.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EndpointsClient.ListResourceUsage` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +// alternatively `client.ListResourceUsage(ctx, id)` can be used to do batched pagination +items, err := client.ListResourceUsageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EndpointsClient.LoadContent` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +payload := endpoints.LoadParameters{ + // ... +} + + +if err := client.LoadContentThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EndpointsClient.PurgeContent` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +payload := endpoints.PurgeParameters{ + // ... +} + + +if err := client.PurgeContentThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EndpointsClient.Start` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +if err := client.StartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EndpointsClient.Stop` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +if err := client.StopThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EndpointsClient.Update` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +payload := endpoints.EndpointUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EndpointsClient.ValidateCustomDomain` + +```go +ctx := context.TODO() +id := endpoints.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +payload := endpoints.ValidateCustomDomainInput{ + // ... +} + + +read, err := client.ValidateCustomDomain(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/cdn/2024-02-01/endpoints/client.go b/resource-manager/cdn/2024-02-01/endpoints/client.go new file mode 100644 index 00000000000..5f6c4ea9ece --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/client.go @@ -0,0 +1,26 @@ +package endpoints + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointsClient struct { + Client *resourcemanager.Client +} + +func NewEndpointsClientWithBaseURI(sdkApi sdkEnv.Api) (*EndpointsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "endpoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EndpointsClient: %+v", err) + } + + return &EndpointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/constants.go b/resource-manager/cdn/2024-02-01/endpoints/constants.go new file mode 100644 index 00000000000..fec07d91d23 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/constants.go @@ -0,0 +1,2629 @@ +package endpoints + +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 Algorithm string + +const ( + AlgorithmSHATwoFiveSix Algorithm = "SHA256" +) + +func PossibleValuesForAlgorithm() []string { + return []string{ + string(AlgorithmSHATwoFiveSix), + } +} + +func (s *Algorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlgorithm(input string) (*Algorithm, error) { + vals := map[string]Algorithm{ + "sha256": AlgorithmSHATwoFiveSix, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Algorithm(input) + return &out, nil +} + +type CacheBehavior string + +const ( + CacheBehaviorBypassCache CacheBehavior = "BypassCache" + CacheBehaviorOverride CacheBehavior = "Override" + CacheBehaviorSetIfMissing CacheBehavior = "SetIfMissing" +) + +func PossibleValuesForCacheBehavior() []string { + return []string{ + string(CacheBehaviorBypassCache), + string(CacheBehaviorOverride), + string(CacheBehaviorSetIfMissing), + } +} + +func (s *CacheBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCacheBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCacheBehavior(input string) (*CacheBehavior, error) { + vals := map[string]CacheBehavior{ + "bypasscache": CacheBehaviorBypassCache, + "override": CacheBehaviorOverride, + "setifmissing": CacheBehaviorSetIfMissing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CacheBehavior(input) + return &out, nil +} + +type CacheType string + +const ( + CacheTypeAll CacheType = "All" +) + +func PossibleValuesForCacheType() []string { + return []string{ + string(CacheTypeAll), + } +} + +func (s *CacheType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCacheType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCacheType(input string) (*CacheType, error) { + vals := map[string]CacheType{ + "all": CacheTypeAll, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CacheType(input) + return &out, nil +} + +type ClientPortOperator string + +const ( + ClientPortOperatorAny ClientPortOperator = "Any" + ClientPortOperatorBeginsWith ClientPortOperator = "BeginsWith" + ClientPortOperatorContains ClientPortOperator = "Contains" + ClientPortOperatorEndsWith ClientPortOperator = "EndsWith" + ClientPortOperatorEqual ClientPortOperator = "Equal" + ClientPortOperatorGreaterThan ClientPortOperator = "GreaterThan" + ClientPortOperatorGreaterThanOrEqual ClientPortOperator = "GreaterThanOrEqual" + ClientPortOperatorLessThan ClientPortOperator = "LessThan" + ClientPortOperatorLessThanOrEqual ClientPortOperator = "LessThanOrEqual" + ClientPortOperatorRegEx ClientPortOperator = "RegEx" +) + +func PossibleValuesForClientPortOperator() []string { + return []string{ + string(ClientPortOperatorAny), + string(ClientPortOperatorBeginsWith), + string(ClientPortOperatorContains), + string(ClientPortOperatorEndsWith), + string(ClientPortOperatorEqual), + string(ClientPortOperatorGreaterThan), + string(ClientPortOperatorGreaterThanOrEqual), + string(ClientPortOperatorLessThan), + string(ClientPortOperatorLessThanOrEqual), + string(ClientPortOperatorRegEx), + } +} + +func (s *ClientPortOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientPortOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientPortOperator(input string) (*ClientPortOperator, error) { + vals := map[string]ClientPortOperator{ + "any": ClientPortOperatorAny, + "beginswith": ClientPortOperatorBeginsWith, + "contains": ClientPortOperatorContains, + "endswith": ClientPortOperatorEndsWith, + "equal": ClientPortOperatorEqual, + "greaterthan": ClientPortOperatorGreaterThan, + "greaterthanorequal": ClientPortOperatorGreaterThanOrEqual, + "lessthan": ClientPortOperatorLessThan, + "lessthanorequal": ClientPortOperatorLessThanOrEqual, + "regex": ClientPortOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientPortOperator(input) + return &out, nil +} + +type CookiesOperator string + +const ( + CookiesOperatorAny CookiesOperator = "Any" + CookiesOperatorBeginsWith CookiesOperator = "BeginsWith" + CookiesOperatorContains CookiesOperator = "Contains" + CookiesOperatorEndsWith CookiesOperator = "EndsWith" + CookiesOperatorEqual CookiesOperator = "Equal" + CookiesOperatorGreaterThan CookiesOperator = "GreaterThan" + CookiesOperatorGreaterThanOrEqual CookiesOperator = "GreaterThanOrEqual" + CookiesOperatorLessThan CookiesOperator = "LessThan" + CookiesOperatorLessThanOrEqual CookiesOperator = "LessThanOrEqual" + CookiesOperatorRegEx CookiesOperator = "RegEx" +) + +func PossibleValuesForCookiesOperator() []string { + return []string{ + string(CookiesOperatorAny), + string(CookiesOperatorBeginsWith), + string(CookiesOperatorContains), + string(CookiesOperatorEndsWith), + string(CookiesOperatorEqual), + string(CookiesOperatorGreaterThan), + string(CookiesOperatorGreaterThanOrEqual), + string(CookiesOperatorLessThan), + string(CookiesOperatorLessThanOrEqual), + string(CookiesOperatorRegEx), + } +} + +func (s *CookiesOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCookiesOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCookiesOperator(input string) (*CookiesOperator, error) { + vals := map[string]CookiesOperator{ + "any": CookiesOperatorAny, + "beginswith": CookiesOperatorBeginsWith, + "contains": CookiesOperatorContains, + "endswith": CookiesOperatorEndsWith, + "equal": CookiesOperatorEqual, + "greaterthan": CookiesOperatorGreaterThan, + "greaterthanorequal": CookiesOperatorGreaterThanOrEqual, + "lessthan": CookiesOperatorLessThan, + "lessthanorequal": CookiesOperatorLessThanOrEqual, + "regex": CookiesOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CookiesOperator(input) + return &out, nil +} + +type DeliveryRuleActionName string + +const ( + DeliveryRuleActionNameCacheExpiration DeliveryRuleActionName = "CacheExpiration" + DeliveryRuleActionNameCacheKeyQueryString DeliveryRuleActionName = "CacheKeyQueryString" + DeliveryRuleActionNameModifyRequestHeader DeliveryRuleActionName = "ModifyRequestHeader" + DeliveryRuleActionNameModifyResponseHeader DeliveryRuleActionName = "ModifyResponseHeader" + DeliveryRuleActionNameOriginGroupOverride DeliveryRuleActionName = "OriginGroupOverride" + DeliveryRuleActionNameRouteConfigurationOverride DeliveryRuleActionName = "RouteConfigurationOverride" + DeliveryRuleActionNameUrlRedirect DeliveryRuleActionName = "UrlRedirect" + DeliveryRuleActionNameUrlRewrite DeliveryRuleActionName = "UrlRewrite" + DeliveryRuleActionNameUrlSigning DeliveryRuleActionName = "UrlSigning" +) + +func PossibleValuesForDeliveryRuleActionName() []string { + return []string{ + string(DeliveryRuleActionNameCacheExpiration), + string(DeliveryRuleActionNameCacheKeyQueryString), + string(DeliveryRuleActionNameModifyRequestHeader), + string(DeliveryRuleActionNameModifyResponseHeader), + string(DeliveryRuleActionNameOriginGroupOverride), + string(DeliveryRuleActionNameRouteConfigurationOverride), + string(DeliveryRuleActionNameUrlRedirect), + string(DeliveryRuleActionNameUrlRewrite), + string(DeliveryRuleActionNameUrlSigning), + } +} + +func (s *DeliveryRuleActionName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryRuleActionName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryRuleActionName(input string) (*DeliveryRuleActionName, error) { + vals := map[string]DeliveryRuleActionName{ + "cacheexpiration": DeliveryRuleActionNameCacheExpiration, + "cachekeyquerystring": DeliveryRuleActionNameCacheKeyQueryString, + "modifyrequestheader": DeliveryRuleActionNameModifyRequestHeader, + "modifyresponseheader": DeliveryRuleActionNameModifyResponseHeader, + "origingroupoverride": DeliveryRuleActionNameOriginGroupOverride, + "routeconfigurationoverride": DeliveryRuleActionNameRouteConfigurationOverride, + "urlredirect": DeliveryRuleActionNameUrlRedirect, + "urlrewrite": DeliveryRuleActionNameUrlRewrite, + "urlsigning": DeliveryRuleActionNameUrlSigning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryRuleActionName(input) + return &out, nil +} + +type DeliveryRuleActionParametersType string + +const ( + DeliveryRuleActionParametersTypeDeliveryRuleCacheExpirationActionParameters DeliveryRuleActionParametersType = "DeliveryRuleCacheExpirationActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleCacheKeyQueryStringBehaviorActionParameters DeliveryRuleActionParametersType = "DeliveryRuleCacheKeyQueryStringBehaviorActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleHeaderActionParameters DeliveryRuleActionParametersType = "DeliveryRuleHeaderActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleOriginGroupOverrideActionParameters DeliveryRuleActionParametersType = "DeliveryRuleOriginGroupOverrideActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleRouteConfigurationOverrideActionParameters DeliveryRuleActionParametersType = "DeliveryRuleRouteConfigurationOverrideActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleUrlRedirectActionParameters DeliveryRuleActionParametersType = "DeliveryRuleUrlRedirectActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleUrlRewriteActionParameters DeliveryRuleActionParametersType = "DeliveryRuleUrlRewriteActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleUrlSigningActionParameters DeliveryRuleActionParametersType = "DeliveryRuleUrlSigningActionParameters" +) + +func PossibleValuesForDeliveryRuleActionParametersType() []string { + return []string{ + string(DeliveryRuleActionParametersTypeDeliveryRuleCacheExpirationActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleCacheKeyQueryStringBehaviorActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleHeaderActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleOriginGroupOverrideActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleRouteConfigurationOverrideActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleUrlRedirectActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleUrlRewriteActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleUrlSigningActionParameters), + } +} + +func (s *DeliveryRuleActionParametersType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryRuleActionParametersType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryRuleActionParametersType(input string) (*DeliveryRuleActionParametersType, error) { + vals := map[string]DeliveryRuleActionParametersType{ + "deliveryrulecacheexpirationactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleCacheExpirationActionParameters, + "deliveryrulecachekeyquerystringbehavioractionparameters": DeliveryRuleActionParametersTypeDeliveryRuleCacheKeyQueryStringBehaviorActionParameters, + "deliveryruleheaderactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleHeaderActionParameters, + "deliveryruleorigingroupoverrideactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleOriginGroupOverrideActionParameters, + "deliveryrulerouteconfigurationoverrideactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleRouteConfigurationOverrideActionParameters, + "deliveryruleurlredirectactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleUrlRedirectActionParameters, + "deliveryruleurlrewriteactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleUrlRewriteActionParameters, + "deliveryruleurlsigningactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleUrlSigningActionParameters, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryRuleActionParametersType(input) + return &out, nil +} + +type DeliveryRuleConditionParametersType string + +const ( + DeliveryRuleConditionParametersTypeDeliveryRuleClientPortConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleClientPortConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleCookiesConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleCookiesConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleHTTPVersionConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleHttpVersionConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleHostNameConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleHostNameConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleIsDeviceConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleIsDeviceConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRulePostArgsConditionParameters DeliveryRuleConditionParametersType = "DeliveryRulePostArgsConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleQueryStringConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleQueryStringConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRemoteAddressConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRemoteAddressConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestBodyConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestBodyConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestHeaderConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestHeaderConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestMethodConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestMethodConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestSchemeConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestSchemeConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestUriConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestUriConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleServerPortConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleServerPortConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleSocketAddrConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleSocketAddrConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleSslProtocolConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleSslProtocolConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleUrlFileExtensionMatchConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleUrlFileExtensionMatchConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleUrlFilenameConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleUrlFilenameConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleUrlPathMatchConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleUrlPathMatchConditionParameters" +) + +func PossibleValuesForDeliveryRuleConditionParametersType() []string { + return []string{ + string(DeliveryRuleConditionParametersTypeDeliveryRuleClientPortConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleCookiesConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleHTTPVersionConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleHostNameConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleIsDeviceConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRulePostArgsConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleQueryStringConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRemoteAddressConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestBodyConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestHeaderConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestMethodConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestSchemeConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestUriConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleServerPortConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleSocketAddrConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleSslProtocolConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleUrlFileExtensionMatchConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleUrlFilenameConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleUrlPathMatchConditionParameters), + } +} + +func (s *DeliveryRuleConditionParametersType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryRuleConditionParametersType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryRuleConditionParametersType(input string) (*DeliveryRuleConditionParametersType, error) { + vals := map[string]DeliveryRuleConditionParametersType{ + "deliveryruleclientportconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleClientPortConditionParameters, + "deliveryrulecookiesconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleCookiesConditionParameters, + "deliveryrulehttpversionconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleHTTPVersionConditionParameters, + "deliveryrulehostnameconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleHostNameConditionParameters, + "deliveryruleisdeviceconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleIsDeviceConditionParameters, + "deliveryrulepostargsconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRulePostArgsConditionParameters, + "deliveryrulequerystringconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleQueryStringConditionParameters, + "deliveryruleremoteaddressconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRemoteAddressConditionParameters, + "deliveryrulerequestbodyconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestBodyConditionParameters, + "deliveryrulerequestheaderconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestHeaderConditionParameters, + "deliveryrulerequestmethodconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestMethodConditionParameters, + "deliveryrulerequestschemeconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestSchemeConditionParameters, + "deliveryrulerequesturiconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestUriConditionParameters, + "deliveryruleserverportconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleServerPortConditionParameters, + "deliveryrulesocketaddrconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleSocketAddrConditionParameters, + "deliveryrulesslprotocolconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleSslProtocolConditionParameters, + "deliveryruleurlfileextensionmatchconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleUrlFileExtensionMatchConditionParameters, + "deliveryruleurlfilenameconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleUrlFilenameConditionParameters, + "deliveryruleurlpathmatchconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleUrlPathMatchConditionParameters, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryRuleConditionParametersType(input) + return &out, nil +} + +type DestinationProtocol string + +const ( + DestinationProtocolHTTP DestinationProtocol = "Http" + DestinationProtocolHTTPS DestinationProtocol = "Https" + DestinationProtocolMatchRequest DestinationProtocol = "MatchRequest" +) + +func PossibleValuesForDestinationProtocol() []string { + return []string{ + string(DestinationProtocolHTTP), + string(DestinationProtocolHTTPS), + string(DestinationProtocolMatchRequest), + } +} + +func (s *DestinationProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDestinationProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDestinationProtocol(input string) (*DestinationProtocol, error) { + vals := map[string]DestinationProtocol{ + "http": DestinationProtocolHTTP, + "https": DestinationProtocolHTTPS, + "matchrequest": DestinationProtocolMatchRequest, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DestinationProtocol(input) + return &out, nil +} + +type EndpointProvisioningState string + +const ( + EndpointProvisioningStateCreating EndpointProvisioningState = "Creating" + EndpointProvisioningStateDeleting EndpointProvisioningState = "Deleting" + EndpointProvisioningStateFailed EndpointProvisioningState = "Failed" + EndpointProvisioningStateSucceeded EndpointProvisioningState = "Succeeded" + EndpointProvisioningStateUpdating EndpointProvisioningState = "Updating" +) + +func PossibleValuesForEndpointProvisioningState() []string { + return []string{ + string(EndpointProvisioningStateCreating), + string(EndpointProvisioningStateDeleting), + string(EndpointProvisioningStateFailed), + string(EndpointProvisioningStateSucceeded), + string(EndpointProvisioningStateUpdating), + } +} + +func (s *EndpointProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEndpointProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEndpointProvisioningState(input string) (*EndpointProvisioningState, error) { + vals := map[string]EndpointProvisioningState{ + "creating": EndpointProvisioningStateCreating, + "deleting": EndpointProvisioningStateDeleting, + "failed": EndpointProvisioningStateFailed, + "succeeded": EndpointProvisioningStateSucceeded, + "updating": EndpointProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EndpointProvisioningState(input) + return &out, nil +} + +type EndpointResourceState string + +const ( + EndpointResourceStateCreating EndpointResourceState = "Creating" + EndpointResourceStateDeleting EndpointResourceState = "Deleting" + EndpointResourceStateRunning EndpointResourceState = "Running" + EndpointResourceStateStarting EndpointResourceState = "Starting" + EndpointResourceStateStopped EndpointResourceState = "Stopped" + EndpointResourceStateStopping EndpointResourceState = "Stopping" +) + +func PossibleValuesForEndpointResourceState() []string { + return []string{ + string(EndpointResourceStateCreating), + string(EndpointResourceStateDeleting), + string(EndpointResourceStateRunning), + string(EndpointResourceStateStarting), + string(EndpointResourceStateStopped), + string(EndpointResourceStateStopping), + } +} + +func (s *EndpointResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEndpointResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEndpointResourceState(input string) (*EndpointResourceState, error) { + vals := map[string]EndpointResourceState{ + "creating": EndpointResourceStateCreating, + "deleting": EndpointResourceStateDeleting, + "running": EndpointResourceStateRunning, + "starting": EndpointResourceStateStarting, + "stopped": EndpointResourceStateStopped, + "stopping": EndpointResourceStateStopping, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EndpointResourceState(input) + return &out, nil +} + +type ForwardingProtocol string + +const ( + ForwardingProtocolHTTPOnly ForwardingProtocol = "HttpOnly" + ForwardingProtocolHTTPSOnly ForwardingProtocol = "HttpsOnly" + ForwardingProtocolMatchRequest ForwardingProtocol = "MatchRequest" +) + +func PossibleValuesForForwardingProtocol() []string { + return []string{ + string(ForwardingProtocolHTTPOnly), + string(ForwardingProtocolHTTPSOnly), + string(ForwardingProtocolMatchRequest), + } +} + +func (s *ForwardingProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseForwardingProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseForwardingProtocol(input string) (*ForwardingProtocol, error) { + vals := map[string]ForwardingProtocol{ + "httponly": ForwardingProtocolHTTPOnly, + "httpsonly": ForwardingProtocolHTTPSOnly, + "matchrequest": ForwardingProtocolMatchRequest, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ForwardingProtocol(input) + return &out, nil +} + +type GeoFilterActions string + +const ( + GeoFilterActionsAllow GeoFilterActions = "Allow" + GeoFilterActionsBlock GeoFilterActions = "Block" +) + +func PossibleValuesForGeoFilterActions() []string { + return []string{ + string(GeoFilterActionsAllow), + string(GeoFilterActionsBlock), + } +} + +func (s *GeoFilterActions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGeoFilterActions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGeoFilterActions(input string) (*GeoFilterActions, error) { + vals := map[string]GeoFilterActions{ + "allow": GeoFilterActionsAllow, + "block": GeoFilterActionsBlock, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GeoFilterActions(input) + return &out, nil +} + +type HTTPVersionOperator string + +const ( + HTTPVersionOperatorEqual HTTPVersionOperator = "Equal" +) + +func PossibleValuesForHTTPVersionOperator() []string { + return []string{ + string(HTTPVersionOperatorEqual), + } +} + +func (s *HTTPVersionOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHTTPVersionOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHTTPVersionOperator(input string) (*HTTPVersionOperator, error) { + vals := map[string]HTTPVersionOperator{ + "equal": HTTPVersionOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HTTPVersionOperator(input) + return &out, nil +} + +type HeaderAction string + +const ( + HeaderActionAppend HeaderAction = "Append" + HeaderActionDelete HeaderAction = "Delete" + HeaderActionOverwrite HeaderAction = "Overwrite" +) + +func PossibleValuesForHeaderAction() []string { + return []string{ + string(HeaderActionAppend), + string(HeaderActionDelete), + string(HeaderActionOverwrite), + } +} + +func (s *HeaderAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHeaderAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHeaderAction(input string) (*HeaderAction, error) { + vals := map[string]HeaderAction{ + "append": HeaderActionAppend, + "delete": HeaderActionDelete, + "overwrite": HeaderActionOverwrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HeaderAction(input) + return &out, nil +} + +type HealthProbeRequestType string + +const ( + HealthProbeRequestTypeGET HealthProbeRequestType = "GET" + HealthProbeRequestTypeHEAD HealthProbeRequestType = "HEAD" + HealthProbeRequestTypeNotSet HealthProbeRequestType = "NotSet" +) + +func PossibleValuesForHealthProbeRequestType() []string { + return []string{ + string(HealthProbeRequestTypeGET), + string(HealthProbeRequestTypeHEAD), + string(HealthProbeRequestTypeNotSet), + } +} + +func (s *HealthProbeRequestType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthProbeRequestType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthProbeRequestType(input string) (*HealthProbeRequestType, error) { + vals := map[string]HealthProbeRequestType{ + "get": HealthProbeRequestTypeGET, + "head": HealthProbeRequestTypeHEAD, + "notset": HealthProbeRequestTypeNotSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthProbeRequestType(input) + return &out, nil +} + +type HostNameOperator string + +const ( + HostNameOperatorAny HostNameOperator = "Any" + HostNameOperatorBeginsWith HostNameOperator = "BeginsWith" + HostNameOperatorContains HostNameOperator = "Contains" + HostNameOperatorEndsWith HostNameOperator = "EndsWith" + HostNameOperatorEqual HostNameOperator = "Equal" + HostNameOperatorGreaterThan HostNameOperator = "GreaterThan" + HostNameOperatorGreaterThanOrEqual HostNameOperator = "GreaterThanOrEqual" + HostNameOperatorLessThan HostNameOperator = "LessThan" + HostNameOperatorLessThanOrEqual HostNameOperator = "LessThanOrEqual" + HostNameOperatorRegEx HostNameOperator = "RegEx" +) + +func PossibleValuesForHostNameOperator() []string { + return []string{ + string(HostNameOperatorAny), + string(HostNameOperatorBeginsWith), + string(HostNameOperatorContains), + string(HostNameOperatorEndsWith), + string(HostNameOperatorEqual), + string(HostNameOperatorGreaterThan), + string(HostNameOperatorGreaterThanOrEqual), + string(HostNameOperatorLessThan), + string(HostNameOperatorLessThanOrEqual), + string(HostNameOperatorRegEx), + } +} + +func (s *HostNameOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostNameOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHostNameOperator(input string) (*HostNameOperator, error) { + vals := map[string]HostNameOperator{ + "any": HostNameOperatorAny, + "beginswith": HostNameOperatorBeginsWith, + "contains": HostNameOperatorContains, + "endswith": HostNameOperatorEndsWith, + "equal": HostNameOperatorEqual, + "greaterthan": HostNameOperatorGreaterThan, + "greaterthanorequal": HostNameOperatorGreaterThanOrEqual, + "lessthan": HostNameOperatorLessThan, + "lessthanorequal": HostNameOperatorLessThanOrEqual, + "regex": HostNameOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostNameOperator(input) + return &out, nil +} + +type IsDeviceMatchValue string + +const ( + IsDeviceMatchValueDesktop IsDeviceMatchValue = "Desktop" + IsDeviceMatchValueMobile IsDeviceMatchValue = "Mobile" +) + +func PossibleValuesForIsDeviceMatchValue() []string { + return []string{ + string(IsDeviceMatchValueDesktop), + string(IsDeviceMatchValueMobile), + } +} + +func (s *IsDeviceMatchValue) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsDeviceMatchValue(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsDeviceMatchValue(input string) (*IsDeviceMatchValue, error) { + vals := map[string]IsDeviceMatchValue{ + "desktop": IsDeviceMatchValueDesktop, + "mobile": IsDeviceMatchValueMobile, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsDeviceMatchValue(input) + return &out, nil +} + +type IsDeviceOperator string + +const ( + IsDeviceOperatorEqual IsDeviceOperator = "Equal" +) + +func PossibleValuesForIsDeviceOperator() []string { + return []string{ + string(IsDeviceOperatorEqual), + } +} + +func (s *IsDeviceOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsDeviceOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsDeviceOperator(input string) (*IsDeviceOperator, error) { + vals := map[string]IsDeviceOperator{ + "equal": IsDeviceOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsDeviceOperator(input) + return &out, nil +} + +type KeyVaultSigningKeyParametersType string + +const ( + KeyVaultSigningKeyParametersTypeKeyVaultSigningKeyParameters KeyVaultSigningKeyParametersType = "KeyVaultSigningKeyParameters" +) + +func PossibleValuesForKeyVaultSigningKeyParametersType() []string { + return []string{ + string(KeyVaultSigningKeyParametersTypeKeyVaultSigningKeyParameters), + } +} + +func (s *KeyVaultSigningKeyParametersType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyVaultSigningKeyParametersType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyVaultSigningKeyParametersType(input string) (*KeyVaultSigningKeyParametersType, error) { + vals := map[string]KeyVaultSigningKeyParametersType{ + "keyvaultsigningkeyparameters": KeyVaultSigningKeyParametersTypeKeyVaultSigningKeyParameters, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyVaultSigningKeyParametersType(input) + return &out, nil +} + +type MatchVariable string + +const ( + MatchVariableClientPort MatchVariable = "ClientPort" + MatchVariableCookies MatchVariable = "Cookies" + MatchVariableHTTPVersion MatchVariable = "HttpVersion" + MatchVariableHostName MatchVariable = "HostName" + MatchVariableIsDevice MatchVariable = "IsDevice" + MatchVariablePostArgs MatchVariable = "PostArgs" + MatchVariableQueryString MatchVariable = "QueryString" + MatchVariableRemoteAddress MatchVariable = "RemoteAddress" + MatchVariableRequestBody MatchVariable = "RequestBody" + MatchVariableRequestHeader MatchVariable = "RequestHeader" + MatchVariableRequestMethod MatchVariable = "RequestMethod" + MatchVariableRequestScheme MatchVariable = "RequestScheme" + MatchVariableRequestUri MatchVariable = "RequestUri" + MatchVariableServerPort MatchVariable = "ServerPort" + MatchVariableSocketAddr MatchVariable = "SocketAddr" + MatchVariableSslProtocol MatchVariable = "SslProtocol" + MatchVariableUrlFileExtension MatchVariable = "UrlFileExtension" + MatchVariableUrlFileName MatchVariable = "UrlFileName" + MatchVariableUrlPath MatchVariable = "UrlPath" +) + +func PossibleValuesForMatchVariable() []string { + return []string{ + string(MatchVariableClientPort), + string(MatchVariableCookies), + string(MatchVariableHTTPVersion), + string(MatchVariableHostName), + string(MatchVariableIsDevice), + string(MatchVariablePostArgs), + string(MatchVariableQueryString), + string(MatchVariableRemoteAddress), + string(MatchVariableRequestBody), + string(MatchVariableRequestHeader), + string(MatchVariableRequestMethod), + string(MatchVariableRequestScheme), + string(MatchVariableRequestUri), + string(MatchVariableServerPort), + string(MatchVariableSocketAddr), + string(MatchVariableSslProtocol), + string(MatchVariableUrlFileExtension), + string(MatchVariableUrlFileName), + string(MatchVariableUrlPath), + } +} + +func (s *MatchVariable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchVariable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMatchVariable(input string) (*MatchVariable, error) { + vals := map[string]MatchVariable{ + "clientport": MatchVariableClientPort, + "cookies": MatchVariableCookies, + "httpversion": MatchVariableHTTPVersion, + "hostname": MatchVariableHostName, + "isdevice": MatchVariableIsDevice, + "postargs": MatchVariablePostArgs, + "querystring": MatchVariableQueryString, + "remoteaddress": MatchVariableRemoteAddress, + "requestbody": MatchVariableRequestBody, + "requestheader": MatchVariableRequestHeader, + "requestmethod": MatchVariableRequestMethod, + "requestscheme": MatchVariableRequestScheme, + "requesturi": MatchVariableRequestUri, + "serverport": MatchVariableServerPort, + "socketaddr": MatchVariableSocketAddr, + "sslprotocol": MatchVariableSslProtocol, + "urlfileextension": MatchVariableUrlFileExtension, + "urlfilename": MatchVariableUrlFileName, + "urlpath": MatchVariableUrlPath, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MatchVariable(input) + return &out, nil +} + +type Operator string + +const ( + OperatorEqual Operator = "Equal" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorEqual), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "equal": OperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type OptimizationType string + +const ( + OptimizationTypeDynamicSiteAcceleration OptimizationType = "DynamicSiteAcceleration" + OptimizationTypeGeneralMediaStreaming OptimizationType = "GeneralMediaStreaming" + OptimizationTypeGeneralWebDelivery OptimizationType = "GeneralWebDelivery" + OptimizationTypeLargeFileDownload OptimizationType = "LargeFileDownload" + OptimizationTypeVideoOnDemandMediaStreaming OptimizationType = "VideoOnDemandMediaStreaming" +) + +func PossibleValuesForOptimizationType() []string { + return []string{ + string(OptimizationTypeDynamicSiteAcceleration), + string(OptimizationTypeGeneralMediaStreaming), + string(OptimizationTypeGeneralWebDelivery), + string(OptimizationTypeLargeFileDownload), + string(OptimizationTypeVideoOnDemandMediaStreaming), + } +} + +func (s *OptimizationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOptimizationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOptimizationType(input string) (*OptimizationType, error) { + vals := map[string]OptimizationType{ + "dynamicsiteacceleration": OptimizationTypeDynamicSiteAcceleration, + "generalmediastreaming": OptimizationTypeGeneralMediaStreaming, + "generalwebdelivery": OptimizationTypeGeneralWebDelivery, + "largefiledownload": OptimizationTypeLargeFileDownload, + "videoondemandmediastreaming": OptimizationTypeVideoOnDemandMediaStreaming, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OptimizationType(input) + return &out, nil +} + +type ParamIndicator string + +const ( + ParamIndicatorExpires ParamIndicator = "Expires" + ParamIndicatorKeyId ParamIndicator = "KeyId" + ParamIndicatorSignature ParamIndicator = "Signature" +) + +func PossibleValuesForParamIndicator() []string { + return []string{ + string(ParamIndicatorExpires), + string(ParamIndicatorKeyId), + string(ParamIndicatorSignature), + } +} + +func (s *ParamIndicator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseParamIndicator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseParamIndicator(input string) (*ParamIndicator, error) { + vals := map[string]ParamIndicator{ + "expires": ParamIndicatorExpires, + "keyid": ParamIndicatorKeyId, + "signature": ParamIndicatorSignature, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ParamIndicator(input) + return &out, nil +} + +type PostArgsOperator string + +const ( + PostArgsOperatorAny PostArgsOperator = "Any" + PostArgsOperatorBeginsWith PostArgsOperator = "BeginsWith" + PostArgsOperatorContains PostArgsOperator = "Contains" + PostArgsOperatorEndsWith PostArgsOperator = "EndsWith" + PostArgsOperatorEqual PostArgsOperator = "Equal" + PostArgsOperatorGreaterThan PostArgsOperator = "GreaterThan" + PostArgsOperatorGreaterThanOrEqual PostArgsOperator = "GreaterThanOrEqual" + PostArgsOperatorLessThan PostArgsOperator = "LessThan" + PostArgsOperatorLessThanOrEqual PostArgsOperator = "LessThanOrEqual" + PostArgsOperatorRegEx PostArgsOperator = "RegEx" +) + +func PossibleValuesForPostArgsOperator() []string { + return []string{ + string(PostArgsOperatorAny), + string(PostArgsOperatorBeginsWith), + string(PostArgsOperatorContains), + string(PostArgsOperatorEndsWith), + string(PostArgsOperatorEqual), + string(PostArgsOperatorGreaterThan), + string(PostArgsOperatorGreaterThanOrEqual), + string(PostArgsOperatorLessThan), + string(PostArgsOperatorLessThanOrEqual), + string(PostArgsOperatorRegEx), + } +} + +func (s *PostArgsOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePostArgsOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePostArgsOperator(input string) (*PostArgsOperator, error) { + vals := map[string]PostArgsOperator{ + "any": PostArgsOperatorAny, + "beginswith": PostArgsOperatorBeginsWith, + "contains": PostArgsOperatorContains, + "endswith": PostArgsOperatorEndsWith, + "equal": PostArgsOperatorEqual, + "greaterthan": PostArgsOperatorGreaterThan, + "greaterthanorequal": PostArgsOperatorGreaterThanOrEqual, + "lessthan": PostArgsOperatorLessThan, + "lessthanorequal": PostArgsOperatorLessThanOrEqual, + "regex": PostArgsOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PostArgsOperator(input) + return &out, nil +} + +type PrivateEndpointStatus string + +const ( + PrivateEndpointStatusApproved PrivateEndpointStatus = "Approved" + PrivateEndpointStatusDisconnected PrivateEndpointStatus = "Disconnected" + PrivateEndpointStatusPending PrivateEndpointStatus = "Pending" + PrivateEndpointStatusRejected PrivateEndpointStatus = "Rejected" + PrivateEndpointStatusTimeout PrivateEndpointStatus = "Timeout" +) + +func PossibleValuesForPrivateEndpointStatus() []string { + return []string{ + string(PrivateEndpointStatusApproved), + string(PrivateEndpointStatusDisconnected), + string(PrivateEndpointStatusPending), + string(PrivateEndpointStatusRejected), + string(PrivateEndpointStatusTimeout), + } +} + +func (s *PrivateEndpointStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointStatus(input string) (*PrivateEndpointStatus, error) { + vals := map[string]PrivateEndpointStatus{ + "approved": PrivateEndpointStatusApproved, + "disconnected": PrivateEndpointStatusDisconnected, + "pending": PrivateEndpointStatusPending, + "rejected": PrivateEndpointStatusRejected, + "timeout": PrivateEndpointStatusTimeout, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointStatus(input) + return &out, nil +} + +type ProbeProtocol string + +const ( + ProbeProtocolHTTP ProbeProtocol = "Http" + ProbeProtocolHTTPS ProbeProtocol = "Https" + ProbeProtocolNotSet ProbeProtocol = "NotSet" +) + +func PossibleValuesForProbeProtocol() []string { + return []string{ + string(ProbeProtocolHTTP), + string(ProbeProtocolHTTPS), + string(ProbeProtocolNotSet), + } +} + +func (s *ProbeProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProbeProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProbeProtocol(input string) (*ProbeProtocol, error) { + vals := map[string]ProbeProtocol{ + "http": ProbeProtocolHTTP, + "https": ProbeProtocolHTTPS, + "notset": ProbeProtocolNotSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProbeProtocol(input) + return &out, nil +} + +type QueryStringBehavior string + +const ( + QueryStringBehaviorExclude QueryStringBehavior = "Exclude" + QueryStringBehaviorExcludeAll QueryStringBehavior = "ExcludeAll" + QueryStringBehaviorInclude QueryStringBehavior = "Include" + QueryStringBehaviorIncludeAll QueryStringBehavior = "IncludeAll" +) + +func PossibleValuesForQueryStringBehavior() []string { + return []string{ + string(QueryStringBehaviorExclude), + string(QueryStringBehaviorExcludeAll), + string(QueryStringBehaviorInclude), + string(QueryStringBehaviorIncludeAll), + } +} + +func (s *QueryStringBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryStringBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryStringBehavior(input string) (*QueryStringBehavior, error) { + vals := map[string]QueryStringBehavior{ + "exclude": QueryStringBehaviorExclude, + "excludeall": QueryStringBehaviorExcludeAll, + "include": QueryStringBehaviorInclude, + "includeall": QueryStringBehaviorIncludeAll, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryStringBehavior(input) + return &out, nil +} + +type QueryStringCachingBehavior string + +const ( + QueryStringCachingBehaviorBypassCaching QueryStringCachingBehavior = "BypassCaching" + QueryStringCachingBehaviorIgnoreQueryString QueryStringCachingBehavior = "IgnoreQueryString" + QueryStringCachingBehaviorNotSet QueryStringCachingBehavior = "NotSet" + QueryStringCachingBehaviorUseQueryString QueryStringCachingBehavior = "UseQueryString" +) + +func PossibleValuesForQueryStringCachingBehavior() []string { + return []string{ + string(QueryStringCachingBehaviorBypassCaching), + string(QueryStringCachingBehaviorIgnoreQueryString), + string(QueryStringCachingBehaviorNotSet), + string(QueryStringCachingBehaviorUseQueryString), + } +} + +func (s *QueryStringCachingBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryStringCachingBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryStringCachingBehavior(input string) (*QueryStringCachingBehavior, error) { + vals := map[string]QueryStringCachingBehavior{ + "bypasscaching": QueryStringCachingBehaviorBypassCaching, + "ignorequerystring": QueryStringCachingBehaviorIgnoreQueryString, + "notset": QueryStringCachingBehaviorNotSet, + "usequerystring": QueryStringCachingBehaviorUseQueryString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryStringCachingBehavior(input) + return &out, nil +} + +type QueryStringOperator string + +const ( + QueryStringOperatorAny QueryStringOperator = "Any" + QueryStringOperatorBeginsWith QueryStringOperator = "BeginsWith" + QueryStringOperatorContains QueryStringOperator = "Contains" + QueryStringOperatorEndsWith QueryStringOperator = "EndsWith" + QueryStringOperatorEqual QueryStringOperator = "Equal" + QueryStringOperatorGreaterThan QueryStringOperator = "GreaterThan" + QueryStringOperatorGreaterThanOrEqual QueryStringOperator = "GreaterThanOrEqual" + QueryStringOperatorLessThan QueryStringOperator = "LessThan" + QueryStringOperatorLessThanOrEqual QueryStringOperator = "LessThanOrEqual" + QueryStringOperatorRegEx QueryStringOperator = "RegEx" +) + +func PossibleValuesForQueryStringOperator() []string { + return []string{ + string(QueryStringOperatorAny), + string(QueryStringOperatorBeginsWith), + string(QueryStringOperatorContains), + string(QueryStringOperatorEndsWith), + string(QueryStringOperatorEqual), + string(QueryStringOperatorGreaterThan), + string(QueryStringOperatorGreaterThanOrEqual), + string(QueryStringOperatorLessThan), + string(QueryStringOperatorLessThanOrEqual), + string(QueryStringOperatorRegEx), + } +} + +func (s *QueryStringOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryStringOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryStringOperator(input string) (*QueryStringOperator, error) { + vals := map[string]QueryStringOperator{ + "any": QueryStringOperatorAny, + "beginswith": QueryStringOperatorBeginsWith, + "contains": QueryStringOperatorContains, + "endswith": QueryStringOperatorEndsWith, + "equal": QueryStringOperatorEqual, + "greaterthan": QueryStringOperatorGreaterThan, + "greaterthanorequal": QueryStringOperatorGreaterThanOrEqual, + "lessthan": QueryStringOperatorLessThan, + "lessthanorequal": QueryStringOperatorLessThanOrEqual, + "regex": QueryStringOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryStringOperator(input) + return &out, nil +} + +type RedirectType string + +const ( + RedirectTypeFound RedirectType = "Found" + RedirectTypeMoved RedirectType = "Moved" + RedirectTypePermanentRedirect RedirectType = "PermanentRedirect" + RedirectTypeTemporaryRedirect RedirectType = "TemporaryRedirect" +) + +func PossibleValuesForRedirectType() []string { + return []string{ + string(RedirectTypeFound), + string(RedirectTypeMoved), + string(RedirectTypePermanentRedirect), + string(RedirectTypeTemporaryRedirect), + } +} + +func (s *RedirectType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRedirectType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRedirectType(input string) (*RedirectType, error) { + vals := map[string]RedirectType{ + "found": RedirectTypeFound, + "moved": RedirectTypeMoved, + "permanentredirect": RedirectTypePermanentRedirect, + "temporaryredirect": RedirectTypeTemporaryRedirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RedirectType(input) + return &out, nil +} + +type RemoteAddressOperator string + +const ( + RemoteAddressOperatorAny RemoteAddressOperator = "Any" + RemoteAddressOperatorGeoMatch RemoteAddressOperator = "GeoMatch" + RemoteAddressOperatorIPMatch RemoteAddressOperator = "IPMatch" +) + +func PossibleValuesForRemoteAddressOperator() []string { + return []string{ + string(RemoteAddressOperatorAny), + string(RemoteAddressOperatorGeoMatch), + string(RemoteAddressOperatorIPMatch), + } +} + +func (s *RemoteAddressOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRemoteAddressOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRemoteAddressOperator(input string) (*RemoteAddressOperator, error) { + vals := map[string]RemoteAddressOperator{ + "any": RemoteAddressOperatorAny, + "geomatch": RemoteAddressOperatorGeoMatch, + "ipmatch": RemoteAddressOperatorIPMatch, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RemoteAddressOperator(input) + return &out, nil +} + +type RequestBodyOperator string + +const ( + RequestBodyOperatorAny RequestBodyOperator = "Any" + RequestBodyOperatorBeginsWith RequestBodyOperator = "BeginsWith" + RequestBodyOperatorContains RequestBodyOperator = "Contains" + RequestBodyOperatorEndsWith RequestBodyOperator = "EndsWith" + RequestBodyOperatorEqual RequestBodyOperator = "Equal" + RequestBodyOperatorGreaterThan RequestBodyOperator = "GreaterThan" + RequestBodyOperatorGreaterThanOrEqual RequestBodyOperator = "GreaterThanOrEqual" + RequestBodyOperatorLessThan RequestBodyOperator = "LessThan" + RequestBodyOperatorLessThanOrEqual RequestBodyOperator = "LessThanOrEqual" + RequestBodyOperatorRegEx RequestBodyOperator = "RegEx" +) + +func PossibleValuesForRequestBodyOperator() []string { + return []string{ + string(RequestBodyOperatorAny), + string(RequestBodyOperatorBeginsWith), + string(RequestBodyOperatorContains), + string(RequestBodyOperatorEndsWith), + string(RequestBodyOperatorEqual), + string(RequestBodyOperatorGreaterThan), + string(RequestBodyOperatorGreaterThanOrEqual), + string(RequestBodyOperatorLessThan), + string(RequestBodyOperatorLessThanOrEqual), + string(RequestBodyOperatorRegEx), + } +} + +func (s *RequestBodyOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestBodyOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestBodyOperator(input string) (*RequestBodyOperator, error) { + vals := map[string]RequestBodyOperator{ + "any": RequestBodyOperatorAny, + "beginswith": RequestBodyOperatorBeginsWith, + "contains": RequestBodyOperatorContains, + "endswith": RequestBodyOperatorEndsWith, + "equal": RequestBodyOperatorEqual, + "greaterthan": RequestBodyOperatorGreaterThan, + "greaterthanorequal": RequestBodyOperatorGreaterThanOrEqual, + "lessthan": RequestBodyOperatorLessThan, + "lessthanorequal": RequestBodyOperatorLessThanOrEqual, + "regex": RequestBodyOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestBodyOperator(input) + return &out, nil +} + +type RequestHeaderOperator string + +const ( + RequestHeaderOperatorAny RequestHeaderOperator = "Any" + RequestHeaderOperatorBeginsWith RequestHeaderOperator = "BeginsWith" + RequestHeaderOperatorContains RequestHeaderOperator = "Contains" + RequestHeaderOperatorEndsWith RequestHeaderOperator = "EndsWith" + RequestHeaderOperatorEqual RequestHeaderOperator = "Equal" + RequestHeaderOperatorGreaterThan RequestHeaderOperator = "GreaterThan" + RequestHeaderOperatorGreaterThanOrEqual RequestHeaderOperator = "GreaterThanOrEqual" + RequestHeaderOperatorLessThan RequestHeaderOperator = "LessThan" + RequestHeaderOperatorLessThanOrEqual RequestHeaderOperator = "LessThanOrEqual" + RequestHeaderOperatorRegEx RequestHeaderOperator = "RegEx" +) + +func PossibleValuesForRequestHeaderOperator() []string { + return []string{ + string(RequestHeaderOperatorAny), + string(RequestHeaderOperatorBeginsWith), + string(RequestHeaderOperatorContains), + string(RequestHeaderOperatorEndsWith), + string(RequestHeaderOperatorEqual), + string(RequestHeaderOperatorGreaterThan), + string(RequestHeaderOperatorGreaterThanOrEqual), + string(RequestHeaderOperatorLessThan), + string(RequestHeaderOperatorLessThanOrEqual), + string(RequestHeaderOperatorRegEx), + } +} + +func (s *RequestHeaderOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestHeaderOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestHeaderOperator(input string) (*RequestHeaderOperator, error) { + vals := map[string]RequestHeaderOperator{ + "any": RequestHeaderOperatorAny, + "beginswith": RequestHeaderOperatorBeginsWith, + "contains": RequestHeaderOperatorContains, + "endswith": RequestHeaderOperatorEndsWith, + "equal": RequestHeaderOperatorEqual, + "greaterthan": RequestHeaderOperatorGreaterThan, + "greaterthanorequal": RequestHeaderOperatorGreaterThanOrEqual, + "lessthan": RequestHeaderOperatorLessThan, + "lessthanorequal": RequestHeaderOperatorLessThanOrEqual, + "regex": RequestHeaderOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestHeaderOperator(input) + return &out, nil +} + +type RequestMethodMatchValue string + +const ( + RequestMethodMatchValueDELETE RequestMethodMatchValue = "DELETE" + RequestMethodMatchValueGET RequestMethodMatchValue = "GET" + RequestMethodMatchValueHEAD RequestMethodMatchValue = "HEAD" + RequestMethodMatchValueOPTIONS RequestMethodMatchValue = "OPTIONS" + RequestMethodMatchValuePOST RequestMethodMatchValue = "POST" + RequestMethodMatchValuePUT RequestMethodMatchValue = "PUT" + RequestMethodMatchValueTRACE RequestMethodMatchValue = "TRACE" +) + +func PossibleValuesForRequestMethodMatchValue() []string { + return []string{ + string(RequestMethodMatchValueDELETE), + string(RequestMethodMatchValueGET), + string(RequestMethodMatchValueHEAD), + string(RequestMethodMatchValueOPTIONS), + string(RequestMethodMatchValuePOST), + string(RequestMethodMatchValuePUT), + string(RequestMethodMatchValueTRACE), + } +} + +func (s *RequestMethodMatchValue) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestMethodMatchValue(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestMethodMatchValue(input string) (*RequestMethodMatchValue, error) { + vals := map[string]RequestMethodMatchValue{ + "delete": RequestMethodMatchValueDELETE, + "get": RequestMethodMatchValueGET, + "head": RequestMethodMatchValueHEAD, + "options": RequestMethodMatchValueOPTIONS, + "post": RequestMethodMatchValuePOST, + "put": RequestMethodMatchValuePUT, + "trace": RequestMethodMatchValueTRACE, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestMethodMatchValue(input) + return &out, nil +} + +type RequestMethodOperator string + +const ( + RequestMethodOperatorEqual RequestMethodOperator = "Equal" +) + +func PossibleValuesForRequestMethodOperator() []string { + return []string{ + string(RequestMethodOperatorEqual), + } +} + +func (s *RequestMethodOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestMethodOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestMethodOperator(input string) (*RequestMethodOperator, error) { + vals := map[string]RequestMethodOperator{ + "equal": RequestMethodOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestMethodOperator(input) + return &out, nil +} + +type RequestSchemeMatchValue string + +const ( + RequestSchemeMatchValueHTTP RequestSchemeMatchValue = "HTTP" + RequestSchemeMatchValueHTTPS RequestSchemeMatchValue = "HTTPS" +) + +func PossibleValuesForRequestSchemeMatchValue() []string { + return []string{ + string(RequestSchemeMatchValueHTTP), + string(RequestSchemeMatchValueHTTPS), + } +} + +func (s *RequestSchemeMatchValue) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestSchemeMatchValue(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestSchemeMatchValue(input string) (*RequestSchemeMatchValue, error) { + vals := map[string]RequestSchemeMatchValue{ + "http": RequestSchemeMatchValueHTTP, + "https": RequestSchemeMatchValueHTTPS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestSchemeMatchValue(input) + return &out, nil +} + +type RequestUriOperator string + +const ( + RequestUriOperatorAny RequestUriOperator = "Any" + RequestUriOperatorBeginsWith RequestUriOperator = "BeginsWith" + RequestUriOperatorContains RequestUriOperator = "Contains" + RequestUriOperatorEndsWith RequestUriOperator = "EndsWith" + RequestUriOperatorEqual RequestUriOperator = "Equal" + RequestUriOperatorGreaterThan RequestUriOperator = "GreaterThan" + RequestUriOperatorGreaterThanOrEqual RequestUriOperator = "GreaterThanOrEqual" + RequestUriOperatorLessThan RequestUriOperator = "LessThan" + RequestUriOperatorLessThanOrEqual RequestUriOperator = "LessThanOrEqual" + RequestUriOperatorRegEx RequestUriOperator = "RegEx" +) + +func PossibleValuesForRequestUriOperator() []string { + return []string{ + string(RequestUriOperatorAny), + string(RequestUriOperatorBeginsWith), + string(RequestUriOperatorContains), + string(RequestUriOperatorEndsWith), + string(RequestUriOperatorEqual), + string(RequestUriOperatorGreaterThan), + string(RequestUriOperatorGreaterThanOrEqual), + string(RequestUriOperatorLessThan), + string(RequestUriOperatorLessThanOrEqual), + string(RequestUriOperatorRegEx), + } +} + +func (s *RequestUriOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestUriOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestUriOperator(input string) (*RequestUriOperator, error) { + vals := map[string]RequestUriOperator{ + "any": RequestUriOperatorAny, + "beginswith": RequestUriOperatorBeginsWith, + "contains": RequestUriOperatorContains, + "endswith": RequestUriOperatorEndsWith, + "equal": RequestUriOperatorEqual, + "greaterthan": RequestUriOperatorGreaterThan, + "greaterthanorequal": RequestUriOperatorGreaterThanOrEqual, + "lessthan": RequestUriOperatorLessThan, + "lessthanorequal": RequestUriOperatorLessThanOrEqual, + "regex": RequestUriOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestUriOperator(input) + return &out, nil +} + +type ResourceUsageUnit string + +const ( + ResourceUsageUnitCount ResourceUsageUnit = "count" +) + +func PossibleValuesForResourceUsageUnit() []string { + return []string{ + string(ResourceUsageUnitCount), + } +} + +func (s *ResourceUsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceUsageUnit(input string) (*ResourceUsageUnit, error) { + vals := map[string]ResourceUsageUnit{ + "count": ResourceUsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceUsageUnit(input) + return &out, nil +} + +type ResponseBasedDetectedErrorTypes string + +const ( + ResponseBasedDetectedErrorTypesNone ResponseBasedDetectedErrorTypes = "None" + ResponseBasedDetectedErrorTypesTcpAndHTTPErrors ResponseBasedDetectedErrorTypes = "TcpAndHttpErrors" + ResponseBasedDetectedErrorTypesTcpErrorsOnly ResponseBasedDetectedErrorTypes = "TcpErrorsOnly" +) + +func PossibleValuesForResponseBasedDetectedErrorTypes() []string { + return []string{ + string(ResponseBasedDetectedErrorTypesNone), + string(ResponseBasedDetectedErrorTypesTcpAndHTTPErrors), + string(ResponseBasedDetectedErrorTypesTcpErrorsOnly), + } +} + +func (s *ResponseBasedDetectedErrorTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResponseBasedDetectedErrorTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResponseBasedDetectedErrorTypes(input string) (*ResponseBasedDetectedErrorTypes, error) { + vals := map[string]ResponseBasedDetectedErrorTypes{ + "none": ResponseBasedDetectedErrorTypesNone, + "tcpandhttperrors": ResponseBasedDetectedErrorTypesTcpAndHTTPErrors, + "tcperrorsonly": ResponseBasedDetectedErrorTypesTcpErrorsOnly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResponseBasedDetectedErrorTypes(input) + return &out, nil +} + +type RuleCacheBehavior string + +const ( + RuleCacheBehaviorHonorOrigin RuleCacheBehavior = "HonorOrigin" + RuleCacheBehaviorOverrideAlways RuleCacheBehavior = "OverrideAlways" + RuleCacheBehaviorOverrideIfOriginMissing RuleCacheBehavior = "OverrideIfOriginMissing" +) + +func PossibleValuesForRuleCacheBehavior() []string { + return []string{ + string(RuleCacheBehaviorHonorOrigin), + string(RuleCacheBehaviorOverrideAlways), + string(RuleCacheBehaviorOverrideIfOriginMissing), + } +} + +func (s *RuleCacheBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleCacheBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleCacheBehavior(input string) (*RuleCacheBehavior, error) { + vals := map[string]RuleCacheBehavior{ + "honororigin": RuleCacheBehaviorHonorOrigin, + "overridealways": RuleCacheBehaviorOverrideAlways, + "overrideiforiginmissing": RuleCacheBehaviorOverrideIfOriginMissing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleCacheBehavior(input) + return &out, nil +} + +type RuleIsCompressionEnabled string + +const ( + RuleIsCompressionEnabledDisabled RuleIsCompressionEnabled = "Disabled" + RuleIsCompressionEnabledEnabled RuleIsCompressionEnabled = "Enabled" +) + +func PossibleValuesForRuleIsCompressionEnabled() []string { + return []string{ + string(RuleIsCompressionEnabledDisabled), + string(RuleIsCompressionEnabledEnabled), + } +} + +func (s *RuleIsCompressionEnabled) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleIsCompressionEnabled(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleIsCompressionEnabled(input string) (*RuleIsCompressionEnabled, error) { + vals := map[string]RuleIsCompressionEnabled{ + "disabled": RuleIsCompressionEnabledDisabled, + "enabled": RuleIsCompressionEnabledEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleIsCompressionEnabled(input) + return &out, nil +} + +type RuleQueryStringCachingBehavior string + +const ( + RuleQueryStringCachingBehaviorIgnoreQueryString RuleQueryStringCachingBehavior = "IgnoreQueryString" + RuleQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings RuleQueryStringCachingBehavior = "IgnoreSpecifiedQueryStrings" + RuleQueryStringCachingBehaviorIncludeSpecifiedQueryStrings RuleQueryStringCachingBehavior = "IncludeSpecifiedQueryStrings" + RuleQueryStringCachingBehaviorUseQueryString RuleQueryStringCachingBehavior = "UseQueryString" +) + +func PossibleValuesForRuleQueryStringCachingBehavior() []string { + return []string{ + string(RuleQueryStringCachingBehaviorIgnoreQueryString), + string(RuleQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings), + string(RuleQueryStringCachingBehaviorIncludeSpecifiedQueryStrings), + string(RuleQueryStringCachingBehaviorUseQueryString), + } +} + +func (s *RuleQueryStringCachingBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleQueryStringCachingBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleQueryStringCachingBehavior(input string) (*RuleQueryStringCachingBehavior, error) { + vals := map[string]RuleQueryStringCachingBehavior{ + "ignorequerystring": RuleQueryStringCachingBehaviorIgnoreQueryString, + "ignorespecifiedquerystrings": RuleQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings, + "includespecifiedquerystrings": RuleQueryStringCachingBehaviorIncludeSpecifiedQueryStrings, + "usequerystring": RuleQueryStringCachingBehaviorUseQueryString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleQueryStringCachingBehavior(input) + return &out, nil +} + +type ServerPortOperator string + +const ( + ServerPortOperatorAny ServerPortOperator = "Any" + ServerPortOperatorBeginsWith ServerPortOperator = "BeginsWith" + ServerPortOperatorContains ServerPortOperator = "Contains" + ServerPortOperatorEndsWith ServerPortOperator = "EndsWith" + ServerPortOperatorEqual ServerPortOperator = "Equal" + ServerPortOperatorGreaterThan ServerPortOperator = "GreaterThan" + ServerPortOperatorGreaterThanOrEqual ServerPortOperator = "GreaterThanOrEqual" + ServerPortOperatorLessThan ServerPortOperator = "LessThan" + ServerPortOperatorLessThanOrEqual ServerPortOperator = "LessThanOrEqual" + ServerPortOperatorRegEx ServerPortOperator = "RegEx" +) + +func PossibleValuesForServerPortOperator() []string { + return []string{ + string(ServerPortOperatorAny), + string(ServerPortOperatorBeginsWith), + string(ServerPortOperatorContains), + string(ServerPortOperatorEndsWith), + string(ServerPortOperatorEqual), + string(ServerPortOperatorGreaterThan), + string(ServerPortOperatorGreaterThanOrEqual), + string(ServerPortOperatorLessThan), + string(ServerPortOperatorLessThanOrEqual), + string(ServerPortOperatorRegEx), + } +} + +func (s *ServerPortOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerPortOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerPortOperator(input string) (*ServerPortOperator, error) { + vals := map[string]ServerPortOperator{ + "any": ServerPortOperatorAny, + "beginswith": ServerPortOperatorBeginsWith, + "contains": ServerPortOperatorContains, + "endswith": ServerPortOperatorEndsWith, + "equal": ServerPortOperatorEqual, + "greaterthan": ServerPortOperatorGreaterThan, + "greaterthanorequal": ServerPortOperatorGreaterThanOrEqual, + "lessthan": ServerPortOperatorLessThan, + "lessthanorequal": ServerPortOperatorLessThanOrEqual, + "regex": ServerPortOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerPortOperator(input) + return &out, nil +} + +type SocketAddrOperator string + +const ( + SocketAddrOperatorAny SocketAddrOperator = "Any" + SocketAddrOperatorIPMatch SocketAddrOperator = "IPMatch" +) + +func PossibleValuesForSocketAddrOperator() []string { + return []string{ + string(SocketAddrOperatorAny), + string(SocketAddrOperatorIPMatch), + } +} + +func (s *SocketAddrOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSocketAddrOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSocketAddrOperator(input string) (*SocketAddrOperator, error) { + vals := map[string]SocketAddrOperator{ + "any": SocketAddrOperatorAny, + "ipmatch": SocketAddrOperatorIPMatch, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SocketAddrOperator(input) + return &out, nil +} + +type SslProtocol string + +const ( + SslProtocolTLSvOne SslProtocol = "TLSv1" + SslProtocolTLSvOnePointOne SslProtocol = "TLSv1.1" + SslProtocolTLSvOnePointTwo SslProtocol = "TLSv1.2" +) + +func PossibleValuesForSslProtocol() []string { + return []string{ + string(SslProtocolTLSvOne), + string(SslProtocolTLSvOnePointOne), + string(SslProtocolTLSvOnePointTwo), + } +} + +func (s *SslProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSslProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSslProtocol(input string) (*SslProtocol, error) { + vals := map[string]SslProtocol{ + "tlsv1": SslProtocolTLSvOne, + "tlsv1.1": SslProtocolTLSvOnePointOne, + "tlsv1.2": SslProtocolTLSvOnePointTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SslProtocol(input) + return &out, nil +} + +type SslProtocolOperator string + +const ( + SslProtocolOperatorEqual SslProtocolOperator = "Equal" +) + +func PossibleValuesForSslProtocolOperator() []string { + return []string{ + string(SslProtocolOperatorEqual), + } +} + +func (s *SslProtocolOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSslProtocolOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSslProtocolOperator(input string) (*SslProtocolOperator, error) { + vals := map[string]SslProtocolOperator{ + "equal": SslProtocolOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SslProtocolOperator(input) + return &out, nil +} + +type Transform string + +const ( + TransformLowercase Transform = "Lowercase" + TransformRemoveNulls Transform = "RemoveNulls" + TransformTrim Transform = "Trim" + TransformUppercase Transform = "Uppercase" + TransformUrlDecode Transform = "UrlDecode" + TransformUrlEncode Transform = "UrlEncode" +) + +func PossibleValuesForTransform() []string { + return []string{ + string(TransformLowercase), + string(TransformRemoveNulls), + string(TransformTrim), + string(TransformUppercase), + string(TransformUrlDecode), + string(TransformUrlEncode), + } +} + +func (s *Transform) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTransform(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTransform(input string) (*Transform, error) { + vals := map[string]Transform{ + "lowercase": TransformLowercase, + "removenulls": TransformRemoveNulls, + "trim": TransformTrim, + "uppercase": TransformUppercase, + "urldecode": TransformUrlDecode, + "urlencode": TransformUrlEncode, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Transform(input) + return &out, nil +} + +type UrlFileExtensionOperator string + +const ( + UrlFileExtensionOperatorAny UrlFileExtensionOperator = "Any" + UrlFileExtensionOperatorBeginsWith UrlFileExtensionOperator = "BeginsWith" + UrlFileExtensionOperatorContains UrlFileExtensionOperator = "Contains" + UrlFileExtensionOperatorEndsWith UrlFileExtensionOperator = "EndsWith" + UrlFileExtensionOperatorEqual UrlFileExtensionOperator = "Equal" + UrlFileExtensionOperatorGreaterThan UrlFileExtensionOperator = "GreaterThan" + UrlFileExtensionOperatorGreaterThanOrEqual UrlFileExtensionOperator = "GreaterThanOrEqual" + UrlFileExtensionOperatorLessThan UrlFileExtensionOperator = "LessThan" + UrlFileExtensionOperatorLessThanOrEqual UrlFileExtensionOperator = "LessThanOrEqual" + UrlFileExtensionOperatorRegEx UrlFileExtensionOperator = "RegEx" +) + +func PossibleValuesForUrlFileExtensionOperator() []string { + return []string{ + string(UrlFileExtensionOperatorAny), + string(UrlFileExtensionOperatorBeginsWith), + string(UrlFileExtensionOperatorContains), + string(UrlFileExtensionOperatorEndsWith), + string(UrlFileExtensionOperatorEqual), + string(UrlFileExtensionOperatorGreaterThan), + string(UrlFileExtensionOperatorGreaterThanOrEqual), + string(UrlFileExtensionOperatorLessThan), + string(UrlFileExtensionOperatorLessThanOrEqual), + string(UrlFileExtensionOperatorRegEx), + } +} + +func (s *UrlFileExtensionOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUrlFileExtensionOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUrlFileExtensionOperator(input string) (*UrlFileExtensionOperator, error) { + vals := map[string]UrlFileExtensionOperator{ + "any": UrlFileExtensionOperatorAny, + "beginswith": UrlFileExtensionOperatorBeginsWith, + "contains": UrlFileExtensionOperatorContains, + "endswith": UrlFileExtensionOperatorEndsWith, + "equal": UrlFileExtensionOperatorEqual, + "greaterthan": UrlFileExtensionOperatorGreaterThan, + "greaterthanorequal": UrlFileExtensionOperatorGreaterThanOrEqual, + "lessthan": UrlFileExtensionOperatorLessThan, + "lessthanorequal": UrlFileExtensionOperatorLessThanOrEqual, + "regex": UrlFileExtensionOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UrlFileExtensionOperator(input) + return &out, nil +} + +type UrlFileNameOperator string + +const ( + UrlFileNameOperatorAny UrlFileNameOperator = "Any" + UrlFileNameOperatorBeginsWith UrlFileNameOperator = "BeginsWith" + UrlFileNameOperatorContains UrlFileNameOperator = "Contains" + UrlFileNameOperatorEndsWith UrlFileNameOperator = "EndsWith" + UrlFileNameOperatorEqual UrlFileNameOperator = "Equal" + UrlFileNameOperatorGreaterThan UrlFileNameOperator = "GreaterThan" + UrlFileNameOperatorGreaterThanOrEqual UrlFileNameOperator = "GreaterThanOrEqual" + UrlFileNameOperatorLessThan UrlFileNameOperator = "LessThan" + UrlFileNameOperatorLessThanOrEqual UrlFileNameOperator = "LessThanOrEqual" + UrlFileNameOperatorRegEx UrlFileNameOperator = "RegEx" +) + +func PossibleValuesForUrlFileNameOperator() []string { + return []string{ + string(UrlFileNameOperatorAny), + string(UrlFileNameOperatorBeginsWith), + string(UrlFileNameOperatorContains), + string(UrlFileNameOperatorEndsWith), + string(UrlFileNameOperatorEqual), + string(UrlFileNameOperatorGreaterThan), + string(UrlFileNameOperatorGreaterThanOrEqual), + string(UrlFileNameOperatorLessThan), + string(UrlFileNameOperatorLessThanOrEqual), + string(UrlFileNameOperatorRegEx), + } +} + +func (s *UrlFileNameOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUrlFileNameOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUrlFileNameOperator(input string) (*UrlFileNameOperator, error) { + vals := map[string]UrlFileNameOperator{ + "any": UrlFileNameOperatorAny, + "beginswith": UrlFileNameOperatorBeginsWith, + "contains": UrlFileNameOperatorContains, + "endswith": UrlFileNameOperatorEndsWith, + "equal": UrlFileNameOperatorEqual, + "greaterthan": UrlFileNameOperatorGreaterThan, + "greaterthanorequal": UrlFileNameOperatorGreaterThanOrEqual, + "lessthan": UrlFileNameOperatorLessThan, + "lessthanorequal": UrlFileNameOperatorLessThanOrEqual, + "regex": UrlFileNameOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UrlFileNameOperator(input) + return &out, nil +} + +type UrlPathOperator string + +const ( + UrlPathOperatorAny UrlPathOperator = "Any" + UrlPathOperatorBeginsWith UrlPathOperator = "BeginsWith" + UrlPathOperatorContains UrlPathOperator = "Contains" + UrlPathOperatorEndsWith UrlPathOperator = "EndsWith" + UrlPathOperatorEqual UrlPathOperator = "Equal" + UrlPathOperatorGreaterThan UrlPathOperator = "GreaterThan" + UrlPathOperatorGreaterThanOrEqual UrlPathOperator = "GreaterThanOrEqual" + UrlPathOperatorLessThan UrlPathOperator = "LessThan" + UrlPathOperatorLessThanOrEqual UrlPathOperator = "LessThanOrEqual" + UrlPathOperatorRegEx UrlPathOperator = "RegEx" + UrlPathOperatorWildcard UrlPathOperator = "Wildcard" +) + +func PossibleValuesForUrlPathOperator() []string { + return []string{ + string(UrlPathOperatorAny), + string(UrlPathOperatorBeginsWith), + string(UrlPathOperatorContains), + string(UrlPathOperatorEndsWith), + string(UrlPathOperatorEqual), + string(UrlPathOperatorGreaterThan), + string(UrlPathOperatorGreaterThanOrEqual), + string(UrlPathOperatorLessThan), + string(UrlPathOperatorLessThanOrEqual), + string(UrlPathOperatorRegEx), + string(UrlPathOperatorWildcard), + } +} + +func (s *UrlPathOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUrlPathOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUrlPathOperator(input string) (*UrlPathOperator, error) { + vals := map[string]UrlPathOperator{ + "any": UrlPathOperatorAny, + "beginswith": UrlPathOperatorBeginsWith, + "contains": UrlPathOperatorContains, + "endswith": UrlPathOperatorEndsWith, + "equal": UrlPathOperatorEqual, + "greaterthan": UrlPathOperatorGreaterThan, + "greaterthanorequal": UrlPathOperatorGreaterThanOrEqual, + "lessthan": UrlPathOperatorLessThan, + "lessthanorequal": UrlPathOperatorLessThanOrEqual, + "regex": UrlPathOperatorRegEx, + "wildcard": UrlPathOperatorWildcard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UrlPathOperator(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/id_endpoint.go b/resource-manager/cdn/2024-02-01/endpoints/id_endpoint.go new file mode 100644 index 00000000000..9d2e722c2d3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/id_endpoint.go @@ -0,0 +1,139 @@ +package endpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&EndpointId{}) +} + +var _ resourceids.ResourceId = &EndpointId{} + +// EndpointId is a struct representing the Resource ID for a Endpoint +type EndpointId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + EndpointName string +} + +// NewEndpointID returns a new EndpointId struct +func NewEndpointID(subscriptionId string, resourceGroupName string, profileName string, endpointName string) EndpointId { + return EndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + EndpointName: endpointName, + } +} + +// ParseEndpointID parses 'input' into a EndpointId +func ParseEndpointID(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEndpointIDInsensitively parses 'input' case-insensitively into a EndpointId +// note: this method should only be used for API response data and not user input +func ParseEndpointIDInsensitively(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.EndpointName, ok = input.Parsed["endpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointName", input) + } + + return nil +} + +// ValidateEndpointID checks that 'input' can be parsed as a Endpoint ID +func ValidateEndpointID(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 := ParseEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Endpoint ID +func (id EndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/endpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.EndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Endpoint ID +func (id EndpointId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticEndpoints", "endpoints", "endpoints"), + resourceids.UserSpecifiedSegment("endpointName", "endpointValue"), + } +} + +// String returns a human-readable description of this Endpoint ID +func (id EndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Endpoint Name: %q", id.EndpointName), + } + return fmt.Sprintf("Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/id_endpoint_test.go b/resource-manager/cdn/2024-02-01/endpoints/id_endpoint_test.go new file mode 100644 index 00000000000..e160b2b9d3b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/id_endpoint_test.go @@ -0,0 +1,327 @@ +package endpoints + +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 = &EndpointId{} + +func TestNewEndpointID(t *testing.T) { + id := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.EndpointName != "endpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointName'", id.EndpointName, "endpointValue") + } +} + +func TestFormatEndpointID(t *testing.T) { + actual := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestParseEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + EndpointName: "eNdPoInTvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestSegmentsForEndpointId(t *testing.T) { + segments := EndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EndpointId 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/cdn/2024-02-01/endpoints/id_profile.go b/resource-manager/cdn/2024-02-01/endpoints/id_profile.go new file mode 100644 index 00000000000..dc5d404c929 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/id_profile.go @@ -0,0 +1,130 @@ +package endpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/id_profile_test.go b/resource-manager/cdn/2024-02-01/endpoints/id_profile_test.go new file mode 100644 index 00000000000..81485b03c04 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/id_profile_test.go @@ -0,0 +1,282 @@ +package endpoints + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/endpoints/method_create.go b/resource-manager/cdn/2024-02-01/endpoints/method_create.go new file mode 100644 index 00000000000..f5a28f25dec --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_create.go @@ -0,0 +1,76 @@ +package endpoints + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Endpoint +} + +// Create ... +func (c EndpointsClient) Create(ctx context.Context, id EndpointId, input Endpoint) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c EndpointsClient) CreateThenPoll(ctx context.Context, id EndpointId, input Endpoint) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_delete.go b/resource-manager/cdn/2024-02-01/endpoints/method_delete.go new file mode 100644 index 00000000000..466f6bc5065 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_delete.go @@ -0,0 +1,71 @@ +package endpoints + +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 EndpointsClient) Delete(ctx context.Context, id EndpointId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c EndpointsClient) DeleteThenPoll(ctx context.Context, id EndpointId) 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/cdn/2024-02-01/endpoints/method_get.go b/resource-manager/cdn/2024-02-01/endpoints/method_get.go new file mode 100644 index 00000000000..d0d322403d0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_get.go @@ -0,0 +1,54 @@ +package endpoints + +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 *Endpoint +} + +// Get ... +func (c EndpointsClient) Get(ctx context.Context, id EndpointId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Endpoint + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_listbyprofile.go b/resource-manager/cdn/2024-02-01/endpoints/method_listbyprofile.go new file mode 100644 index 00000000000..4cc86b4aa69 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_listbyprofile.go @@ -0,0 +1,105 @@ +package endpoints + +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 ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Endpoint +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []Endpoint +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c EndpointsClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + Path: fmt.Sprintf("%s/endpoints", 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 *[]Endpoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c EndpointsClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, EndpointOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EndpointsClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate EndpointOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]Endpoint, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_listresourceusage.go b/resource-manager/cdn/2024-02-01/endpoints/method_listresourceusage.go new file mode 100644 index 00000000000..31b7829b979 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_listresourceusage.go @@ -0,0 +1,105 @@ +package endpoints + +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 ListResourceUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceUsage +} + +type ListResourceUsageCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceUsage +} + +type ListResourceUsageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListResourceUsageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListResourceUsage ... +func (c EndpointsClient) ListResourceUsage(ctx context.Context, id EndpointId) (result ListResourceUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListResourceUsageCustomPager{}, + Path: fmt.Sprintf("%s/checkResourceUsage", 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 *[]ResourceUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourceUsageComplete retrieves all the results into a single object +func (c EndpointsClient) ListResourceUsageComplete(ctx context.Context, id EndpointId) (ListResourceUsageCompleteResult, error) { + return c.ListResourceUsageCompleteMatchingPredicate(ctx, id, ResourceUsageOperationPredicate{}) +} + +// ListResourceUsageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EndpointsClient) ListResourceUsageCompleteMatchingPredicate(ctx context.Context, id EndpointId, predicate ResourceUsageOperationPredicate) (result ListResourceUsageCompleteResult, err error) { + items := make([]ResourceUsage, 0) + + resp, err := c.ListResourceUsage(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListResourceUsageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_loadcontent.go b/resource-manager/cdn/2024-02-01/endpoints/method_loadcontent.go new file mode 100644 index 00000000000..b1ba0411544 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_loadcontent.go @@ -0,0 +1,74 @@ +package endpoints + +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 LoadContentOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// LoadContent ... +func (c EndpointsClient) LoadContent(ctx context.Context, id EndpointId, input LoadParameters) (result LoadContentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/load", 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 +} + +// LoadContentThenPoll performs LoadContent then polls until it's completed +func (c EndpointsClient) LoadContentThenPoll(ctx context.Context, id EndpointId, input LoadParameters) error { + result, err := c.LoadContent(ctx, id, input) + if err != nil { + return fmt.Errorf("performing LoadContent: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after LoadContent: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_purgecontent.go b/resource-manager/cdn/2024-02-01/endpoints/method_purgecontent.go new file mode 100644 index 00000000000..075274be601 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_purgecontent.go @@ -0,0 +1,74 @@ +package endpoints + +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 PurgeContentOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// PurgeContent ... +func (c EndpointsClient) PurgeContent(ctx context.Context, id EndpointId, input PurgeParameters) (result PurgeContentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/purge", 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 +} + +// PurgeContentThenPoll performs PurgeContent then polls until it's completed +func (c EndpointsClient) PurgeContentThenPoll(ctx context.Context, id EndpointId, input PurgeParameters) error { + result, err := c.PurgeContent(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PurgeContent: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PurgeContent: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_start.go b/resource-manager/cdn/2024-02-01/endpoints/method_start.go new file mode 100644 index 00000000000..c5c1f2c28a6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_start.go @@ -0,0 +1,71 @@ +package endpoints + +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 StartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Endpoint +} + +// Start ... +func (c EndpointsClient) Start(ctx context.Context, id EndpointId) (result StartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", 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 +} + +// StartThenPoll performs Start then polls until it's completed +func (c EndpointsClient) StartThenPoll(ctx context.Context, id EndpointId) error { + result, err := c.Start(ctx, id) + if err != nil { + return fmt.Errorf("performing Start: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Start: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_stop.go b/resource-manager/cdn/2024-02-01/endpoints/method_stop.go new file mode 100644 index 00000000000..84477fff9db --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_stop.go @@ -0,0 +1,71 @@ +package endpoints + +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 StopOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Endpoint +} + +// Stop ... +func (c EndpointsClient) Stop(ctx context.Context, id EndpointId) (result StopOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", 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 +} + +// StopThenPoll performs Stop then polls until it's completed +func (c EndpointsClient) StopThenPoll(ctx context.Context, id EndpointId) error { + result, err := c.Stop(ctx, id) + if err != nil { + return fmt.Errorf("performing Stop: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Stop: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/method_update.go b/resource-manager/cdn/2024-02-01/endpoints/method_update.go new file mode 100644 index 00000000000..b61db980e96 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_update.go @@ -0,0 +1,75 @@ +package endpoints + +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 + Model *Endpoint +} + +// Update ... +func (c EndpointsClient) Update(ctx context.Context, id EndpointId, input EndpointUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c EndpointsClient) UpdateThenPoll(ctx context.Context, id EndpointId, input EndpointUpdateParameters) 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/cdn/2024-02-01/endpoints/method_validatecustomdomain.go b/resource-manager/cdn/2024-02-01/endpoints/method_validatecustomdomain.go new file mode 100644 index 00000000000..125559b2c28 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/method_validatecustomdomain.go @@ -0,0 +1,59 @@ +package endpoints + +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 ValidateCustomDomainOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ValidateCustomDomainOutput +} + +// ValidateCustomDomain ... +func (c EndpointsClient) ValidateCustomDomain(ctx context.Context, id EndpointId, input ValidateCustomDomainInput) (result ValidateCustomDomainOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateCustomDomain", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ValidateCustomDomainOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_cacheconfiguration.go b/resource-manager/cdn/2024-02-01/endpoints/model_cacheconfiguration.go new file mode 100644 index 00000000000..21f119971ed --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_cacheconfiguration.go @@ -0,0 +1,12 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheConfiguration struct { + CacheBehavior *RuleCacheBehavior `json:"cacheBehavior,omitempty"` + CacheDuration *string `json:"cacheDuration,omitempty"` + IsCompressionEnabled *RuleIsCompressionEnabled `json:"isCompressionEnabled,omitempty"` + QueryParameters *string `json:"queryParameters,omitempty"` + QueryStringCachingBehavior *RuleQueryStringCachingBehavior `json:"queryStringCachingBehavior,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_cacheexpirationactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_cacheexpirationactionparameters.go new file mode 100644 index 00000000000..9546bfb6210 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_cacheexpirationactionparameters.go @@ -0,0 +1,43 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = CacheExpirationActionParameters{} + +type CacheExpirationActionParameters struct { + CacheBehavior CacheBehavior `json:"cacheBehavior"` + CacheDuration *string `json:"cacheDuration,omitempty"` + CacheType CacheType `json:"cacheType"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = CacheExpirationActionParameters{} + +func (s CacheExpirationActionParameters) MarshalJSON() ([]byte, error) { + type wrapper CacheExpirationActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CacheExpirationActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CacheExpirationActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleCacheExpirationActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CacheExpirationActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_cachekeyquerystringactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_cachekeyquerystringactionparameters.go new file mode 100644 index 00000000000..c1d45ce5b67 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_cachekeyquerystringactionparameters.go @@ -0,0 +1,42 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = CacheKeyQueryStringActionParameters{} + +type CacheKeyQueryStringActionParameters struct { + QueryParameters *string `json:"queryParameters,omitempty"` + QueryStringBehavior QueryStringBehavior `json:"queryStringBehavior"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = CacheKeyQueryStringActionParameters{} + +func (s CacheKeyQueryStringActionParameters) MarshalJSON() ([]byte, error) { + type wrapper CacheKeyQueryStringActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CacheKeyQueryStringActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CacheKeyQueryStringActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleCacheKeyQueryStringBehaviorActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CacheKeyQueryStringActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_clientportmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_clientportmatchconditionparameters.go new file mode 100644 index 00000000000..6b90d9e1019 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_clientportmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = ClientPortMatchConditionParameters{} + +type ClientPortMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator ClientPortOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = ClientPortMatchConditionParameters{} + +func (s ClientPortMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper ClientPortMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ClientPortMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ClientPortMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleClientPortConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ClientPortMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_cookiesmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_cookiesmatchconditionparameters.go new file mode 100644 index 00000000000..bd3b4d4361d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_cookiesmatchconditionparameters.go @@ -0,0 +1,45 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = CookiesMatchConditionParameters{} + +type CookiesMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator CookiesOperator `json:"operator"` + Selector *string `json:"selector,omitempty"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = CookiesMatchConditionParameters{} + +func (s CookiesMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper CookiesMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CookiesMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CookiesMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleCookiesConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CookiesMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedcustomdomain.go b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedcustomdomain.go new file mode 100644 index 00000000000..ec8b3de7b4b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedcustomdomain.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeepCreatedCustomDomain struct { + Name string `json:"name"` + Properties *DeepCreatedCustomDomainProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedcustomdomainproperties.go b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedcustomdomainproperties.go new file mode 100644 index 00000000000..6e671e7d83c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedcustomdomainproperties.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeepCreatedCustomDomainProperties struct { + HostName string `json:"hostName"` + ValidationData *string `json:"validationData,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigin.go b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigin.go new file mode 100644 index 00000000000..690b78c5197 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigin.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeepCreatedOrigin struct { + Name string `json:"name"` + Properties *DeepCreatedOriginProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigingroup.go b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigingroup.go new file mode 100644 index 00000000000..254badd74b7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigingroup.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeepCreatedOriginGroup struct { + Name string `json:"name"` + Properties *DeepCreatedOriginGroupProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigingroupproperties.go b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigingroupproperties.go new file mode 100644 index 00000000000..f29aff0fea0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedorigingroupproperties.go @@ -0,0 +1,11 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeepCreatedOriginGroupProperties struct { + HealthProbeSettings *HealthProbeParameters `json:"healthProbeSettings,omitempty"` + Origins []ResourceReference `json:"origins"` + ResponseBasedOriginErrorDetectionSettings *ResponseBasedOriginErrorDetectionParameters `json:"responseBasedOriginErrorDetectionSettings,omitempty"` + TrafficRestorationTimeToHealedOrNewEndpointsInMinutes *int64 `json:"trafficRestorationTimeToHealedOrNewEndpointsInMinutes,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedoriginproperties.go b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedoriginproperties.go new file mode 100644 index 00000000000..71dbdd39e96 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deepcreatedoriginproperties.go @@ -0,0 +1,19 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeepCreatedOriginProperties struct { + Enabled *bool `json:"enabled,omitempty"` + HTTPPort *int64 `json:"httpPort,omitempty"` + HTTPSPort *int64 `json:"httpsPort,omitempty"` + HostName string `json:"hostName"` + OriginHostHeader *string `json:"originHostHeader,omitempty"` + Priority *int64 `json:"priority,omitempty"` + PrivateEndpointStatus *PrivateEndpointStatus `json:"privateEndpointStatus,omitempty"` + PrivateLinkAlias *string `json:"privateLinkAlias,omitempty"` + PrivateLinkApprovalMessage *string `json:"privateLinkApprovalMessage,omitempty"` + PrivateLinkLocation *string `json:"privateLinkLocation,omitempty"` + PrivateLinkResourceId *string `json:"privateLinkResourceId,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrule.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrule.go new file mode 100644 index 00000000000..fb5414d1008 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrule.go @@ -0,0 +1,69 @@ +package endpoints + +import ( + "encoding/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 DeliveryRule struct { + Actions []DeliveryRuleAction `json:"actions"` + Conditions *[]DeliveryRuleCondition `json:"conditions,omitempty"` + Name *string `json:"name,omitempty"` + Order int64 `json:"order"` +} + +var _ json.Unmarshaler = &DeliveryRule{} + +func (s *DeliveryRule) UnmarshalJSON(bytes []byte) error { + type alias DeliveryRule + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DeliveryRule: %+v", err) + } + + s.Name = decoded.Name + s.Order = decoded.Order + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DeliveryRule into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["actions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Actions into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryRuleAction, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryRuleActionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Actions' for 'DeliveryRule': %+v", i, err) + } + output = append(output, impl) + } + s.Actions = output + } + + if v, ok := temp["conditions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Conditions into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryRuleCondition, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryRuleConditionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Conditions' for 'DeliveryRule': %+v", i, err) + } + output = append(output, impl) + } + s.Conditions = &output + } + return nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleaction.go new file mode 100644 index 00000000000..25f771969a3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleaction.go @@ -0,0 +1,117 @@ +package endpoints + +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 DeliveryRuleAction interface { +} + +// RawDeliveryRuleActionImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleActionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleActionImplementation(input []byte) (DeliveryRuleAction, 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 DeliveryRuleAction into map[string]interface: %+v", err) + } + + value, ok := temp["name"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "CacheExpiration") { + var out DeliveryRuleCacheExpirationAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleCacheExpirationAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "CacheKeyQueryString") { + var out DeliveryRuleCacheKeyQueryStringAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ModifyRequestHeader") { + var out DeliveryRuleRequestHeaderAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestHeaderAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ModifyResponseHeader") { + var out DeliveryRuleResponseHeaderAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleResponseHeaderAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RouteConfigurationOverride") { + var out DeliveryRuleRouteConfigurationOverrideAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "OriginGroupOverride") { + var out OriginGroupOverrideAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into OriginGroupOverrideAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlRedirect") { + var out UrlRedirectAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRedirectAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlRewrite") { + var out UrlRewriteAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRewriteAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlSigning") { + var out UrlSigningAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlSigningAction: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleActionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleactionparameters.go new file mode 100644 index 00000000000..69f84b520ea --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleactionparameters.go @@ -0,0 +1,109 @@ +package endpoints + +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 DeliveryRuleActionParameters interface { +} + +// RawDeliveryRuleActionParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleActionParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleActionParametersImplementation(input []byte) (DeliveryRuleActionParameters, 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 DeliveryRuleActionParameters into map[string]interface: %+v", err) + } + + value, ok := temp["typeName"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "DeliveryRuleCacheExpirationActionParameters") { + var out CacheExpirationActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CacheExpirationActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleCacheKeyQueryStringBehaviorActionParameters") { + var out CacheKeyQueryStringActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CacheKeyQueryStringActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleHeaderActionParameters") { + var out HeaderActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HeaderActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleOriginGroupOverrideActionParameters") { + var out OriginGroupOverrideActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into OriginGroupOverrideActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRouteConfigurationOverrideActionParameters") { + var out RouteConfigurationOverrideActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RouteConfigurationOverrideActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlRedirectActionParameters") { + var out UrlRedirectActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRedirectActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlRewriteActionParameters") { + var out UrlRewriteActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRewriteActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlSigningActionParameters") { + var out UrlSigningActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlSigningActionParameters: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleActionParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecacheexpirationaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecacheexpirationaction.go new file mode 100644 index 00000000000..e3a39737968 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecacheexpirationaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleCacheExpirationAction{} + +type DeliveryRuleCacheExpirationAction struct { + Parameters CacheExpirationActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleCacheExpirationAction{} + +func (s DeliveryRuleCacheExpirationAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleCacheExpirationAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleCacheExpirationAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleCacheExpirationAction: %+v", err) + } + decoded["name"] = "CacheExpiration" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleCacheExpirationAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecachekeyquerystringaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecachekeyquerystringaction.go new file mode 100644 index 00000000000..f428ec70439 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecachekeyquerystringaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleCacheKeyQueryStringAction{} + +type DeliveryRuleCacheKeyQueryStringAction struct { + Parameters CacheKeyQueryStringActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleCacheKeyQueryStringAction{} + +func (s DeliveryRuleCacheKeyQueryStringAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleCacheKeyQueryStringAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + decoded["name"] = "CacheKeyQueryString" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleclientportcondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleclientportcondition.go new file mode 100644 index 00000000000..1f0d3904128 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleclientportcondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleClientPortCondition{} + +type DeliveryRuleClientPortCondition struct { + Parameters ClientPortMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleClientPortCondition{} + +func (s DeliveryRuleClientPortCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleClientPortCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleClientPortCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleClientPortCondition: %+v", err) + } + decoded["name"] = "ClientPort" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleClientPortCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecondition.go new file mode 100644 index 00000000000..f49d3ad2ad3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecondition.go @@ -0,0 +1,197 @@ +package endpoints + +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 DeliveryRuleCondition interface { +} + +// RawDeliveryRuleConditionImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleConditionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleConditionImplementation(input []byte) (DeliveryRuleCondition, 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 DeliveryRuleCondition into map[string]interface: %+v", err) + } + + value, ok := temp["name"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ClientPort") { + var out DeliveryRuleClientPortCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleClientPortCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Cookies") { + var out DeliveryRuleCookiesCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleCookiesCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HttpVersion") { + var out DeliveryRuleHTTPVersionCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleHTTPVersionCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HostName") { + var out DeliveryRuleHostNameCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleHostNameCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IsDevice") { + var out DeliveryRuleIsDeviceCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleIsDeviceCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "PostArgs") { + var out DeliveryRulePostArgsCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRulePostArgsCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "QueryString") { + var out DeliveryRuleQueryStringCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleQueryStringCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RemoteAddress") { + var out DeliveryRuleRemoteAddressCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRemoteAddressCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestBody") { + var out DeliveryRuleRequestBodyCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestBodyCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestHeader") { + var out DeliveryRuleRequestHeaderCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestHeaderCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestMethod") { + var out DeliveryRuleRequestMethodCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestMethodCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestScheme") { + var out DeliveryRuleRequestSchemeCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestSchemeCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestUri") { + var out DeliveryRuleRequestUriCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestUriCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ServerPort") { + var out DeliveryRuleServerPortCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleServerPortCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SocketAddr") { + var out DeliveryRuleSocketAddrCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleSocketAddrCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SslProtocol") { + var out DeliveryRuleSslProtocolCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleSslProtocolCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlFileExtension") { + var out DeliveryRuleUrlFileExtensionCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlFileName") { + var out DeliveryRuleUrlFileNameCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleUrlFileNameCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlPath") { + var out DeliveryRuleUrlPathCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleUrlPathCondition: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleConditionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleconditionparameters.go new file mode 100644 index 00000000000..6c959ee454c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleconditionparameters.go @@ -0,0 +1,197 @@ +package endpoints + +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 DeliveryRuleConditionParameters interface { +} + +// RawDeliveryRuleConditionParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleConditionParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleConditionParametersImplementation(input []byte) (DeliveryRuleConditionParameters, 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 DeliveryRuleConditionParameters into map[string]interface: %+v", err) + } + + value, ok := temp["typeName"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "DeliveryRuleClientPortConditionParameters") { + var out ClientPortMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ClientPortMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleCookiesConditionParameters") { + var out CookiesMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CookiesMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleHttpVersionConditionParameters") { + var out HTTPVersionMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HTTPVersionMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleHostNameConditionParameters") { + var out HostNameMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HostNameMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleIsDeviceConditionParameters") { + var out IsDeviceMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IsDeviceMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRulePostArgsConditionParameters") { + var out PostArgsMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PostArgsMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleQueryStringConditionParameters") { + var out QueryStringMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into QueryStringMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRemoteAddressConditionParameters") { + var out RemoteAddressMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RemoteAddressMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestBodyConditionParameters") { + var out RequestBodyMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestBodyMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestHeaderConditionParameters") { + var out RequestHeaderMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestHeaderMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestMethodConditionParameters") { + var out RequestMethodMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestMethodMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestSchemeConditionParameters") { + var out RequestSchemeMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestSchemeMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestUriConditionParameters") { + var out RequestUriMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestUriMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleServerPortConditionParameters") { + var out ServerPortMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ServerPortMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleSocketAddrConditionParameters") { + var out SocketAddrMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SocketAddrMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleSslProtocolConditionParameters") { + var out SslProtocolMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SslProtocolMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlFileExtensionMatchConditionParameters") { + var out UrlFileExtensionMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlFileExtensionMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlFilenameConditionParameters") { + var out UrlFileNameMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlFileNameMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlPathMatchConditionParameters") { + var out UrlPathMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlPathMatchConditionParameters: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleConditionParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecookiescondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecookiescondition.go new file mode 100644 index 00000000000..80b2e9919ec --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulecookiescondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleCookiesCondition{} + +type DeliveryRuleCookiesCondition struct { + Parameters CookiesMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleCookiesCondition{} + +func (s DeliveryRuleCookiesCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleCookiesCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleCookiesCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleCookiesCondition: %+v", err) + } + decoded["name"] = "Cookies" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleCookiesCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulehostnamecondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulehostnamecondition.go new file mode 100644 index 00000000000..9865c1a12e3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulehostnamecondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleHostNameCondition{} + +type DeliveryRuleHostNameCondition struct { + Parameters HostNameMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleHostNameCondition{} + +func (s DeliveryRuleHostNameCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleHostNameCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleHostNameCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleHostNameCondition: %+v", err) + } + decoded["name"] = "HostName" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleHostNameCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulehttpversioncondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulehttpversioncondition.go new file mode 100644 index 00000000000..cb76c00fba5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulehttpversioncondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleHTTPVersionCondition{} + +type DeliveryRuleHTTPVersionCondition struct { + Parameters HTTPVersionMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleHTTPVersionCondition{} + +func (s DeliveryRuleHTTPVersionCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleHTTPVersionCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleHTTPVersionCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleHTTPVersionCondition: %+v", err) + } + decoded["name"] = "HttpVersion" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleHTTPVersionCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleisdevicecondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleisdevicecondition.go new file mode 100644 index 00000000000..e6d64fb7592 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleisdevicecondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleIsDeviceCondition{} + +type DeliveryRuleIsDeviceCondition struct { + Parameters IsDeviceMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleIsDeviceCondition{} + +func (s DeliveryRuleIsDeviceCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleIsDeviceCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleIsDeviceCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleIsDeviceCondition: %+v", err) + } + decoded["name"] = "IsDevice" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleIsDeviceCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulepostargscondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulepostargscondition.go new file mode 100644 index 00000000000..39db484d210 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulepostargscondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRulePostArgsCondition{} + +type DeliveryRulePostArgsCondition struct { + Parameters PostArgsMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRulePostArgsCondition{} + +func (s DeliveryRulePostArgsCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRulePostArgsCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRulePostArgsCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRulePostArgsCondition: %+v", err) + } + decoded["name"] = "PostArgs" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRulePostArgsCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulequerystringcondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulequerystringcondition.go new file mode 100644 index 00000000000..d1d8dfe3e1e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulequerystringcondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleQueryStringCondition{} + +type DeliveryRuleQueryStringCondition struct { + Parameters QueryStringMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleQueryStringCondition{} + +func (s DeliveryRuleQueryStringCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleQueryStringCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleQueryStringCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleQueryStringCondition: %+v", err) + } + decoded["name"] = "QueryString" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleQueryStringCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleremoteaddresscondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleremoteaddresscondition.go new file mode 100644 index 00000000000..6c4078d3e78 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleremoteaddresscondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRemoteAddressCondition{} + +type DeliveryRuleRemoteAddressCondition struct { + Parameters RemoteAddressMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRemoteAddressCondition{} + +func (s DeliveryRuleRemoteAddressCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRemoteAddressCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRemoteAddressCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRemoteAddressCondition: %+v", err) + } + decoded["name"] = "RemoteAddress" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRemoteAddressCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestbodycondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestbodycondition.go new file mode 100644 index 00000000000..e265dcf81fc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestbodycondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestBodyCondition{} + +type DeliveryRuleRequestBodyCondition struct { + Parameters RequestBodyMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestBodyCondition{} + +func (s DeliveryRuleRequestBodyCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestBodyCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestBodyCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestBodyCondition: %+v", err) + } + decoded["name"] = "RequestBody" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestBodyCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestheaderaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestheaderaction.go new file mode 100644 index 00000000000..28426c6b1ca --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestheaderaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleRequestHeaderAction{} + +type DeliveryRuleRequestHeaderAction struct { + Parameters HeaderActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleRequestHeaderAction{} + +func (s DeliveryRuleRequestHeaderAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestHeaderAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestHeaderAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestHeaderAction: %+v", err) + } + decoded["name"] = "ModifyRequestHeader" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestHeaderAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestheadercondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestheadercondition.go new file mode 100644 index 00000000000..8b79a3d89d9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestheadercondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestHeaderCondition{} + +type DeliveryRuleRequestHeaderCondition struct { + Parameters RequestHeaderMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestHeaderCondition{} + +func (s DeliveryRuleRequestHeaderCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestHeaderCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestHeaderCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestHeaderCondition: %+v", err) + } + decoded["name"] = "RequestHeader" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestHeaderCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestmethodcondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestmethodcondition.go new file mode 100644 index 00000000000..9cdb2fc4e86 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestmethodcondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestMethodCondition{} + +type DeliveryRuleRequestMethodCondition struct { + Parameters RequestMethodMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestMethodCondition{} + +func (s DeliveryRuleRequestMethodCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestMethodCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestMethodCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestMethodCondition: %+v", err) + } + decoded["name"] = "RequestMethod" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestMethodCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestschemecondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestschemecondition.go new file mode 100644 index 00000000000..e6772530b38 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequestschemecondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestSchemeCondition{} + +type DeliveryRuleRequestSchemeCondition struct { + Parameters RequestSchemeMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestSchemeCondition{} + +func (s DeliveryRuleRequestSchemeCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestSchemeCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestSchemeCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestSchemeCondition: %+v", err) + } + decoded["name"] = "RequestScheme" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestSchemeCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequesturicondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequesturicondition.go new file mode 100644 index 00000000000..9c8ce3a3324 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerequesturicondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestUriCondition{} + +type DeliveryRuleRequestUriCondition struct { + Parameters RequestUriMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestUriCondition{} + +func (s DeliveryRuleRequestUriCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestUriCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestUriCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestUriCondition: %+v", err) + } + decoded["name"] = "RequestUri" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestUriCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleresponseheaderaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleresponseheaderaction.go new file mode 100644 index 00000000000..61f368cb146 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleresponseheaderaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleResponseHeaderAction{} + +type DeliveryRuleResponseHeaderAction struct { + Parameters HeaderActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleResponseHeaderAction{} + +func (s DeliveryRuleResponseHeaderAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleResponseHeaderAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleResponseHeaderAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleResponseHeaderAction: %+v", err) + } + decoded["name"] = "ModifyResponseHeader" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleResponseHeaderAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerouteconfigurationoverrideaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerouteconfigurationoverrideaction.go new file mode 100644 index 00000000000..4233ed32dd5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulerouteconfigurationoverrideaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleRouteConfigurationOverrideAction{} + +type DeliveryRuleRouteConfigurationOverrideAction struct { + Parameters RouteConfigurationOverrideActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleRouteConfigurationOverrideAction{} + +func (s DeliveryRuleRouteConfigurationOverrideAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRouteConfigurationOverrideAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + decoded["name"] = "RouteConfigurationOverride" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleserverportcondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleserverportcondition.go new file mode 100644 index 00000000000..88846937b53 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleserverportcondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleServerPortCondition{} + +type DeliveryRuleServerPortCondition struct { + Parameters ServerPortMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleServerPortCondition{} + +func (s DeliveryRuleServerPortCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleServerPortCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleServerPortCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleServerPortCondition: %+v", err) + } + decoded["name"] = "ServerPort" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleServerPortCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulesocketaddrcondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulesocketaddrcondition.go new file mode 100644 index 00000000000..b3637fa1433 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulesocketaddrcondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleSocketAddrCondition{} + +type DeliveryRuleSocketAddrCondition struct { + Parameters SocketAddrMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleSocketAddrCondition{} + +func (s DeliveryRuleSocketAddrCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleSocketAddrCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleSocketAddrCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleSocketAddrCondition: %+v", err) + } + decoded["name"] = "SocketAddr" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleSocketAddrCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulesslprotocolcondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulesslprotocolcondition.go new file mode 100644 index 00000000000..5398e0c13fe --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryrulesslprotocolcondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleSslProtocolCondition{} + +type DeliveryRuleSslProtocolCondition struct { + Parameters SslProtocolMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleSslProtocolCondition{} + +func (s DeliveryRuleSslProtocolCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleSslProtocolCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleSslProtocolCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleSslProtocolCondition: %+v", err) + } + decoded["name"] = "SslProtocol" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleSslProtocolCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlfileextensioncondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlfileextensioncondition.go new file mode 100644 index 00000000000..1b66144f9ed --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlfileextensioncondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleUrlFileExtensionCondition{} + +type DeliveryRuleUrlFileExtensionCondition struct { + Parameters UrlFileExtensionMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleUrlFileExtensionCondition{} + +func (s DeliveryRuleUrlFileExtensionCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleUrlFileExtensionCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + decoded["name"] = "UrlFileExtension" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlfilenamecondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlfilenamecondition.go new file mode 100644 index 00000000000..3d25a8b60c2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlfilenamecondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleUrlFileNameCondition{} + +type DeliveryRuleUrlFileNameCondition struct { + Parameters UrlFileNameMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleUrlFileNameCondition{} + +func (s DeliveryRuleUrlFileNameCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleUrlFileNameCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleUrlFileNameCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleUrlFileNameCondition: %+v", err) + } + decoded["name"] = "UrlFileName" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleUrlFileNameCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlpathcondition.go b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlpathcondition.go new file mode 100644 index 00000000000..93a542a2de3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_deliveryruleurlpathcondition.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleUrlPathCondition{} + +type DeliveryRuleUrlPathCondition struct { + Parameters UrlPathMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleUrlPathCondition{} + +func (s DeliveryRuleUrlPathCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleUrlPathCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleUrlPathCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleUrlPathCondition: %+v", err) + } + decoded["name"] = "UrlPath" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleUrlPathCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_endpoint.go b/resource-manager/cdn/2024-02-01/endpoints/model_endpoint.go new file mode 100644 index 00000000000..1367b86ec12 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_endpoint.go @@ -0,0 +1,18 @@ +package endpoints + +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 Endpoint struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *EndpointProperties `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/cdn/2024-02-01/endpoints/model_endpointproperties.go b/resource-manager/cdn/2024-02-01/endpoints/model_endpointproperties.go new file mode 100644 index 00000000000..6ee490e4fca --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_endpointproperties.go @@ -0,0 +1,27 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointProperties struct { + ContentTypesToCompress *[]string `json:"contentTypesToCompress,omitempty"` + CustomDomains *[]DeepCreatedCustomDomain `json:"customDomains,omitempty"` + DefaultOriginGroup *ResourceReference `json:"defaultOriginGroup,omitempty"` + DeliveryPolicy *EndpointPropertiesUpdateParametersDeliveryPolicy `json:"deliveryPolicy,omitempty"` + GeoFilters *[]GeoFilter `json:"geoFilters,omitempty"` + HostName *string `json:"hostName,omitempty"` + IsCompressionEnabled *bool `json:"isCompressionEnabled,omitempty"` + IsHTTPAllowed *bool `json:"isHttpAllowed,omitempty"` + IsHTTPSAllowed *bool `json:"isHttpsAllowed,omitempty"` + OptimizationType *OptimizationType `json:"optimizationType,omitempty"` + OriginGroups *[]DeepCreatedOriginGroup `json:"originGroups,omitempty"` + OriginHostHeader *string `json:"originHostHeader,omitempty"` + OriginPath *string `json:"originPath,omitempty"` + Origins []DeepCreatedOrigin `json:"origins"` + ProbePath *string `json:"probePath,omitempty"` + ProvisioningState *EndpointProvisioningState `json:"provisioningState,omitempty"` + QueryStringCachingBehavior *QueryStringCachingBehavior `json:"queryStringCachingBehavior,omitempty"` + ResourceState *EndpointResourceState `json:"resourceState,omitempty"` + UrlSigningKeys *[]UrlSigningKey `json:"urlSigningKeys,omitempty"` + WebApplicationFirewallPolicyLink *EndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink `json:"webApplicationFirewallPolicyLink,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparameters.go new file mode 100644 index 00000000000..c35794d9388 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparameters.go @@ -0,0 +1,21 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointPropertiesUpdateParameters struct { + ContentTypesToCompress *[]string `json:"contentTypesToCompress,omitempty"` + DefaultOriginGroup *ResourceReference `json:"defaultOriginGroup,omitempty"` + DeliveryPolicy *EndpointPropertiesUpdateParametersDeliveryPolicy `json:"deliveryPolicy,omitempty"` + GeoFilters *[]GeoFilter `json:"geoFilters,omitempty"` + IsCompressionEnabled *bool `json:"isCompressionEnabled,omitempty"` + IsHTTPAllowed *bool `json:"isHttpAllowed,omitempty"` + IsHTTPSAllowed *bool `json:"isHttpsAllowed,omitempty"` + OptimizationType *OptimizationType `json:"optimizationType,omitempty"` + OriginHostHeader *string `json:"originHostHeader,omitempty"` + OriginPath *string `json:"originPath,omitempty"` + ProbePath *string `json:"probePath,omitempty"` + QueryStringCachingBehavior *QueryStringCachingBehavior `json:"queryStringCachingBehavior,omitempty"` + UrlSigningKeys *[]UrlSigningKey `json:"urlSigningKeys,omitempty"` + WebApplicationFirewallPolicyLink *EndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink `json:"webApplicationFirewallPolicyLink,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparametersdeliverypolicy.go b/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparametersdeliverypolicy.go new file mode 100644 index 00000000000..fc16bce3fc3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparametersdeliverypolicy.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointPropertiesUpdateParametersDeliveryPolicy struct { + Description *string `json:"description,omitempty"` + Rules []DeliveryRule `json:"rules"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparameterswebapplicationfirewallpolicylink.go b/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparameterswebapplicationfirewallpolicylink.go new file mode 100644 index 00000000000..334f027af8d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_endpointpropertiesupdateparameterswebapplicationfirewallpolicylink.go @@ -0,0 +1,8 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_endpointupdateparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_endpointupdateparameters.go new file mode 100644 index 00000000000..8e59a3fc5f8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_endpointupdateparameters.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointUpdateParameters struct { + Properties *EndpointPropertiesUpdateParameters `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_geofilter.go b/resource-manager/cdn/2024-02-01/endpoints/model_geofilter.go new file mode 100644 index 00000000000..245420ec643 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_geofilter.go @@ -0,0 +1,10 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoFilter struct { + Action GeoFilterActions `json:"action"` + CountryCodes []string `json:"countryCodes"` + RelativePath string `json:"relativePath"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_headeractionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_headeractionparameters.go new file mode 100644 index 00000000000..27750c8ea58 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_headeractionparameters.go @@ -0,0 +1,43 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = HeaderActionParameters{} + +type HeaderActionParameters struct { + HeaderAction HeaderAction `json:"headerAction"` + HeaderName string `json:"headerName"` + Value *string `json:"value,omitempty"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = HeaderActionParameters{} + +func (s HeaderActionParameters) MarshalJSON() ([]byte, error) { + type wrapper HeaderActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HeaderActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HeaderActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleHeaderActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HeaderActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_healthprobeparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_healthprobeparameters.go new file mode 100644 index 00000000000..f7491e35f6a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_healthprobeparameters.go @@ -0,0 +1,11 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthProbeParameters struct { + ProbeIntervalInSeconds *int64 `json:"probeIntervalInSeconds,omitempty"` + ProbePath *string `json:"probePath,omitempty"` + ProbeProtocol *ProbeProtocol `json:"probeProtocol,omitempty"` + ProbeRequestType *HealthProbeRequestType `json:"probeRequestType,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_hostnamematchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_hostnamematchconditionparameters.go new file mode 100644 index 00000000000..0b1f2c93eb2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_hostnamematchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = HostNameMatchConditionParameters{} + +type HostNameMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator HostNameOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = HostNameMatchConditionParameters{} + +func (s HostNameMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper HostNameMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HostNameMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HostNameMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleHostNameConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HostNameMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_httperrorrangeparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_httperrorrangeparameters.go new file mode 100644 index 00000000000..7ee3f694daa --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_httperrorrangeparameters.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPErrorRangeParameters struct { + Begin *int64 `json:"begin,omitempty"` + End *int64 `json:"end,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_httpversionmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_httpversionmatchconditionparameters.go new file mode 100644 index 00000000000..d949fdf7e65 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_httpversionmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = HTTPVersionMatchConditionParameters{} + +type HTTPVersionMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator HTTPVersionOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = HTTPVersionMatchConditionParameters{} + +func (s HTTPVersionMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper HTTPVersionMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HTTPVersionMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HTTPVersionMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleHttpVersionConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HTTPVersionMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_isdevicematchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_isdevicematchconditionparameters.go new file mode 100644 index 00000000000..38891244922 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_isdevicematchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = IsDeviceMatchConditionParameters{} + +type IsDeviceMatchConditionParameters struct { + MatchValues *[]IsDeviceMatchValue `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator IsDeviceOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = IsDeviceMatchConditionParameters{} + +func (s IsDeviceMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper IsDeviceMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IsDeviceMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IsDeviceMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleIsDeviceConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IsDeviceMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_keyvaultsigningkeyparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_keyvaultsigningkeyparameters.go new file mode 100644 index 00000000000..9c7b3e64eb1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_keyvaultsigningkeyparameters.go @@ -0,0 +1,13 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultSigningKeyParameters struct { + ResourceGroupName string `json:"resourceGroupName"` + SecretName string `json:"secretName"` + SecretVersion string `json:"secretVersion"` + SubscriptionId string `json:"subscriptionId"` + TypeName KeyVaultSigningKeyParametersType `json:"typeName"` + VaultName string `json:"vaultName"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_loadparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_loadparameters.go new file mode 100644 index 00000000000..4ba6766cb34 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_loadparameters.go @@ -0,0 +1,8 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoadParameters struct { + ContentPaths []string `json:"contentPaths"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverride.go b/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverride.go new file mode 100644 index 00000000000..e01336f6451 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverride.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginGroupOverride struct { + ForwardingProtocol *ForwardingProtocol `json:"forwardingProtocol,omitempty"` + OriginGroup *ResourceReference `json:"originGroup,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverrideaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverrideaction.go new file mode 100644 index 00000000000..2f44abbd861 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverrideaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = OriginGroupOverrideAction{} + +type OriginGroupOverrideAction struct { + Parameters OriginGroupOverrideActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = OriginGroupOverrideAction{} + +func (s OriginGroupOverrideAction) MarshalJSON() ([]byte, error) { + type wrapper OriginGroupOverrideAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling OriginGroupOverrideAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling OriginGroupOverrideAction: %+v", err) + } + decoded["name"] = "OriginGroupOverride" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling OriginGroupOverrideAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverrideactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverrideactionparameters.go new file mode 100644 index 00000000000..1f0180c5403 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_origingroupoverrideactionparameters.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = OriginGroupOverrideActionParameters{} + +type OriginGroupOverrideActionParameters struct { + OriginGroup ResourceReference `json:"originGroup"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = OriginGroupOverrideActionParameters{} + +func (s OriginGroupOverrideActionParameters) MarshalJSON() ([]byte, error) { + type wrapper OriginGroupOverrideActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling OriginGroupOverrideActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling OriginGroupOverrideActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleOriginGroupOverrideActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling OriginGroupOverrideActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_postargsmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_postargsmatchconditionparameters.go new file mode 100644 index 00000000000..e6e134ca339 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_postargsmatchconditionparameters.go @@ -0,0 +1,45 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = PostArgsMatchConditionParameters{} + +type PostArgsMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator PostArgsOperator `json:"operator"` + Selector *string `json:"selector,omitempty"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = PostArgsMatchConditionParameters{} + +func (s PostArgsMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper PostArgsMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PostArgsMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PostArgsMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRulePostArgsConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PostArgsMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_purgeparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_purgeparameters.go new file mode 100644 index 00000000000..7df637012d1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_purgeparameters.go @@ -0,0 +1,8 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurgeParameters struct { + ContentPaths []string `json:"contentPaths"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_querystringmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_querystringmatchconditionparameters.go new file mode 100644 index 00000000000..e604b41ccfa --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_querystringmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = QueryStringMatchConditionParameters{} + +type QueryStringMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator QueryStringOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = QueryStringMatchConditionParameters{} + +func (s QueryStringMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper QueryStringMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling QueryStringMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling QueryStringMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleQueryStringConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling QueryStringMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_remoteaddressmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_remoteaddressmatchconditionparameters.go new file mode 100644 index 00000000000..688d6637e5e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_remoteaddressmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RemoteAddressMatchConditionParameters{} + +type RemoteAddressMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RemoteAddressOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RemoteAddressMatchConditionParameters{} + +func (s RemoteAddressMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RemoteAddressMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RemoteAddressMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RemoteAddressMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRemoteAddressConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RemoteAddressMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_requestbodymatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_requestbodymatchconditionparameters.go new file mode 100644 index 00000000000..901dfb52a04 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_requestbodymatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestBodyMatchConditionParameters{} + +type RequestBodyMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestBodyOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestBodyMatchConditionParameters{} + +func (s RequestBodyMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestBodyMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestBodyMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestBodyMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestBodyConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestBodyMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_requestheadermatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_requestheadermatchconditionparameters.go new file mode 100644 index 00000000000..9cca72bbaa0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_requestheadermatchconditionparameters.go @@ -0,0 +1,45 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestHeaderMatchConditionParameters{} + +type RequestHeaderMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestHeaderOperator `json:"operator"` + Selector *string `json:"selector,omitempty"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestHeaderMatchConditionParameters{} + +func (s RequestHeaderMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestHeaderMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestHeaderMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestHeaderMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestHeaderConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestHeaderMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_requestmethodmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_requestmethodmatchconditionparameters.go new file mode 100644 index 00000000000..2fe208d05ea --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_requestmethodmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestMethodMatchConditionParameters{} + +type RequestMethodMatchConditionParameters struct { + MatchValues *[]RequestMethodMatchValue `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestMethodOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestMethodMatchConditionParameters{} + +func (s RequestMethodMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestMethodMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestMethodMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestMethodMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestMethodConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestMethodMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_requestschemematchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_requestschemematchconditionparameters.go new file mode 100644 index 00000000000..b49c2c1ba80 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_requestschemematchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestSchemeMatchConditionParameters{} + +type RequestSchemeMatchConditionParameters struct { + MatchValues *[]RequestSchemeMatchValue `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator Operator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestSchemeMatchConditionParameters{} + +func (s RequestSchemeMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestSchemeMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestSchemeMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestSchemeMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestSchemeConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestSchemeMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_requesturimatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_requesturimatchconditionparameters.go new file mode 100644 index 00000000000..ba8a8e3bf74 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_requesturimatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestUriMatchConditionParameters{} + +type RequestUriMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestUriOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestUriMatchConditionParameters{} + +func (s RequestUriMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestUriMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestUriMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestUriMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestUriConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestUriMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_resourcereference.go b/resource-manager/cdn/2024-02-01/endpoints/model_resourcereference.go new file mode 100644 index 00000000000..d2738a85404 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_resourcereference.go @@ -0,0 +1,8 @@ +package endpoints + +// 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/cdn/2024-02-01/endpoints/model_resourceusage.go b/resource-manager/cdn/2024-02-01/endpoints/model_resourceusage.go new file mode 100644 index 00000000000..e9ab54ffd5c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_resourceusage.go @@ -0,0 +1,11 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceUsage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Limit *int64 `json:"limit,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Unit *ResourceUsageUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_responsebasedoriginerrordetectionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_responsebasedoriginerrordetectionparameters.go new file mode 100644 index 00000000000..e9d37b8212f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_responsebasedoriginerrordetectionparameters.go @@ -0,0 +1,10 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResponseBasedOriginErrorDetectionParameters struct { + HTTPErrorRanges *[]HTTPErrorRangeParameters `json:"httpErrorRanges,omitempty"` + ResponseBasedDetectedErrorTypes *ResponseBasedDetectedErrorTypes `json:"responseBasedDetectedErrorTypes,omitempty"` + ResponseBasedFailoverThresholdPercentage *int64 `json:"responseBasedFailoverThresholdPercentage,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_routeconfigurationoverrideactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_routeconfigurationoverrideactionparameters.go new file mode 100644 index 00000000000..7a6722597fa --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_routeconfigurationoverrideactionparameters.go @@ -0,0 +1,42 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = RouteConfigurationOverrideActionParameters{} + +type RouteConfigurationOverrideActionParameters struct { + CacheConfiguration *CacheConfiguration `json:"cacheConfiguration,omitempty"` + OriginGroupOverride *OriginGroupOverride `json:"originGroupOverride,omitempty"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = RouteConfigurationOverrideActionParameters{} + +func (s RouteConfigurationOverrideActionParameters) MarshalJSON() ([]byte, error) { + type wrapper RouteConfigurationOverrideActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RouteConfigurationOverrideActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RouteConfigurationOverrideActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRouteConfigurationOverrideActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RouteConfigurationOverrideActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_serverportmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_serverportmatchconditionparameters.go new file mode 100644 index 00000000000..71940e1fa10 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_serverportmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = ServerPortMatchConditionParameters{} + +type ServerPortMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator ServerPortOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = ServerPortMatchConditionParameters{} + +func (s ServerPortMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper ServerPortMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ServerPortMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ServerPortMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleServerPortConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ServerPortMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_socketaddrmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_socketaddrmatchconditionparameters.go new file mode 100644 index 00000000000..2575a2d5e1f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_socketaddrmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = SocketAddrMatchConditionParameters{} + +type SocketAddrMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator SocketAddrOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = SocketAddrMatchConditionParameters{} + +func (s SocketAddrMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper SocketAddrMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SocketAddrMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SocketAddrMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleSocketAddrConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SocketAddrMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_sslprotocolmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_sslprotocolmatchconditionparameters.go new file mode 100644 index 00000000000..ca7f269db73 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_sslprotocolmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = SslProtocolMatchConditionParameters{} + +type SslProtocolMatchConditionParameters struct { + MatchValues *[]SslProtocol `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator SslProtocolOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = SslProtocolMatchConditionParameters{} + +func (s SslProtocolMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper SslProtocolMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SslProtocolMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SslProtocolMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleSslProtocolConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SslProtocolMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlfileextensionmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlfileextensionmatchconditionparameters.go new file mode 100644 index 00000000000..548d60a1fde --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlfileextensionmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = UrlFileExtensionMatchConditionParameters{} + +type UrlFileExtensionMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator UrlFileExtensionOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = UrlFileExtensionMatchConditionParameters{} + +func (s UrlFileExtensionMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlFileExtensionMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlFileExtensionMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlFileExtensionMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlFileExtensionMatchConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlFileExtensionMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlfilenamematchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlfilenamematchconditionparameters.go new file mode 100644 index 00000000000..2a642fffa2d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlfilenamematchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = UrlFileNameMatchConditionParameters{} + +type UrlFileNameMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator UrlFileNameOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = UrlFileNameMatchConditionParameters{} + +func (s UrlFileNameMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlFileNameMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlFileNameMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlFileNameMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlFilenameConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlFileNameMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlpathmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlpathmatchconditionparameters.go new file mode 100644 index 00000000000..ce0fd8fc664 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlpathmatchconditionparameters.go @@ -0,0 +1,44 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = UrlPathMatchConditionParameters{} + +type UrlPathMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator UrlPathOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = UrlPathMatchConditionParameters{} + +func (s UrlPathMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlPathMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlPathMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlPathMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlPathMatchConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlPathMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlredirectaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlredirectaction.go new file mode 100644 index 00000000000..a5db76a2a4e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlredirectaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = UrlRedirectAction{} + +type UrlRedirectAction struct { + Parameters UrlRedirectActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = UrlRedirectAction{} + +func (s UrlRedirectAction) MarshalJSON() ([]byte, error) { + type wrapper UrlRedirectAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRedirectAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRedirectAction: %+v", err) + } + decoded["name"] = "UrlRedirect" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRedirectAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlredirectactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlredirectactionparameters.go new file mode 100644 index 00000000000..10e68831fd4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlredirectactionparameters.go @@ -0,0 +1,46 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = UrlRedirectActionParameters{} + +type UrlRedirectActionParameters struct { + CustomFragment *string `json:"customFragment,omitempty"` + CustomHostname *string `json:"customHostname,omitempty"` + CustomPath *string `json:"customPath,omitempty"` + CustomQueryString *string `json:"customQueryString,omitempty"` + DestinationProtocol *DestinationProtocol `json:"destinationProtocol,omitempty"` + RedirectType RedirectType `json:"redirectType"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = UrlRedirectActionParameters{} + +func (s UrlRedirectActionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlRedirectActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRedirectActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRedirectActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlRedirectActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRedirectActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlrewriteaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlrewriteaction.go new file mode 100644 index 00000000000..3c36aa76d07 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlrewriteaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = UrlRewriteAction{} + +type UrlRewriteAction struct { + Parameters UrlRewriteActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = UrlRewriteAction{} + +func (s UrlRewriteAction) MarshalJSON() ([]byte, error) { + type wrapper UrlRewriteAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRewriteAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRewriteAction: %+v", err) + } + decoded["name"] = "UrlRewrite" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRewriteAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlrewriteactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlrewriteactionparameters.go new file mode 100644 index 00000000000..482c872d094 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlrewriteactionparameters.go @@ -0,0 +1,43 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = UrlRewriteActionParameters{} + +type UrlRewriteActionParameters struct { + Destination string `json:"destination"` + PreserveUnmatchedPath *bool `json:"preserveUnmatchedPath,omitempty"` + SourcePattern string `json:"sourcePattern"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = UrlRewriteActionParameters{} + +func (s UrlRewriteActionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlRewriteActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRewriteActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRewriteActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlRewriteActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRewriteActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningaction.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningaction.go new file mode 100644 index 00000000000..63d28cdaf67 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningaction.go @@ -0,0 +1,41 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = UrlSigningAction{} + +type UrlSigningAction struct { + Parameters UrlSigningActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = UrlSigningAction{} + +func (s UrlSigningAction) MarshalJSON() ([]byte, error) { + type wrapper UrlSigningAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlSigningAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlSigningAction: %+v", err) + } + decoded["name"] = "UrlSigning" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlSigningAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningactionparameters.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningactionparameters.go new file mode 100644 index 00000000000..80c7f8ba5bf --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningactionparameters.go @@ -0,0 +1,42 @@ +package endpoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = UrlSigningActionParameters{} + +type UrlSigningActionParameters struct { + Algorithm *Algorithm `json:"algorithm,omitempty"` + ParameterNameOverride *[]UrlSigningParamIdentifier `json:"parameterNameOverride,omitempty"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = UrlSigningActionParameters{} + +func (s UrlSigningActionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlSigningActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlSigningActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlSigningActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlSigningActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlSigningActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningkey.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningkey.go new file mode 100644 index 00000000000..9249776a493 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningkey.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UrlSigningKey struct { + KeyId string `json:"keyId"` + KeySourceParameters KeyVaultSigningKeyParameters `json:"keySourceParameters"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningparamidentifier.go b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningparamidentifier.go new file mode 100644 index 00000000000..a8bdab0f7a2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_urlsigningparamidentifier.go @@ -0,0 +1,9 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UrlSigningParamIdentifier struct { + ParamIndicator ParamIndicator `json:"paramIndicator"` + ParamName string `json:"paramName"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_validatecustomdomaininput.go b/resource-manager/cdn/2024-02-01/endpoints/model_validatecustomdomaininput.go new file mode 100644 index 00000000000..e143829b2e9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_validatecustomdomaininput.go @@ -0,0 +1,8 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateCustomDomainInput struct { + HostName string `json:"hostName"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/model_validatecustomdomainoutput.go b/resource-manager/cdn/2024-02-01/endpoints/model_validatecustomdomainoutput.go new file mode 100644 index 00000000000..ca152306143 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/model_validatecustomdomainoutput.go @@ -0,0 +1,10 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateCustomDomainOutput struct { + CustomDomainValidated *bool `json:"customDomainValidated,omitempty"` + Message *string `json:"message,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/predicates.go b/resource-manager/cdn/2024-02-01/endpoints/predicates.go new file mode 100644 index 00000000000..bb41ee6d27a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/predicates.go @@ -0,0 +1,55 @@ +package endpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p EndpointOperationPredicate) Matches(input Endpoint) 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 ResourceUsageOperationPredicate struct { + CurrentValue *int64 + Limit *int64 + ResourceType *string +} + +func (p ResourceUsageOperationPredicate) Matches(input ResourceUsage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + return true +} diff --git a/resource-manager/cdn/2024-02-01/endpoints/version.go b/resource-manager/cdn/2024-02-01/endpoints/version.go new file mode 100644 index 00000000000..6354ed27cb0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/endpoints/version.go @@ -0,0 +1,12 @@ +package endpoints + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/endpoints/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/README.md b/resource-manager/cdn/2024-02-01/loganalytics/README.md new file mode 100644 index 00000000000..e63d5de33cc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/README.md @@ -0,0 +1,84 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/loganalytics` Documentation + +The `loganalytics` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/loganalytics" +``` + + +### Client Initialization + +```go +client := loganalytics.NewLogAnalyticsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LogAnalyticsClient.GetLogAnalyticsLocations` + +```go +ctx := context.TODO() +id := loganalytics.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.GetLogAnalyticsLocations(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LogAnalyticsClient.GetLogAnalyticsMetrics` + +```go +ctx := context.TODO() +id := loganalytics.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.GetLogAnalyticsMetrics(ctx, id, loganalytics.DefaultGetLogAnalyticsMetricsOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LogAnalyticsClient.GetLogAnalyticsRankings` + +```go +ctx := context.TODO() +id := loganalytics.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.GetLogAnalyticsRankings(ctx, id, loganalytics.DefaultGetLogAnalyticsRankingsOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LogAnalyticsClient.GetLogAnalyticsResources` + +```go +ctx := context.TODO() +id := loganalytics.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.GetLogAnalyticsResources(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/cdn/2024-02-01/loganalytics/client.go b/resource-manager/cdn/2024-02-01/loganalytics/client.go new file mode 100644 index 00000000000..5053f2ddae1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/client.go @@ -0,0 +1,26 @@ +package loganalytics + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsClient struct { + Client *resourcemanager.Client +} + +func NewLogAnalyticsClientWithBaseURI(sdkApi sdkEnv.Api) (*LogAnalyticsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "loganalytics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LogAnalyticsClient: %+v", err) + } + + return &LogAnalyticsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/constants.go b/resource-manager/cdn/2024-02-01/loganalytics/constants.go new file mode 100644 index 00000000000..b6b4815c44d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/constants.go @@ -0,0 +1,145 @@ +package loganalytics + +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 LogMetricsGranularity string + +const ( + LogMetricsGranularityPOneD LogMetricsGranularity = "P1D" + LogMetricsGranularityPTFiveM LogMetricsGranularity = "PT5M" + LogMetricsGranularityPTOneH LogMetricsGranularity = "PT1H" +) + +func PossibleValuesForLogMetricsGranularity() []string { + return []string{ + string(LogMetricsGranularityPOneD), + string(LogMetricsGranularityPTFiveM), + string(LogMetricsGranularityPTOneH), + } +} + +func (s *LogMetricsGranularity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLogMetricsGranularity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLogMetricsGranularity(input string) (*LogMetricsGranularity, error) { + vals := map[string]LogMetricsGranularity{ + "p1d": LogMetricsGranularityPOneD, + "pt5m": LogMetricsGranularityPTFiveM, + "pt1h": LogMetricsGranularityPTOneH, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LogMetricsGranularity(input) + return &out, nil +} + +type MetricsGranularity string + +const ( + MetricsGranularityPOneD MetricsGranularity = "P1D" + MetricsGranularityPTFiveM MetricsGranularity = "PT5M" + MetricsGranularityPTOneH MetricsGranularity = "PT1H" +) + +func PossibleValuesForMetricsGranularity() []string { + return []string{ + string(MetricsGranularityPOneD), + string(MetricsGranularityPTFiveM), + string(MetricsGranularityPTOneH), + } +} + +func (s *MetricsGranularity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMetricsGranularity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMetricsGranularity(input string) (*MetricsGranularity, error) { + vals := map[string]MetricsGranularity{ + "p1d": MetricsGranularityPOneD, + "pt5m": MetricsGranularityPTFiveM, + "pt1h": MetricsGranularityPTOneH, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MetricsGranularity(input) + return &out, nil +} + +type MetricsSeriesUnit string + +const ( + MetricsSeriesUnitBitsPerSecond MetricsSeriesUnit = "bitsPerSecond" + MetricsSeriesUnitBytes MetricsSeriesUnit = "bytes" + MetricsSeriesUnitCount MetricsSeriesUnit = "count" + MetricsSeriesUnitMilliSeconds MetricsSeriesUnit = "milliSeconds" +) + +func PossibleValuesForMetricsSeriesUnit() []string { + return []string{ + string(MetricsSeriesUnitBitsPerSecond), + string(MetricsSeriesUnitBytes), + string(MetricsSeriesUnitCount), + string(MetricsSeriesUnitMilliSeconds), + } +} + +func (s *MetricsSeriesUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMetricsSeriesUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMetricsSeriesUnit(input string) (*MetricsSeriesUnit, error) { + vals := map[string]MetricsSeriesUnit{ + "bitspersecond": MetricsSeriesUnitBitsPerSecond, + "bytes": MetricsSeriesUnitBytes, + "count": MetricsSeriesUnitCount, + "milliseconds": MetricsSeriesUnitMilliSeconds, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MetricsSeriesUnit(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/id_profile.go b/resource-manager/cdn/2024-02-01/loganalytics/id_profile.go new file mode 100644 index 00000000000..872671fbfcf --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/id_profile.go @@ -0,0 +1,130 @@ +package loganalytics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/id_profile_test.go b/resource-manager/cdn/2024-02-01/loganalytics/id_profile_test.go new file mode 100644 index 00000000000..118207dc63f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/id_profile_test.go @@ -0,0 +1,282 @@ +package loganalytics + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/loganalytics/method_getloganalyticslocations.go b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticslocations.go new file mode 100644 index 00000000000..d22e4349b9d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticslocations.go @@ -0,0 +1,55 @@ +package loganalytics + +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 GetLogAnalyticsLocationsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ContinentsResponse +} + +// GetLogAnalyticsLocations ... +func (c LogAnalyticsClient) GetLogAnalyticsLocations(ctx context.Context, id ProfileId) (result GetLogAnalyticsLocationsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/getLogAnalyticsLocations", 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 + } + + var model ContinentsResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsmetrics.go b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsmetrics.go new file mode 100644 index 00000000000..656edb603c9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsmetrics.go @@ -0,0 +1,115 @@ +package loganalytics + +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 GetLogAnalyticsMetricsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetricsResponse +} + +type GetLogAnalyticsMetricsOperationOptions struct { + Continents *[]string + CountryOrRegions *[]string + CustomDomains *[]string + DateTimeBegin *string + DateTimeEnd *string + Granularity *LogMetricsGranularity + GroupBy *[]string + Metrics *[]string + Protocols *[]string +} + +func DefaultGetLogAnalyticsMetricsOperationOptions() GetLogAnalyticsMetricsOperationOptions { + return GetLogAnalyticsMetricsOperationOptions{} +} + +func (o GetLogAnalyticsMetricsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetLogAnalyticsMetricsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetLogAnalyticsMetricsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Continents != nil { + out.Append("continents", fmt.Sprintf("%v", *o.Continents)) + } + if o.CountryOrRegions != nil { + out.Append("countryOrRegions", fmt.Sprintf("%v", *o.CountryOrRegions)) + } + if o.CustomDomains != nil { + out.Append("customDomains", fmt.Sprintf("%v", *o.CustomDomains)) + } + if o.DateTimeBegin != nil { + out.Append("dateTimeBegin", fmt.Sprintf("%v", *o.DateTimeBegin)) + } + if o.DateTimeEnd != nil { + out.Append("dateTimeEnd", fmt.Sprintf("%v", *o.DateTimeEnd)) + } + if o.Granularity != nil { + out.Append("granularity", fmt.Sprintf("%v", *o.Granularity)) + } + if o.GroupBy != nil { + out.Append("groupBy", fmt.Sprintf("%v", *o.GroupBy)) + } + if o.Metrics != nil { + out.Append("metrics", fmt.Sprintf("%v", *o.Metrics)) + } + if o.Protocols != nil { + out.Append("protocols", fmt.Sprintf("%v", *o.Protocols)) + } + return &out +} + +// GetLogAnalyticsMetrics ... +func (c LogAnalyticsClient) GetLogAnalyticsMetrics(ctx context.Context, id ProfileId, options GetLogAnalyticsMetricsOperationOptions) (result GetLogAnalyticsMetricsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/getLogAnalyticsMetrics", 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 + } + + var model MetricsResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsrankings.go b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsrankings.go new file mode 100644 index 00000000000..14e605620b5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsrankings.go @@ -0,0 +1,103 @@ +package loganalytics + +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 GetLogAnalyticsRankingsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RankingsResponse +} + +type GetLogAnalyticsRankingsOperationOptions struct { + CustomDomains *[]string + DateTimeBegin *string + DateTimeEnd *string + MaxRanking *int64 + Metrics *[]string + Rankings *[]string +} + +func DefaultGetLogAnalyticsRankingsOperationOptions() GetLogAnalyticsRankingsOperationOptions { + return GetLogAnalyticsRankingsOperationOptions{} +} + +func (o GetLogAnalyticsRankingsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetLogAnalyticsRankingsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetLogAnalyticsRankingsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.CustomDomains != nil { + out.Append("customDomains", fmt.Sprintf("%v", *o.CustomDomains)) + } + if o.DateTimeBegin != nil { + out.Append("dateTimeBegin", fmt.Sprintf("%v", *o.DateTimeBegin)) + } + if o.DateTimeEnd != nil { + out.Append("dateTimeEnd", fmt.Sprintf("%v", *o.DateTimeEnd)) + } + if o.MaxRanking != nil { + out.Append("maxRanking", fmt.Sprintf("%v", *o.MaxRanking)) + } + if o.Metrics != nil { + out.Append("metrics", fmt.Sprintf("%v", *o.Metrics)) + } + if o.Rankings != nil { + out.Append("rankings", fmt.Sprintf("%v", *o.Rankings)) + } + return &out +} + +// GetLogAnalyticsRankings ... +func (c LogAnalyticsClient) GetLogAnalyticsRankings(ctx context.Context, id ProfileId, options GetLogAnalyticsRankingsOperationOptions) (result GetLogAnalyticsRankingsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/getLogAnalyticsRankings", 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 + } + + var model RankingsResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsresources.go b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsresources.go new file mode 100644 index 00000000000..197601b3bb3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/method_getloganalyticsresources.go @@ -0,0 +1,55 @@ +package loganalytics + +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 GetLogAnalyticsResourcesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourcesResponse +} + +// GetLogAnalyticsResources ... +func (c LogAnalyticsClient) GetLogAnalyticsResources(ctx context.Context, id ProfileId) (result GetLogAnalyticsResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/getLogAnalyticsResources", 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 + } + + var model ResourcesResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponse.go b/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponse.go new file mode 100644 index 00000000000..2769d4b2734 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponse.go @@ -0,0 +1,9 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContinentsResponse struct { + Continents *[]ContinentsResponseContinentsInlined `json:"continents,omitempty"` + CountryOrRegions *[]ContinentsResponseCountryOrRegionsInlined `json:"countryOrRegions,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponsecontinentsinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponsecontinentsinlined.go new file mode 100644 index 00000000000..78369bd519c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponsecontinentsinlined.go @@ -0,0 +1,8 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContinentsResponseContinentsInlined struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponsecountryorregionsinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponsecountryorregionsinlined.go new file mode 100644 index 00000000000..5fc2ba4521d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_continentsresponsecountryorregionsinlined.go @@ -0,0 +1,9 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContinentsResponseCountryOrRegionsInlined struct { + ContinentId *string `json:"continentId,omitempty"` + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponse.go b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponse.go new file mode 100644 index 00000000000..0bbcacac905 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponse.go @@ -0,0 +1,41 @@ +package loganalytics + +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 MetricsResponse struct { + DateTimeBegin *string `json:"dateTimeBegin,omitempty"` + DateTimeEnd *string `json:"dateTimeEnd,omitempty"` + Granularity *MetricsGranularity `json:"granularity,omitempty"` + Series *[]MetricsResponseSeriesInlined `json:"series,omitempty"` +} + +func (o *MetricsResponse) GetDateTimeBeginAsTime() (*time.Time, error) { + if o.DateTimeBegin == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeBegin, "2006-01-02T15:04:05Z07:00") +} + +func (o *MetricsResponse) SetDateTimeBeginAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeBegin = &formatted +} + +func (o *MetricsResponse) GetDateTimeEndAsTime() (*time.Time, error) { + if o.DateTimeEnd == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeEnd, "2006-01-02T15:04:05Z07:00") +} + +func (o *MetricsResponse) SetDateTimeEndAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeEnd = &formatted +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlined.go new file mode 100644 index 00000000000..2f151cc93d3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlined.go @@ -0,0 +1,11 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetricsResponseSeriesInlined struct { + Data *[]MetricsResponseSeriesInlinedDataInlined `json:"data,omitempty"` + Groups *[]MetricsResponseSeriesInlinedGroupsInlined `json:"groups,omitempty"` + Metric *string `json:"metric,omitempty"` + Unit *MetricsSeriesUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlineddatainlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlineddatainlined.go new file mode 100644 index 00000000000..7d848aecfce --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlineddatainlined.go @@ -0,0 +1,27 @@ +package loganalytics + +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 MetricsResponseSeriesInlinedDataInlined struct { + DateTime *string `json:"dateTime,omitempty"` + Value *float64 `json:"value,omitempty"` +} + +func (o *MetricsResponseSeriesInlinedDataInlined) GetDateTimeAsTime() (*time.Time, error) { + if o.DateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MetricsResponseSeriesInlinedDataInlined) SetDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTime = &formatted +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlinedgroupsinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlinedgroupsinlined.go new file mode 100644 index 00000000000..ffd5770e6f5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_metricsresponseseriesinlinedgroupsinlined.go @@ -0,0 +1,9 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetricsResponseSeriesInlinedGroupsInlined struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponse.go b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponse.go new file mode 100644 index 00000000000..c7d2cbd3a7e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponse.go @@ -0,0 +1,40 @@ +package loganalytics + +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 RankingsResponse struct { + DateTimeBegin *string `json:"dateTimeBegin,omitempty"` + DateTimeEnd *string `json:"dateTimeEnd,omitempty"` + Tables *[]RankingsResponseTablesInlined `json:"tables,omitempty"` +} + +func (o *RankingsResponse) GetDateTimeBeginAsTime() (*time.Time, error) { + if o.DateTimeBegin == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeBegin, "2006-01-02T15:04:05Z07:00") +} + +func (o *RankingsResponse) SetDateTimeBeginAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeBegin = &formatted +} + +func (o *RankingsResponse) GetDateTimeEndAsTime() (*time.Time, error) { + if o.DateTimeEnd == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeEnd, "2006-01-02T15:04:05Z07:00") +} + +func (o *RankingsResponse) SetDateTimeEndAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeEnd = &formatted +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlined.go new file mode 100644 index 00000000000..41b56e2085e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlined.go @@ -0,0 +1,9 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RankingsResponseTablesInlined struct { + Data *[]RankingsResponseTablesInlinedDataInlined `json:"data,omitempty"` + Ranking *string `json:"ranking,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlineddatainlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlineddatainlined.go new file mode 100644 index 00000000000..4cc5bfe9476 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlineddatainlined.go @@ -0,0 +1,9 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RankingsResponseTablesInlinedDataInlined struct { + Metrics *[]RankingsResponseTablesInlinedDataInlinedMetricsInlined `json:"metrics,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlineddatainlinedmetricsinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlineddatainlinedmetricsinlined.go new file mode 100644 index 00000000000..61a3412e580 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_rankingsresponsetablesinlineddatainlinedmetricsinlined.go @@ -0,0 +1,10 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RankingsResponseTablesInlinedDataInlinedMetricsInlined struct { + Metric *string `json:"metric,omitempty"` + Percentage *float64 `json:"percentage,omitempty"` + Value *int64 `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponse.go b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponse.go new file mode 100644 index 00000000000..3def33df803 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponse.go @@ -0,0 +1,9 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesResponse struct { + CustomDomains *[]ResourcesResponseCustomDomainsInlined `json:"customDomains,omitempty"` + Endpoints *[]ResourcesResponseEndpointsInlined `json:"endpoints,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponsecustomdomainsinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponsecustomdomainsinlined.go new file mode 100644 index 00000000000..1414be5266a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponsecustomdomainsinlined.go @@ -0,0 +1,11 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesResponseCustomDomainsInlined struct { + EndpointId *string `json:"endpointId,omitempty"` + History *bool `json:"history,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponseendpointsinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponseendpointsinlined.go new file mode 100644 index 00000000000..086302ac252 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponseendpointsinlined.go @@ -0,0 +1,11 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesResponseEndpointsInlined struct { + CustomDomains *[]ResourcesResponseEndpointsInlinedCustomDomainsInlined `json:"customDomains,omitempty"` + History *bool `json:"history,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponseendpointsinlinedcustomdomainsinlined.go b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponseendpointsinlinedcustomdomainsinlined.go new file mode 100644 index 00000000000..5b907cc5cf7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/model_resourcesresponseendpointsinlinedcustomdomainsinlined.go @@ -0,0 +1,11 @@ +package loganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesResponseEndpointsInlinedCustomDomainsInlined struct { + EndpointId *string `json:"endpointId,omitempty"` + History *bool `json:"history,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/loganalytics/version.go b/resource-manager/cdn/2024-02-01/loganalytics/version.go new file mode 100644 index 00000000000..ad01c41282d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/loganalytics/version.go @@ -0,0 +1,12 @@ +package loganalytics + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/loganalytics/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/README.md b/resource-manager/cdn/2024-02-01/origingroups/README.md new file mode 100644 index 00000000000..f569c20a82a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/origingroups` Documentation + +The `origingroups` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/origingroups" +``` + + +### Client Initialization + +```go +client := origingroups.NewOriginGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OriginGroupsClient.Create` + +```go +ctx := context.TODO() +id := origingroups.NewEndpointOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originGroupValue") + +payload := origingroups.OriginGroup{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `OriginGroupsClient.Delete` + +```go +ctx := context.TODO() +id := origingroups.NewEndpointOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originGroupValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `OriginGroupsClient.Get` + +```go +ctx := context.TODO() +id := origingroups.NewEndpointOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originGroupValue") + +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: `OriginGroupsClient.ListByEndpoint` + +```go +ctx := context.TODO() +id := origingroups.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +// alternatively `client.ListByEndpoint(ctx, id)` can be used to do batched pagination +items, err := client.ListByEndpointComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `OriginGroupsClient.Update` + +```go +ctx := context.TODO() +id := origingroups.NewEndpointOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originGroupValue") + +payload := origingroups.OriginGroupUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/origingroups/client.go b/resource-manager/cdn/2024-02-01/origingroups/client.go new file mode 100644 index 00000000000..00a8cd65506 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/client.go @@ -0,0 +1,26 @@ +package origingroups + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginGroupsClient struct { + Client *resourcemanager.Client +} + +func NewOriginGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*OriginGroupsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "origingroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OriginGroupsClient: %+v", err) + } + + return &OriginGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/constants.go b/resource-manager/cdn/2024-02-01/origingroups/constants.go new file mode 100644 index 00000000000..b7f9848fff3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/constants.go @@ -0,0 +1,236 @@ +package origingroups + +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 HealthProbeRequestType string + +const ( + HealthProbeRequestTypeGET HealthProbeRequestType = "GET" + HealthProbeRequestTypeHEAD HealthProbeRequestType = "HEAD" + HealthProbeRequestTypeNotSet HealthProbeRequestType = "NotSet" +) + +func PossibleValuesForHealthProbeRequestType() []string { + return []string{ + string(HealthProbeRequestTypeGET), + string(HealthProbeRequestTypeHEAD), + string(HealthProbeRequestTypeNotSet), + } +} + +func (s *HealthProbeRequestType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthProbeRequestType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthProbeRequestType(input string) (*HealthProbeRequestType, error) { + vals := map[string]HealthProbeRequestType{ + "get": HealthProbeRequestTypeGET, + "head": HealthProbeRequestTypeHEAD, + "notset": HealthProbeRequestTypeNotSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthProbeRequestType(input) + return &out, nil +} + +type OriginGroupProvisioningState string + +const ( + OriginGroupProvisioningStateCreating OriginGroupProvisioningState = "Creating" + OriginGroupProvisioningStateDeleting OriginGroupProvisioningState = "Deleting" + OriginGroupProvisioningStateFailed OriginGroupProvisioningState = "Failed" + OriginGroupProvisioningStateSucceeded OriginGroupProvisioningState = "Succeeded" + OriginGroupProvisioningStateUpdating OriginGroupProvisioningState = "Updating" +) + +func PossibleValuesForOriginGroupProvisioningState() []string { + return []string{ + string(OriginGroupProvisioningStateCreating), + string(OriginGroupProvisioningStateDeleting), + string(OriginGroupProvisioningStateFailed), + string(OriginGroupProvisioningStateSucceeded), + string(OriginGroupProvisioningStateUpdating), + } +} + +func (s *OriginGroupProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOriginGroupProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOriginGroupProvisioningState(input string) (*OriginGroupProvisioningState, error) { + vals := map[string]OriginGroupProvisioningState{ + "creating": OriginGroupProvisioningStateCreating, + "deleting": OriginGroupProvisioningStateDeleting, + "failed": OriginGroupProvisioningStateFailed, + "succeeded": OriginGroupProvisioningStateSucceeded, + "updating": OriginGroupProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OriginGroupProvisioningState(input) + return &out, nil +} + +type OriginGroupResourceState string + +const ( + OriginGroupResourceStateActive OriginGroupResourceState = "Active" + OriginGroupResourceStateCreating OriginGroupResourceState = "Creating" + OriginGroupResourceStateDeleting OriginGroupResourceState = "Deleting" +) + +func PossibleValuesForOriginGroupResourceState() []string { + return []string{ + string(OriginGroupResourceStateActive), + string(OriginGroupResourceStateCreating), + string(OriginGroupResourceStateDeleting), + } +} + +func (s *OriginGroupResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOriginGroupResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOriginGroupResourceState(input string) (*OriginGroupResourceState, error) { + vals := map[string]OriginGroupResourceState{ + "active": OriginGroupResourceStateActive, + "creating": OriginGroupResourceStateCreating, + "deleting": OriginGroupResourceStateDeleting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OriginGroupResourceState(input) + return &out, nil +} + +type ProbeProtocol string + +const ( + ProbeProtocolHTTP ProbeProtocol = "Http" + ProbeProtocolHTTPS ProbeProtocol = "Https" + ProbeProtocolNotSet ProbeProtocol = "NotSet" +) + +func PossibleValuesForProbeProtocol() []string { + return []string{ + string(ProbeProtocolHTTP), + string(ProbeProtocolHTTPS), + string(ProbeProtocolNotSet), + } +} + +func (s *ProbeProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProbeProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProbeProtocol(input string) (*ProbeProtocol, error) { + vals := map[string]ProbeProtocol{ + "http": ProbeProtocolHTTP, + "https": ProbeProtocolHTTPS, + "notset": ProbeProtocolNotSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProbeProtocol(input) + return &out, nil +} + +type ResponseBasedDetectedErrorTypes string + +const ( + ResponseBasedDetectedErrorTypesNone ResponseBasedDetectedErrorTypes = "None" + ResponseBasedDetectedErrorTypesTcpAndHTTPErrors ResponseBasedDetectedErrorTypes = "TcpAndHttpErrors" + ResponseBasedDetectedErrorTypesTcpErrorsOnly ResponseBasedDetectedErrorTypes = "TcpErrorsOnly" +) + +func PossibleValuesForResponseBasedDetectedErrorTypes() []string { + return []string{ + string(ResponseBasedDetectedErrorTypesNone), + string(ResponseBasedDetectedErrorTypesTcpAndHTTPErrors), + string(ResponseBasedDetectedErrorTypesTcpErrorsOnly), + } +} + +func (s *ResponseBasedDetectedErrorTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResponseBasedDetectedErrorTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResponseBasedDetectedErrorTypes(input string) (*ResponseBasedDetectedErrorTypes, error) { + vals := map[string]ResponseBasedDetectedErrorTypes{ + "none": ResponseBasedDetectedErrorTypesNone, + "tcpandhttperrors": ResponseBasedDetectedErrorTypesTcpAndHTTPErrors, + "tcperrorsonly": ResponseBasedDetectedErrorTypesTcpErrorsOnly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResponseBasedDetectedErrorTypes(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/id_endpoint.go b/resource-manager/cdn/2024-02-01/origingroups/id_endpoint.go new file mode 100644 index 00000000000..bea74c32e1e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/id_endpoint.go @@ -0,0 +1,139 @@ +package origingroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&EndpointId{}) +} + +var _ resourceids.ResourceId = &EndpointId{} + +// EndpointId is a struct representing the Resource ID for a Endpoint +type EndpointId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + EndpointName string +} + +// NewEndpointID returns a new EndpointId struct +func NewEndpointID(subscriptionId string, resourceGroupName string, profileName string, endpointName string) EndpointId { + return EndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + EndpointName: endpointName, + } +} + +// ParseEndpointID parses 'input' into a EndpointId +func ParseEndpointID(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEndpointIDInsensitively parses 'input' case-insensitively into a EndpointId +// note: this method should only be used for API response data and not user input +func ParseEndpointIDInsensitively(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.EndpointName, ok = input.Parsed["endpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointName", input) + } + + return nil +} + +// ValidateEndpointID checks that 'input' can be parsed as a Endpoint ID +func ValidateEndpointID(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 := ParseEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Endpoint ID +func (id EndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/endpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.EndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Endpoint ID +func (id EndpointId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticEndpoints", "endpoints", "endpoints"), + resourceids.UserSpecifiedSegment("endpointName", "endpointValue"), + } +} + +// String returns a human-readable description of this Endpoint ID +func (id EndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Endpoint Name: %q", id.EndpointName), + } + return fmt.Sprintf("Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/id_endpoint_test.go b/resource-manager/cdn/2024-02-01/origingroups/id_endpoint_test.go new file mode 100644 index 00000000000..2887bff0677 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/id_endpoint_test.go @@ -0,0 +1,327 @@ +package origingroups + +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 = &EndpointId{} + +func TestNewEndpointID(t *testing.T) { + id := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.EndpointName != "endpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointName'", id.EndpointName, "endpointValue") + } +} + +func TestFormatEndpointID(t *testing.T) { + actual := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestParseEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + EndpointName: "eNdPoInTvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestSegmentsForEndpointId(t *testing.T) { + segments := EndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EndpointId 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/cdn/2024-02-01/origingroups/id_endpointorigingroup.go b/resource-manager/cdn/2024-02-01/origingroups/id_endpointorigingroup.go new file mode 100644 index 00000000000..e6fd9c99199 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/id_endpointorigingroup.go @@ -0,0 +1,148 @@ +package origingroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&EndpointOriginGroupId{}) +} + +var _ resourceids.ResourceId = &EndpointOriginGroupId{} + +// EndpointOriginGroupId is a struct representing the Resource ID for a Endpoint Origin Group +type EndpointOriginGroupId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + EndpointName string + OriginGroupName string +} + +// NewEndpointOriginGroupID returns a new EndpointOriginGroupId struct +func NewEndpointOriginGroupID(subscriptionId string, resourceGroupName string, profileName string, endpointName string, originGroupName string) EndpointOriginGroupId { + return EndpointOriginGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + EndpointName: endpointName, + OriginGroupName: originGroupName, + } +} + +// ParseEndpointOriginGroupID parses 'input' into a EndpointOriginGroupId +func ParseEndpointOriginGroupID(input string) (*EndpointOriginGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointOriginGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointOriginGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEndpointOriginGroupIDInsensitively parses 'input' case-insensitively into a EndpointOriginGroupId +// note: this method should only be used for API response data and not user input +func ParseEndpointOriginGroupIDInsensitively(input string) (*EndpointOriginGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointOriginGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointOriginGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EndpointOriginGroupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.EndpointName, ok = input.Parsed["endpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointName", input) + } + + if id.OriginGroupName, ok = input.Parsed["originGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "originGroupName", input) + } + + return nil +} + +// ValidateEndpointOriginGroupID checks that 'input' can be parsed as a Endpoint Origin Group ID +func ValidateEndpointOriginGroupID(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 := ParseEndpointOriginGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Endpoint Origin Group ID +func (id EndpointOriginGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/endpoints/%s/originGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.EndpointName, id.OriginGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Endpoint Origin Group ID +func (id EndpointOriginGroupId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticEndpoints", "endpoints", "endpoints"), + resourceids.UserSpecifiedSegment("endpointName", "endpointValue"), + resourceids.StaticSegment("staticOriginGroups", "originGroups", "originGroups"), + resourceids.UserSpecifiedSegment("originGroupName", "originGroupValue"), + } +} + +// String returns a human-readable description of this Endpoint Origin Group ID +func (id EndpointOriginGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Endpoint Name: %q", id.EndpointName), + fmt.Sprintf("Origin Group Name: %q", id.OriginGroupName), + } + return fmt.Sprintf("Endpoint Origin Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/id_endpointorigingroup_test.go b/resource-manager/cdn/2024-02-01/origingroups/id_endpointorigingroup_test.go new file mode 100644 index 00000000000..7b15a4680c5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/id_endpointorigingroup_test.go @@ -0,0 +1,372 @@ +package origingroups + +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 = &EndpointOriginGroupId{} + +func TestNewEndpointOriginGroupID(t *testing.T) { + id := NewEndpointOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originGroupValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.EndpointName != "endpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointName'", id.EndpointName, "endpointValue") + } + + if id.OriginGroupName != "originGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'OriginGroupName'", id.OriginGroupName, "originGroupValue") + } +} + +func TestFormatEndpointOriginGroupID(t *testing.T) { + actual := NewEndpointOriginGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/originGroups/originGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEndpointOriginGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointOriginGroupId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/originGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/originGroups/originGroupValue", + Expected: &EndpointOriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + OriginGroupName: "originGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/originGroups/originGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointOriginGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + } +} + +func TestParseEndpointOriginGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointOriginGroupId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/originGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/oRiGiNgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/originGroups/originGroupValue", + Expected: &EndpointOriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + OriginGroupName: "originGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/originGroups/originGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE", + Expected: &EndpointOriginGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + EndpointName: "eNdPoInTvAlUe", + OriginGroupName: "oRiGiNgRoUpVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/oRiGiNgRoUpS/oRiGiNgRoUpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointOriginGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + if actual.OriginGroupName != v.Expected.OriginGroupName { + t.Fatalf("Expected %q but got %q for OriginGroupName", v.Expected.OriginGroupName, actual.OriginGroupName) + } + + } +} + +func TestSegmentsForEndpointOriginGroupId(t *testing.T) { + segments := EndpointOriginGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EndpointOriginGroupId 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/cdn/2024-02-01/origingroups/method_create.go b/resource-manager/cdn/2024-02-01/origingroups/method_create.go new file mode 100644 index 00000000000..db797b0f3e0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/method_create.go @@ -0,0 +1,76 @@ +package origingroups + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OriginGroup +} + +// Create ... +func (c OriginGroupsClient) Create(ctx context.Context, id EndpointOriginGroupId, input OriginGroup) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c OriginGroupsClient) CreateThenPoll(ctx context.Context, id EndpointOriginGroupId, input OriginGroup) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/method_delete.go b/resource-manager/cdn/2024-02-01/origingroups/method_delete.go new file mode 100644 index 00000000000..81cc0819cdc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/method_delete.go @@ -0,0 +1,71 @@ +package origingroups + +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 OriginGroupsClient) Delete(ctx context.Context, id EndpointOriginGroupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c OriginGroupsClient) DeleteThenPoll(ctx context.Context, id EndpointOriginGroupId) 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/cdn/2024-02-01/origingroups/method_get.go b/resource-manager/cdn/2024-02-01/origingroups/method_get.go new file mode 100644 index 00000000000..74deca9e343 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/method_get.go @@ -0,0 +1,54 @@ +package origingroups + +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 *OriginGroup +} + +// Get ... +func (c OriginGroupsClient) Get(ctx context.Context, id EndpointOriginGroupId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model OriginGroup + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/method_listbyendpoint.go b/resource-manager/cdn/2024-02-01/origingroups/method_listbyendpoint.go new file mode 100644 index 00000000000..fa1f3ae0b80 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/method_listbyendpoint.go @@ -0,0 +1,105 @@ +package origingroups + +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 ListByEndpointOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OriginGroup +} + +type ListByEndpointCompleteResult struct { + LatestHttpResponse *http.Response + Items []OriginGroup +} + +type ListByEndpointCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByEndpointCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByEndpoint ... +func (c OriginGroupsClient) ListByEndpoint(ctx context.Context, id EndpointId) (result ListByEndpointOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByEndpointCustomPager{}, + Path: fmt.Sprintf("%s/originGroups", 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 *[]OriginGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByEndpointComplete retrieves all the results into a single object +func (c OriginGroupsClient) ListByEndpointComplete(ctx context.Context, id EndpointId) (ListByEndpointCompleteResult, error) { + return c.ListByEndpointCompleteMatchingPredicate(ctx, id, OriginGroupOperationPredicate{}) +} + +// ListByEndpointCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OriginGroupsClient) ListByEndpointCompleteMatchingPredicate(ctx context.Context, id EndpointId, predicate OriginGroupOperationPredicate) (result ListByEndpointCompleteResult, err error) { + items := make([]OriginGroup, 0) + + resp, err := c.ListByEndpoint(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByEndpointCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/method_update.go b/resource-manager/cdn/2024-02-01/origingroups/method_update.go new file mode 100644 index 00000000000..b4051dee39a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/method_update.go @@ -0,0 +1,75 @@ +package origingroups + +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 + Model *OriginGroup +} + +// Update ... +func (c OriginGroupsClient) Update(ctx context.Context, id EndpointOriginGroupId, input OriginGroupUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c OriginGroupsClient) UpdateThenPoll(ctx context.Context, id EndpointOriginGroupId, input OriginGroupUpdateParameters) 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/cdn/2024-02-01/origingroups/model_healthprobeparameters.go b/resource-manager/cdn/2024-02-01/origingroups/model_healthprobeparameters.go new file mode 100644 index 00000000000..67018c3f6da --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_healthprobeparameters.go @@ -0,0 +1,11 @@ +package origingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthProbeParameters struct { + ProbeIntervalInSeconds *int64 `json:"probeIntervalInSeconds,omitempty"` + ProbePath *string `json:"probePath,omitempty"` + ProbeProtocol *ProbeProtocol `json:"probeProtocol,omitempty"` + ProbeRequestType *HealthProbeRequestType `json:"probeRequestType,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/model_httperrorrangeparameters.go b/resource-manager/cdn/2024-02-01/origingroups/model_httperrorrangeparameters.go new file mode 100644 index 00000000000..b6b3fe27f23 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_httperrorrangeparameters.go @@ -0,0 +1,9 @@ +package origingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPErrorRangeParameters struct { + Begin *int64 `json:"begin,omitempty"` + End *int64 `json:"end,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/model_origingroup.go b/resource-manager/cdn/2024-02-01/origingroups/model_origingroup.go new file mode 100644 index 00000000000..649ed9a3b6b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_origingroup.go @@ -0,0 +1,16 @@ +package origingroups + +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 OriginGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OriginGroupProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/model_origingroupproperties.go b/resource-manager/cdn/2024-02-01/origingroups/model_origingroupproperties.go new file mode 100644 index 00000000000..a407158a8d0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_origingroupproperties.go @@ -0,0 +1,13 @@ +package origingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginGroupProperties struct { + HealthProbeSettings *HealthProbeParameters `json:"healthProbeSettings,omitempty"` + Origins *[]ResourceReference `json:"origins,omitempty"` + ProvisioningState *OriginGroupProvisioningState `json:"provisioningState,omitempty"` + ResourceState *OriginGroupResourceState `json:"resourceState,omitempty"` + ResponseBasedOriginErrorDetectionSettings *ResponseBasedOriginErrorDetectionParameters `json:"responseBasedOriginErrorDetectionSettings,omitempty"` + TrafficRestorationTimeToHealedOrNewEndpointsInMinutes *int64 `json:"trafficRestorationTimeToHealedOrNewEndpointsInMinutes,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/model_origingroupupdateparameters.go b/resource-manager/cdn/2024-02-01/origingroups/model_origingroupupdateparameters.go new file mode 100644 index 00000000000..03f4cb09dc3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_origingroupupdateparameters.go @@ -0,0 +1,8 @@ +package origingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginGroupUpdateParameters struct { + Properties *OriginGroupUpdatePropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/model_origingroupupdatepropertiesparameters.go b/resource-manager/cdn/2024-02-01/origingroups/model_origingroupupdatepropertiesparameters.go new file mode 100644 index 00000000000..12ea2b4d7f5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_origingroupupdatepropertiesparameters.go @@ -0,0 +1,11 @@ +package origingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginGroupUpdatePropertiesParameters struct { + HealthProbeSettings *HealthProbeParameters `json:"healthProbeSettings,omitempty"` + Origins *[]ResourceReference `json:"origins,omitempty"` + ResponseBasedOriginErrorDetectionSettings *ResponseBasedOriginErrorDetectionParameters `json:"responseBasedOriginErrorDetectionSettings,omitempty"` + TrafficRestorationTimeToHealedOrNewEndpointsInMinutes *int64 `json:"trafficRestorationTimeToHealedOrNewEndpointsInMinutes,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/model_resourcereference.go b/resource-manager/cdn/2024-02-01/origingroups/model_resourcereference.go new file mode 100644 index 00000000000..67700c54e20 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_resourcereference.go @@ -0,0 +1,8 @@ +package origingroups + +// 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/cdn/2024-02-01/origingroups/model_responsebasedoriginerrordetectionparameters.go b/resource-manager/cdn/2024-02-01/origingroups/model_responsebasedoriginerrordetectionparameters.go new file mode 100644 index 00000000000..f6bdf7d8ced --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/model_responsebasedoriginerrordetectionparameters.go @@ -0,0 +1,10 @@ +package origingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResponseBasedOriginErrorDetectionParameters struct { + HTTPErrorRanges *[]HTTPErrorRangeParameters `json:"httpErrorRanges,omitempty"` + ResponseBasedDetectedErrorTypes *ResponseBasedDetectedErrorTypes `json:"responseBasedDetectedErrorTypes,omitempty"` + ResponseBasedFailoverThresholdPercentage *int64 `json:"responseBasedFailoverThresholdPercentage,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origingroups/predicates.go b/resource-manager/cdn/2024-02-01/origingroups/predicates.go new file mode 100644 index 00000000000..74bab74fc98 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/predicates.go @@ -0,0 +1,27 @@ +package origingroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p OriginGroupOperationPredicate) Matches(input OriginGroup) 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/cdn/2024-02-01/origingroups/version.go b/resource-manager/cdn/2024-02-01/origingroups/version.go new file mode 100644 index 00000000000..55ea5bc4f33 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origingroups/version.go @@ -0,0 +1,12 @@ +package origingroups + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/origingroups/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/origins/README.md b/resource-manager/cdn/2024-02-01/origins/README.md new file mode 100644 index 00000000000..47d8793bdf8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/origins` Documentation + +The `origins` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/origins" +``` + + +### Client Initialization + +```go +client := origins.NewOriginsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OriginsClient.Create` + +```go +ctx := context.TODO() +id := origins.NewOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originValue") + +payload := origins.Origin{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `OriginsClient.Delete` + +```go +ctx := context.TODO() +id := origins.NewOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `OriginsClient.Get` + +```go +ctx := context.TODO() +id := origins.NewOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originValue") + +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: `OriginsClient.ListByEndpoint` + +```go +ctx := context.TODO() +id := origins.NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + +// alternatively `client.ListByEndpoint(ctx, id)` can be used to do batched pagination +items, err := client.ListByEndpointComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `OriginsClient.Update` + +```go +ctx := context.TODO() +id := origins.NewOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originValue") + +payload := origins.OriginUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/origins/client.go b/resource-manager/cdn/2024-02-01/origins/client.go new file mode 100644 index 00000000000..0ca8f1f1cca --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/client.go @@ -0,0 +1,26 @@ +package origins + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginsClient struct { + Client *resourcemanager.Client +} + +func NewOriginsClientWithBaseURI(sdkApi sdkEnv.Api) (*OriginsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "origins", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OriginsClient: %+v", err) + } + + return &OriginsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/origins/constants.go b/resource-manager/cdn/2024-02-01/origins/constants.go new file mode 100644 index 00000000000..a04f9ed83bf --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/constants.go @@ -0,0 +1,154 @@ +package origins + +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 OriginProvisioningState string + +const ( + OriginProvisioningStateCreating OriginProvisioningState = "Creating" + OriginProvisioningStateDeleting OriginProvisioningState = "Deleting" + OriginProvisioningStateFailed OriginProvisioningState = "Failed" + OriginProvisioningStateSucceeded OriginProvisioningState = "Succeeded" + OriginProvisioningStateUpdating OriginProvisioningState = "Updating" +) + +func PossibleValuesForOriginProvisioningState() []string { + return []string{ + string(OriginProvisioningStateCreating), + string(OriginProvisioningStateDeleting), + string(OriginProvisioningStateFailed), + string(OriginProvisioningStateSucceeded), + string(OriginProvisioningStateUpdating), + } +} + +func (s *OriginProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOriginProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOriginProvisioningState(input string) (*OriginProvisioningState, error) { + vals := map[string]OriginProvisioningState{ + "creating": OriginProvisioningStateCreating, + "deleting": OriginProvisioningStateDeleting, + "failed": OriginProvisioningStateFailed, + "succeeded": OriginProvisioningStateSucceeded, + "updating": OriginProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OriginProvisioningState(input) + return &out, nil +} + +type OriginResourceState string + +const ( + OriginResourceStateActive OriginResourceState = "Active" + OriginResourceStateCreating OriginResourceState = "Creating" + OriginResourceStateDeleting OriginResourceState = "Deleting" +) + +func PossibleValuesForOriginResourceState() []string { + return []string{ + string(OriginResourceStateActive), + string(OriginResourceStateCreating), + string(OriginResourceStateDeleting), + } +} + +func (s *OriginResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOriginResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOriginResourceState(input string) (*OriginResourceState, error) { + vals := map[string]OriginResourceState{ + "active": OriginResourceStateActive, + "creating": OriginResourceStateCreating, + "deleting": OriginResourceStateDeleting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OriginResourceState(input) + return &out, nil +} + +type PrivateEndpointStatus string + +const ( + PrivateEndpointStatusApproved PrivateEndpointStatus = "Approved" + PrivateEndpointStatusDisconnected PrivateEndpointStatus = "Disconnected" + PrivateEndpointStatusPending PrivateEndpointStatus = "Pending" + PrivateEndpointStatusRejected PrivateEndpointStatus = "Rejected" + PrivateEndpointStatusTimeout PrivateEndpointStatus = "Timeout" +) + +func PossibleValuesForPrivateEndpointStatus() []string { + return []string{ + string(PrivateEndpointStatusApproved), + string(PrivateEndpointStatusDisconnected), + string(PrivateEndpointStatusPending), + string(PrivateEndpointStatusRejected), + string(PrivateEndpointStatusTimeout), + } +} + +func (s *PrivateEndpointStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointStatus(input string) (*PrivateEndpointStatus, error) { + vals := map[string]PrivateEndpointStatus{ + "approved": PrivateEndpointStatusApproved, + "disconnected": PrivateEndpointStatusDisconnected, + "pending": PrivateEndpointStatusPending, + "rejected": PrivateEndpointStatusRejected, + "timeout": PrivateEndpointStatusTimeout, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointStatus(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/origins/id_endpoint.go b/resource-manager/cdn/2024-02-01/origins/id_endpoint.go new file mode 100644 index 00000000000..4894a4cbede --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/id_endpoint.go @@ -0,0 +1,139 @@ +package origins + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&EndpointId{}) +} + +var _ resourceids.ResourceId = &EndpointId{} + +// EndpointId is a struct representing the Resource ID for a Endpoint +type EndpointId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + EndpointName string +} + +// NewEndpointID returns a new EndpointId struct +func NewEndpointID(subscriptionId string, resourceGroupName string, profileName string, endpointName string) EndpointId { + return EndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + EndpointName: endpointName, + } +} + +// ParseEndpointID parses 'input' into a EndpointId +func ParseEndpointID(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEndpointIDInsensitively parses 'input' case-insensitively into a EndpointId +// note: this method should only be used for API response data and not user input +func ParseEndpointIDInsensitively(input string) (*EndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.EndpointName, ok = input.Parsed["endpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointName", input) + } + + return nil +} + +// ValidateEndpointID checks that 'input' can be parsed as a Endpoint ID +func ValidateEndpointID(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 := ParseEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Endpoint ID +func (id EndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/endpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.EndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Endpoint ID +func (id EndpointId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticEndpoints", "endpoints", "endpoints"), + resourceids.UserSpecifiedSegment("endpointName", "endpointValue"), + } +} + +// String returns a human-readable description of this Endpoint ID +func (id EndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Endpoint Name: %q", id.EndpointName), + } + return fmt.Sprintf("Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/origins/id_endpoint_test.go b/resource-manager/cdn/2024-02-01/origins/id_endpoint_test.go new file mode 100644 index 00000000000..f3a3e68fe2a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/id_endpoint_test.go @@ -0,0 +1,327 @@ +package origins + +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 = &EndpointId{} + +func TestNewEndpointID(t *testing.T) { + id := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.EndpointName != "endpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointName'", id.EndpointName, "endpointValue") + } +} + +func TestFormatEndpointID(t *testing.T) { + actual := NewEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestParseEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe", + Expected: &EndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + EndpointName: "eNdPoInTvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + } +} + +func TestSegmentsForEndpointId(t *testing.T) { + segments := EndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EndpointId 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/cdn/2024-02-01/origins/id_origin.go b/resource-manager/cdn/2024-02-01/origins/id_origin.go new file mode 100644 index 00000000000..d219c13e03d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/id_origin.go @@ -0,0 +1,148 @@ +package origins + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OriginId{}) +} + +var _ resourceids.ResourceId = &OriginId{} + +// OriginId is a struct representing the Resource ID for a Origin +type OriginId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + EndpointName string + OriginName string +} + +// NewOriginID returns a new OriginId struct +func NewOriginID(subscriptionId string, resourceGroupName string, profileName string, endpointName string, originName string) OriginId { + return OriginId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + EndpointName: endpointName, + OriginName: originName, + } +} + +// ParseOriginID parses 'input' into a OriginId +func ParseOriginID(input string) (*OriginId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOriginIDInsensitively parses 'input' case-insensitively into a OriginId +// note: this method should only be used for API response data and not user input +func ParseOriginIDInsensitively(input string) (*OriginId, error) { + parser := resourceids.NewParserFromResourceIdType(&OriginId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OriginId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OriginId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.EndpointName, ok = input.Parsed["endpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointName", input) + } + + if id.OriginName, ok = input.Parsed["originName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "originName", input) + } + + return nil +} + +// ValidateOriginID checks that 'input' can be parsed as a Origin ID +func ValidateOriginID(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 := ParseOriginID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Origin ID +func (id OriginId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/endpoints/%s/origins/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.EndpointName, id.OriginName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Origin ID +func (id OriginId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticEndpoints", "endpoints", "endpoints"), + resourceids.UserSpecifiedSegment("endpointName", "endpointValue"), + resourceids.StaticSegment("staticOrigins", "origins", "origins"), + resourceids.UserSpecifiedSegment("originName", "originValue"), + } +} + +// String returns a human-readable description of this Origin ID +func (id OriginId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Endpoint Name: %q", id.EndpointName), + fmt.Sprintf("Origin Name: %q", id.OriginName), + } + return fmt.Sprintf("Origin (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/origins/id_origin_test.go b/resource-manager/cdn/2024-02-01/origins/id_origin_test.go new file mode 100644 index 00000000000..6d0f8778f41 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/id_origin_test.go @@ -0,0 +1,372 @@ +package origins + +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 = &OriginId{} + +func TestNewOriginID(t *testing.T) { + id := NewOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.EndpointName != "endpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointName'", id.EndpointName, "endpointValue") + } + + if id.OriginName != "originValue" { + t.Fatalf("Expected %q but got %q for Segment 'OriginName'", id.OriginName, "originValue") + } +} + +func TestFormatOriginID(t *testing.T) { + actual := NewOriginID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "endpointValue", "originValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/origins/originValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOriginID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/origins", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/origins/originValue", + Expected: &OriginId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + OriginName: "originValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/origins/originValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + if actual.OriginName != v.Expected.OriginName { + t.Fatalf("Expected %q but got %q for OriginName", v.Expected.OriginName, actual.OriginName) + } + + } +} + +func TestParseOriginIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OriginId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/origins", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/oRiGiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/origins/originValue", + Expected: &OriginId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + EndpointName: "endpointValue", + OriginName: "originValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/endpoints/endpointValue/origins/originValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/oRiGiNs/oRiGiNvAlUe", + Expected: &OriginId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + EndpointName: "eNdPoInTvAlUe", + OriginName: "oRiGiNvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/eNdPoInTs/eNdPoInTvAlUe/oRiGiNs/oRiGiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOriginIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.EndpointName != v.Expected.EndpointName { + t.Fatalf("Expected %q but got %q for EndpointName", v.Expected.EndpointName, actual.EndpointName) + } + + if actual.OriginName != v.Expected.OriginName { + t.Fatalf("Expected %q but got %q for OriginName", v.Expected.OriginName, actual.OriginName) + } + + } +} + +func TestSegmentsForOriginId(t *testing.T) { + segments := OriginId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OriginId 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/cdn/2024-02-01/origins/method_create.go b/resource-manager/cdn/2024-02-01/origins/method_create.go new file mode 100644 index 00000000000..e6005a205a4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/method_create.go @@ -0,0 +1,76 @@ +package origins + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Origin +} + +// Create ... +func (c OriginsClient) Create(ctx context.Context, id OriginId, input Origin) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c OriginsClient) CreateThenPoll(ctx context.Context, id OriginId, input Origin) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/origins/method_delete.go b/resource-manager/cdn/2024-02-01/origins/method_delete.go new file mode 100644 index 00000000000..47d36e6e87f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/method_delete.go @@ -0,0 +1,71 @@ +package origins + +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 OriginsClient) Delete(ctx context.Context, id OriginId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c OriginsClient) DeleteThenPoll(ctx context.Context, id OriginId) 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/cdn/2024-02-01/origins/method_get.go b/resource-manager/cdn/2024-02-01/origins/method_get.go new file mode 100644 index 00000000000..e246ef7d14d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/method_get.go @@ -0,0 +1,54 @@ +package origins + +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 *Origin +} + +// Get ... +func (c OriginsClient) Get(ctx context.Context, id OriginId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Origin + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/origins/method_listbyendpoint.go b/resource-manager/cdn/2024-02-01/origins/method_listbyendpoint.go new file mode 100644 index 00000000000..476f311d7bb --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/method_listbyendpoint.go @@ -0,0 +1,105 @@ +package origins + +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 ListByEndpointOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Origin +} + +type ListByEndpointCompleteResult struct { + LatestHttpResponse *http.Response + Items []Origin +} + +type ListByEndpointCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByEndpointCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByEndpoint ... +func (c OriginsClient) ListByEndpoint(ctx context.Context, id EndpointId) (result ListByEndpointOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByEndpointCustomPager{}, + Path: fmt.Sprintf("%s/origins", 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 *[]Origin `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByEndpointComplete retrieves all the results into a single object +func (c OriginsClient) ListByEndpointComplete(ctx context.Context, id EndpointId) (ListByEndpointCompleteResult, error) { + return c.ListByEndpointCompleteMatchingPredicate(ctx, id, OriginOperationPredicate{}) +} + +// ListByEndpointCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OriginsClient) ListByEndpointCompleteMatchingPredicate(ctx context.Context, id EndpointId, predicate OriginOperationPredicate) (result ListByEndpointCompleteResult, err error) { + items := make([]Origin, 0) + + resp, err := c.ListByEndpoint(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByEndpointCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/origins/method_update.go b/resource-manager/cdn/2024-02-01/origins/method_update.go new file mode 100644 index 00000000000..830da0e27ff --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/method_update.go @@ -0,0 +1,75 @@ +package origins + +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 + Model *Origin +} + +// Update ... +func (c OriginsClient) Update(ctx context.Context, id OriginId, input OriginUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c OriginsClient) UpdateThenPoll(ctx context.Context, id OriginId, input OriginUpdateParameters) 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/cdn/2024-02-01/origins/model_origin.go b/resource-manager/cdn/2024-02-01/origins/model_origin.go new file mode 100644 index 00000000000..38f21bdbd29 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/model_origin.go @@ -0,0 +1,16 @@ +package origins + +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 Origin struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OriginProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origins/model_originproperties.go b/resource-manager/cdn/2024-02-01/origins/model_originproperties.go new file mode 100644 index 00000000000..1c6a60f33a7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/model_originproperties.go @@ -0,0 +1,21 @@ +package origins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginProperties struct { + Enabled *bool `json:"enabled,omitempty"` + HTTPPort *int64 `json:"httpPort,omitempty"` + HTTPSPort *int64 `json:"httpsPort,omitempty"` + HostName *string `json:"hostName,omitempty"` + OriginHostHeader *string `json:"originHostHeader,omitempty"` + Priority *int64 `json:"priority,omitempty"` + PrivateEndpointStatus *PrivateEndpointStatus `json:"privateEndpointStatus,omitempty"` + PrivateLinkAlias *string `json:"privateLinkAlias,omitempty"` + PrivateLinkApprovalMessage *string `json:"privateLinkApprovalMessage,omitempty"` + PrivateLinkLocation *string `json:"privateLinkLocation,omitempty"` + PrivateLinkResourceId *string `json:"privateLinkResourceId,omitempty"` + ProvisioningState *OriginProvisioningState `json:"provisioningState,omitempty"` + ResourceState *OriginResourceState `json:"resourceState,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origins/model_originupdateparameters.go b/resource-manager/cdn/2024-02-01/origins/model_originupdateparameters.go new file mode 100644 index 00000000000..7277698e9d5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/model_originupdateparameters.go @@ -0,0 +1,8 @@ +package origins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginUpdateParameters struct { + Properties *OriginUpdatePropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origins/model_originupdatepropertiesparameters.go b/resource-manager/cdn/2024-02-01/origins/model_originupdatepropertiesparameters.go new file mode 100644 index 00000000000..c442bb8d4d9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/model_originupdatepropertiesparameters.go @@ -0,0 +1,18 @@ +package origins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginUpdatePropertiesParameters struct { + Enabled *bool `json:"enabled,omitempty"` + HTTPPort *int64 `json:"httpPort,omitempty"` + HTTPSPort *int64 `json:"httpsPort,omitempty"` + HostName *string `json:"hostName,omitempty"` + OriginHostHeader *string `json:"originHostHeader,omitempty"` + Priority *int64 `json:"priority,omitempty"` + PrivateLinkAlias *string `json:"privateLinkAlias,omitempty"` + PrivateLinkApprovalMessage *string `json:"privateLinkApprovalMessage,omitempty"` + PrivateLinkLocation *string `json:"privateLinkLocation,omitempty"` + PrivateLinkResourceId *string `json:"privateLinkResourceId,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/origins/predicates.go b/resource-manager/cdn/2024-02-01/origins/predicates.go new file mode 100644 index 00000000000..2424013ceb9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/predicates.go @@ -0,0 +1,27 @@ +package origins + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p OriginOperationPredicate) Matches(input Origin) 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/cdn/2024-02-01/origins/version.go b/resource-manager/cdn/2024-02-01/origins/version.go new file mode 100644 index 00000000000..f314368a2fd --- /dev/null +++ b/resource-manager/cdn/2024-02-01/origins/version.go @@ -0,0 +1,12 @@ +package origins + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/origins/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/profiles/README.md b/resource-manager/cdn/2024-02-01/profiles/README.md new file mode 100644 index 00000000000..a9483309dad --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/README.md @@ -0,0 +1,212 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles` Documentation + +The `profiles` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" +``` + + +### Client Initialization + +```go +client := profiles.NewProfilesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProfilesClient.CanMigrate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := profiles.CanMigrateParameters{ + // ... +} + + +if err := client.CanMigrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.Create` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +payload := profiles.Profile{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.Delete` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.GenerateSsoUri` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.GenerateSsoUri(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProfilesClient.Get` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +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: `ProfilesClient.List` + +```go +ctx := context.TODO() +id := commonids.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: `ProfilesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.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: `ProfilesClient.ListResourceUsage` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListResourceUsage(ctx, id)` can be used to do batched pagination +items, err := client.ListResourceUsageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProfilesClient.ListSupportedOptimizationTypes` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.ListSupportedOptimizationTypes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProfilesClient.Migrate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := profiles.MigrationParameters{ + // ... +} + + +if err := client.MigrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.MigrationCommit` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +if err := client.MigrationCommitThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.Update` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +payload := profiles.ProfileUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/profiles/client.go b/resource-manager/cdn/2024-02-01/profiles/client.go new file mode 100644 index 00000000000..72048226618 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/client.go @@ -0,0 +1,26 @@ +package profiles + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfilesClient struct { + Client *resourcemanager.Client +} + +func NewProfilesClientWithBaseURI(sdkApi sdkEnv.Api) (*ProfilesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "profiles", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProfilesClient: %+v", err) + } + + return &ProfilesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/profiles/constants.go b/resource-manager/cdn/2024-02-01/profiles/constants.go new file mode 100644 index 00000000000..7c46f402b9a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/constants.go @@ -0,0 +1,489 @@ +package profiles + +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 CanMigrateDefaultSku string + +const ( + CanMigrateDefaultSkuPremiumAzureFrontDoor CanMigrateDefaultSku = "Premium_AzureFrontDoor" + CanMigrateDefaultSkuStandardAzureFrontDoor CanMigrateDefaultSku = "Standard_AzureFrontDoor" +) + +func PossibleValuesForCanMigrateDefaultSku() []string { + return []string{ + string(CanMigrateDefaultSkuPremiumAzureFrontDoor), + string(CanMigrateDefaultSkuStandardAzureFrontDoor), + } +} + +func (s *CanMigrateDefaultSku) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCanMigrateDefaultSku(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCanMigrateDefaultSku(input string) (*CanMigrateDefaultSku, error) { + vals := map[string]CanMigrateDefaultSku{ + "premium_azurefrontdoor": CanMigrateDefaultSkuPremiumAzureFrontDoor, + "standard_azurefrontdoor": CanMigrateDefaultSkuStandardAzureFrontDoor, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CanMigrateDefaultSku(input) + return &out, nil +} + +type OptimizationType string + +const ( + OptimizationTypeDynamicSiteAcceleration OptimizationType = "DynamicSiteAcceleration" + OptimizationTypeGeneralMediaStreaming OptimizationType = "GeneralMediaStreaming" + OptimizationTypeGeneralWebDelivery OptimizationType = "GeneralWebDelivery" + OptimizationTypeLargeFileDownload OptimizationType = "LargeFileDownload" + OptimizationTypeVideoOnDemandMediaStreaming OptimizationType = "VideoOnDemandMediaStreaming" +) + +func PossibleValuesForOptimizationType() []string { + return []string{ + string(OptimizationTypeDynamicSiteAcceleration), + string(OptimizationTypeGeneralMediaStreaming), + string(OptimizationTypeGeneralWebDelivery), + string(OptimizationTypeLargeFileDownload), + string(OptimizationTypeVideoOnDemandMediaStreaming), + } +} + +func (s *OptimizationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOptimizationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOptimizationType(input string) (*OptimizationType, error) { + vals := map[string]OptimizationType{ + "dynamicsiteacceleration": OptimizationTypeDynamicSiteAcceleration, + "generalmediastreaming": OptimizationTypeGeneralMediaStreaming, + "generalwebdelivery": OptimizationTypeGeneralWebDelivery, + "largefiledownload": OptimizationTypeLargeFileDownload, + "videoondemandmediastreaming": OptimizationTypeVideoOnDemandMediaStreaming, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OptimizationType(input) + return &out, nil +} + +type ProfileProvisioningState string + +const ( + ProfileProvisioningStateCreating ProfileProvisioningState = "Creating" + ProfileProvisioningStateDeleting ProfileProvisioningState = "Deleting" + ProfileProvisioningStateFailed ProfileProvisioningState = "Failed" + ProfileProvisioningStateSucceeded ProfileProvisioningState = "Succeeded" + ProfileProvisioningStateUpdating ProfileProvisioningState = "Updating" +) + +func PossibleValuesForProfileProvisioningState() []string { + return []string{ + string(ProfileProvisioningStateCreating), + string(ProfileProvisioningStateDeleting), + string(ProfileProvisioningStateFailed), + string(ProfileProvisioningStateSucceeded), + string(ProfileProvisioningStateUpdating), + } +} + +func (s *ProfileProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileProvisioningState(input string) (*ProfileProvisioningState, error) { + vals := map[string]ProfileProvisioningState{ + "creating": ProfileProvisioningStateCreating, + "deleting": ProfileProvisioningStateDeleting, + "failed": ProfileProvisioningStateFailed, + "succeeded": ProfileProvisioningStateSucceeded, + "updating": ProfileProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileProvisioningState(input) + return &out, nil +} + +type ProfileResourceState string + +const ( + ProfileResourceStateAbortingMigration ProfileResourceState = "AbortingMigration" + ProfileResourceStateActive ProfileResourceState = "Active" + ProfileResourceStateCommittingMigration ProfileResourceState = "CommittingMigration" + ProfileResourceStateCreating ProfileResourceState = "Creating" + ProfileResourceStateDeleting ProfileResourceState = "Deleting" + ProfileResourceStateDisabled ProfileResourceState = "Disabled" + ProfileResourceStateMigrated ProfileResourceState = "Migrated" + ProfileResourceStateMigrating ProfileResourceState = "Migrating" + ProfileResourceStatePendingMigrationCommit ProfileResourceState = "PendingMigrationCommit" +) + +func PossibleValuesForProfileResourceState() []string { + return []string{ + string(ProfileResourceStateAbortingMigration), + string(ProfileResourceStateActive), + string(ProfileResourceStateCommittingMigration), + string(ProfileResourceStateCreating), + string(ProfileResourceStateDeleting), + string(ProfileResourceStateDisabled), + string(ProfileResourceStateMigrated), + string(ProfileResourceStateMigrating), + string(ProfileResourceStatePendingMigrationCommit), + } +} + +func (s *ProfileResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileResourceState(input string) (*ProfileResourceState, error) { + vals := map[string]ProfileResourceState{ + "abortingmigration": ProfileResourceStateAbortingMigration, + "active": ProfileResourceStateActive, + "committingmigration": ProfileResourceStateCommittingMigration, + "creating": ProfileResourceStateCreating, + "deleting": ProfileResourceStateDeleting, + "disabled": ProfileResourceStateDisabled, + "migrated": ProfileResourceStateMigrated, + "migrating": ProfileResourceStateMigrating, + "pendingmigrationcommit": ProfileResourceStatePendingMigrationCommit, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileResourceState(input) + return &out, nil +} + +type ProfileScrubbingState string + +const ( + ProfileScrubbingStateDisabled ProfileScrubbingState = "Disabled" + ProfileScrubbingStateEnabled ProfileScrubbingState = "Enabled" +) + +func PossibleValuesForProfileScrubbingState() []string { + return []string{ + string(ProfileScrubbingStateDisabled), + string(ProfileScrubbingStateEnabled), + } +} + +func (s *ProfileScrubbingState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileScrubbingState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileScrubbingState(input string) (*ProfileScrubbingState, error) { + vals := map[string]ProfileScrubbingState{ + "disabled": ProfileScrubbingStateDisabled, + "enabled": ProfileScrubbingStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileScrubbingState(input) + return &out, nil +} + +type ResourceUsageUnit string + +const ( + ResourceUsageUnitCount ResourceUsageUnit = "count" +) + +func PossibleValuesForResourceUsageUnit() []string { + return []string{ + string(ResourceUsageUnitCount), + } +} + +func (s *ResourceUsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceUsageUnit(input string) (*ResourceUsageUnit, error) { + vals := map[string]ResourceUsageUnit{ + "count": ResourceUsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceUsageUnit(input) + return &out, nil +} + +type ScrubbingRuleEntryMatchOperator string + +const ( + ScrubbingRuleEntryMatchOperatorEqualsAny ScrubbingRuleEntryMatchOperator = "EqualsAny" +) + +func PossibleValuesForScrubbingRuleEntryMatchOperator() []string { + return []string{ + string(ScrubbingRuleEntryMatchOperatorEqualsAny), + } +} + +func (s *ScrubbingRuleEntryMatchOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryMatchOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryMatchOperator(input string) (*ScrubbingRuleEntryMatchOperator, error) { + vals := map[string]ScrubbingRuleEntryMatchOperator{ + "equalsany": ScrubbingRuleEntryMatchOperatorEqualsAny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryMatchOperator(input) + return &out, nil +} + +type ScrubbingRuleEntryMatchVariable string + +const ( + ScrubbingRuleEntryMatchVariableQueryStringArgNames ScrubbingRuleEntryMatchVariable = "QueryStringArgNames" + ScrubbingRuleEntryMatchVariableRequestIPAddress ScrubbingRuleEntryMatchVariable = "RequestIPAddress" + ScrubbingRuleEntryMatchVariableRequestUri ScrubbingRuleEntryMatchVariable = "RequestUri" +) + +func PossibleValuesForScrubbingRuleEntryMatchVariable() []string { + return []string{ + string(ScrubbingRuleEntryMatchVariableQueryStringArgNames), + string(ScrubbingRuleEntryMatchVariableRequestIPAddress), + string(ScrubbingRuleEntryMatchVariableRequestUri), + } +} + +func (s *ScrubbingRuleEntryMatchVariable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryMatchVariable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryMatchVariable(input string) (*ScrubbingRuleEntryMatchVariable, error) { + vals := map[string]ScrubbingRuleEntryMatchVariable{ + "querystringargnames": ScrubbingRuleEntryMatchVariableQueryStringArgNames, + "requestipaddress": ScrubbingRuleEntryMatchVariableRequestIPAddress, + "requesturi": ScrubbingRuleEntryMatchVariableRequestUri, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryMatchVariable(input) + return &out, nil +} + +type ScrubbingRuleEntryState string + +const ( + ScrubbingRuleEntryStateDisabled ScrubbingRuleEntryState = "Disabled" + ScrubbingRuleEntryStateEnabled ScrubbingRuleEntryState = "Enabled" +) + +func PossibleValuesForScrubbingRuleEntryState() []string { + return []string{ + string(ScrubbingRuleEntryStateDisabled), + string(ScrubbingRuleEntryStateEnabled), + } +} + +func (s *ScrubbingRuleEntryState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryState(input string) (*ScrubbingRuleEntryState, error) { + vals := map[string]ScrubbingRuleEntryState{ + "disabled": ScrubbingRuleEntryStateDisabled, + "enabled": ScrubbingRuleEntryStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryState(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameCustomVerizon SkuName = "Custom_Verizon" + SkuNamePremiumAzureFrontDoor SkuName = "Premium_AzureFrontDoor" + SkuNamePremiumVerizon SkuName = "Premium_Verizon" + SkuNameStandardAkamai SkuName = "Standard_Akamai" + SkuNameStandardAvgBandWidthChinaCdn SkuName = "Standard_AvgBandWidth_ChinaCdn" + SkuNameStandardAzureFrontDoor SkuName = "Standard_AzureFrontDoor" + SkuNameStandardChinaCdn SkuName = "Standard_ChinaCdn" + SkuNameStandardMicrosoft SkuName = "Standard_Microsoft" + SkuNameStandardNineFiveFiveBandWidthChinaCdn SkuName = "Standard_955BandWidth_ChinaCdn" + SkuNameStandardPlusAvgBandWidthChinaCdn SkuName = "StandardPlus_AvgBandWidth_ChinaCdn" + SkuNameStandardPlusChinaCdn SkuName = "StandardPlus_ChinaCdn" + SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn SkuName = "StandardPlus_955BandWidth_ChinaCdn" + SkuNameStandardVerizon SkuName = "Standard_Verizon" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameCustomVerizon), + string(SkuNamePremiumAzureFrontDoor), + string(SkuNamePremiumVerizon), + string(SkuNameStandardAkamai), + string(SkuNameStandardAvgBandWidthChinaCdn), + string(SkuNameStandardAzureFrontDoor), + string(SkuNameStandardChinaCdn), + string(SkuNameStandardMicrosoft), + string(SkuNameStandardNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardPlusAvgBandWidthChinaCdn), + string(SkuNameStandardPlusChinaCdn), + string(SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardVerizon), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "custom_verizon": SkuNameCustomVerizon, + "premium_azurefrontdoor": SkuNamePremiumAzureFrontDoor, + "premium_verizon": SkuNamePremiumVerizon, + "standard_akamai": SkuNameStandardAkamai, + "standard_avgbandwidth_chinacdn": SkuNameStandardAvgBandWidthChinaCdn, + "standard_azurefrontdoor": SkuNameStandardAzureFrontDoor, + "standard_chinacdn": SkuNameStandardChinaCdn, + "standard_microsoft": SkuNameStandardMicrosoft, + "standard_955bandwidth_chinacdn": SkuNameStandardNineFiveFiveBandWidthChinaCdn, + "standardplus_avgbandwidth_chinacdn": SkuNameStandardPlusAvgBandWidthChinaCdn, + "standardplus_chinacdn": SkuNameStandardPlusChinaCdn, + "standardplus_955bandwidth_chinacdn": SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn, + "standard_verizon": SkuNameStandardVerizon, + } + 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 +} diff --git a/resource-manager/cdn/2024-02-01/profiles/id_profile.go b/resource-manager/cdn/2024-02-01/profiles/id_profile.go new file mode 100644 index 00000000000..488b8f6993b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/id_profile.go @@ -0,0 +1,130 @@ +package profiles + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/profiles/id_profile_test.go b/resource-manager/cdn/2024-02-01/profiles/id_profile_test.go new file mode 100644 index 00000000000..f46c7b2aae3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/id_profile_test.go @@ -0,0 +1,282 @@ +package profiles + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/profiles/method_canmigrate.go b/resource-manager/cdn/2024-02-01/profiles/method_canmigrate.go new file mode 100644 index 00000000000..edda0638219 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_canmigrate.go @@ -0,0 +1,76 @@ +package profiles + +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/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 CanMigrateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CanMigrateResult +} + +// CanMigrate ... +func (c ProfilesClient) CanMigrate(ctx context.Context, id commonids.ResourceGroupId, input CanMigrateParameters) (result CanMigrateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/canMigrate", 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 +} + +// CanMigrateThenPoll performs CanMigrate then polls until it's completed +func (c ProfilesClient) CanMigrateThenPoll(ctx context.Context, id commonids.ResourceGroupId, input CanMigrateParameters) error { + result, err := c.CanMigrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CanMigrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CanMigrate: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_create.go b/resource-manager/cdn/2024-02-01/profiles/method_create.go new file mode 100644 index 00000000000..fdde9d737ec --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_create.go @@ -0,0 +1,76 @@ +package profiles + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Profile +} + +// Create ... +func (c ProfilesClient) Create(ctx context.Context, id ProfileId, input Profile) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ProfilesClient) CreateThenPoll(ctx context.Context, id ProfileId, input Profile) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_delete.go b/resource-manager/cdn/2024-02-01/profiles/method_delete.go new file mode 100644 index 00000000000..8d46fe3a4ff --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_delete.go @@ -0,0 +1,71 @@ +package profiles + +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 ProfilesClient) Delete(ctx context.Context, id ProfileId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ProfilesClient) DeleteThenPoll(ctx context.Context, id ProfileId) 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/cdn/2024-02-01/profiles/method_generatessouri.go b/resource-manager/cdn/2024-02-01/profiles/method_generatessouri.go new file mode 100644 index 00000000000..0a6e358bcb7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_generatessouri.go @@ -0,0 +1,55 @@ +package profiles + +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 GenerateSsoUriOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SsoUri +} + +// GenerateSsoUri ... +func (c ProfilesClient) GenerateSsoUri(ctx context.Context, id ProfileId) (result GenerateSsoUriOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/generateSsoUri", 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 + } + + var model SsoUri + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_get.go b/resource-manager/cdn/2024-02-01/profiles/method_get.go new file mode 100644 index 00000000000..0320b7520fc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_get.go @@ -0,0 +1,54 @@ +package profiles + +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 *Profile +} + +// Get ... +func (c ProfilesClient) Get(ctx context.Context, id ProfileId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Profile + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_list.go b/resource-manager/cdn/2024-02-01/profiles/method_list.go new file mode 100644 index 00000000000..3a6e95d2b42 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_list.go @@ -0,0 +1,106 @@ +package profiles + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Profile +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Profile +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ProfilesClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/profiles", 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 *[]Profile `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ProfilesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ProfileOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProfilesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ProfileOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Profile, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_listbyresourcegroup.go b/resource-manager/cdn/2024-02-01/profiles/method_listbyresourcegroup.go new file mode 100644 index 00000000000..da005d4d92c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package profiles + +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 *[]Profile +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Profile +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ProfilesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/profiles", 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 *[]Profile `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c ProfilesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ProfileOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProfilesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ProfileOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Profile, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_listresourceusage.go b/resource-manager/cdn/2024-02-01/profiles/method_listresourceusage.go new file mode 100644 index 00000000000..1f51a1643fd --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_listresourceusage.go @@ -0,0 +1,105 @@ +package profiles + +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 ListResourceUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceUsage +} + +type ListResourceUsageCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceUsage +} + +type ListResourceUsageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListResourceUsageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListResourceUsage ... +func (c ProfilesClient) ListResourceUsage(ctx context.Context, id ProfileId) (result ListResourceUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListResourceUsageCustomPager{}, + Path: fmt.Sprintf("%s/checkResourceUsage", 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 *[]ResourceUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourceUsageComplete retrieves all the results into a single object +func (c ProfilesClient) ListResourceUsageComplete(ctx context.Context, id ProfileId) (ListResourceUsageCompleteResult, error) { + return c.ListResourceUsageCompleteMatchingPredicate(ctx, id, ResourceUsageOperationPredicate{}) +} + +// ListResourceUsageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProfilesClient) ListResourceUsageCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate ResourceUsageOperationPredicate) (result ListResourceUsageCompleteResult, err error) { + items := make([]ResourceUsage, 0) + + resp, err := c.ListResourceUsage(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListResourceUsageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_listsupportedoptimizationtypes.go b/resource-manager/cdn/2024-02-01/profiles/method_listsupportedoptimizationtypes.go new file mode 100644 index 00000000000..22ac1c5c226 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_listsupportedoptimizationtypes.go @@ -0,0 +1,55 @@ +package profiles + +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 ListSupportedOptimizationTypesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SupportedOptimizationTypesListResult +} + +// ListSupportedOptimizationTypes ... +func (c ProfilesClient) ListSupportedOptimizationTypes(ctx context.Context, id ProfileId) (result ListSupportedOptimizationTypesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getSupportedOptimizationTypes", 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 + } + + var model SupportedOptimizationTypesListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_migrate.go b/resource-manager/cdn/2024-02-01/profiles/method_migrate.go new file mode 100644 index 00000000000..cb3ea6cce65 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_migrate.go @@ -0,0 +1,76 @@ +package profiles + +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/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 MigrateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *MigrateResult +} + +// Migrate ... +func (c ProfilesClient) Migrate(ctx context.Context, id commonids.ResourceGroupId, input MigrationParameters) (result MigrateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/migrate", 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 +} + +// MigrateThenPoll performs Migrate then polls until it's completed +func (c ProfilesClient) MigrateThenPoll(ctx context.Context, id commonids.ResourceGroupId, input MigrationParameters) error { + result, err := c.Migrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Migrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Migrate: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_migrationcommit.go b/resource-manager/cdn/2024-02-01/profiles/method_migrationcommit.go new file mode 100644 index 00000000000..eb5e0a88a27 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_migrationcommit.go @@ -0,0 +1,70 @@ +package profiles + +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 MigrationCommitOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// MigrationCommit ... +func (c ProfilesClient) MigrationCommit(ctx context.Context, id ProfileId) (result MigrationCommitOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/migrationCommit", 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 +} + +// MigrationCommitThenPoll performs MigrationCommit then polls until it's completed +func (c ProfilesClient) MigrationCommitThenPoll(ctx context.Context, id ProfileId) error { + result, err := c.MigrationCommit(ctx, id) + if err != nil { + return fmt.Errorf("performing MigrationCommit: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MigrationCommit: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/profiles/method_update.go b/resource-manager/cdn/2024-02-01/profiles/method_update.go new file mode 100644 index 00000000000..5694b5666a6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/method_update.go @@ -0,0 +1,75 @@ +package profiles + +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 + Model *Profile +} + +// Update ... +func (c ProfilesClient) Update(ctx context.Context, id ProfileId, input ProfileUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ProfilesClient) UpdateThenPoll(ctx context.Context, id ProfileId, input ProfileUpdateParameters) 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/cdn/2024-02-01/profiles/model_canmigrateparameters.go b/resource-manager/cdn/2024-02-01/profiles/model_canmigrateparameters.go new file mode 100644 index 00000000000..cba030af8d7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_canmigrateparameters.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CanMigrateParameters struct { + ClassicResourceReference ResourceReference `json:"classicResourceReference"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_canmigrateproperties.go b/resource-manager/cdn/2024-02-01/profiles/model_canmigrateproperties.go new file mode 100644 index 00000000000..8a79f4648c1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_canmigrateproperties.go @@ -0,0 +1,10 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CanMigrateProperties struct { + CanMigrate *bool `json:"canMigrate,omitempty"` + DefaultSku *CanMigrateDefaultSku `json:"defaultSku,omitempty"` + Errors *[]MigrationErrorType `json:"errors,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_canmigrateresult.go b/resource-manager/cdn/2024-02-01/profiles/model_canmigrateresult.go new file mode 100644 index 00000000000..500699ff775 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_canmigrateresult.go @@ -0,0 +1,10 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CanMigrateResult struct { + Id *string `json:"id,omitempty"` + Properties *CanMigrateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_migrateresult.go b/resource-manager/cdn/2024-02-01/profiles/model_migrateresult.go new file mode 100644 index 00000000000..c53f7a73fc5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_migrateresult.go @@ -0,0 +1,10 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateResult struct { + Id *string `json:"id,omitempty"` + Properties *MigrateResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_migrateresultproperties.go b/resource-manager/cdn/2024-02-01/profiles/model_migrateresultproperties.go new file mode 100644 index 00000000000..ad533db013d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_migrateresultproperties.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateResultProperties struct { + MigratedProfileResourceId *ResourceReference `json:"migratedProfileResourceId,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_migrationerrortype.go b/resource-manager/cdn/2024-02-01/profiles/model_migrationerrortype.go new file mode 100644 index 00000000000..6155279d9c1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_migrationerrortype.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationErrorType struct { + Code *string `json:"code,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + NextSteps *string `json:"nextSteps,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_migrationparameters.go b/resource-manager/cdn/2024-02-01/profiles/model_migrationparameters.go new file mode 100644 index 00000000000..37a14cc634b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_migrationparameters.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationParameters struct { + ClassicResourceReference ResourceReference `json:"classicResourceReference"` + MigrationWebApplicationFirewallMappings *[]MigrationWebApplicationFirewallMapping `json:"migrationWebApplicationFirewallMappings,omitempty"` + ProfileName string `json:"profileName"` + Sku Sku `json:"sku"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_migrationwebapplicationfirewallmapping.go b/resource-manager/cdn/2024-02-01/profiles/model_migrationwebapplicationfirewallmapping.go new file mode 100644 index 00000000000..342be305588 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_migrationwebapplicationfirewallmapping.go @@ -0,0 +1,9 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationWebApplicationFirewallMapping struct { + MigratedFrom *ResourceReference `json:"migratedFrom,omitempty"` + MigratedTo *ResourceReference `json:"migratedTo,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_profile.go b/resource-manager/cdn/2024-02-01/profiles/model_profile.go new file mode 100644 index 00000000000..2568ad9b130 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_profile.go @@ -0,0 +1,22 @@ +package profiles + +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 Profile struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ProfileProperties `json:"properties,omitempty"` + Sku Sku `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_profilelogscrubbing.go b/resource-manager/cdn/2024-02-01/profiles/model_profilelogscrubbing.go new file mode 100644 index 00000000000..f897715e8c2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_profilelogscrubbing.go @@ -0,0 +1,9 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileLogScrubbing struct { + ScrubbingRules *[]ProfileScrubbingRules `json:"scrubbingRules,omitempty"` + State *ProfileScrubbingState `json:"state,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_profileproperties.go b/resource-manager/cdn/2024-02-01/profiles/model_profileproperties.go new file mode 100644 index 00000000000..6c9e4d175b4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_profileproperties.go @@ -0,0 +1,13 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileProperties struct { + ExtendedProperties *map[string]string `json:"extendedProperties,omitempty"` + FrontDoorId *string `json:"frontDoorId,omitempty"` + LogScrubbing *ProfileLogScrubbing `json:"logScrubbing,omitempty"` + OriginResponseTimeoutSeconds *int64 `json:"originResponseTimeoutSeconds,omitempty"` + ProvisioningState *ProfileProvisioningState `json:"provisioningState,omitempty"` + ResourceState *ProfileResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_profilepropertiesupdateparameters.go b/resource-manager/cdn/2024-02-01/profiles/model_profilepropertiesupdateparameters.go new file mode 100644 index 00000000000..01d3dc5ad0e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_profilepropertiesupdateparameters.go @@ -0,0 +1,9 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfilePropertiesUpdateParameters struct { + LogScrubbing *ProfileLogScrubbing `json:"logScrubbing,omitempty"` + OriginResponseTimeoutSeconds *int64 `json:"originResponseTimeoutSeconds,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_profilescrubbingrules.go b/resource-manager/cdn/2024-02-01/profiles/model_profilescrubbingrules.go new file mode 100644 index 00000000000..9ed138086f8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_profilescrubbingrules.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileScrubbingRules struct { + MatchVariable ScrubbingRuleEntryMatchVariable `json:"matchVariable"` + Selector *string `json:"selector,omitempty"` + SelectorMatchOperator ScrubbingRuleEntryMatchOperator `json:"selectorMatchOperator"` + State *ScrubbingRuleEntryState `json:"state,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_profileupdateparameters.go b/resource-manager/cdn/2024-02-01/profiles/model_profileupdateparameters.go new file mode 100644 index 00000000000..01c4b966536 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_profileupdateparameters.go @@ -0,0 +1,14 @@ +package profiles + +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 ProfileUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ProfilePropertiesUpdateParameters `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_resourcereference.go b/resource-manager/cdn/2024-02-01/profiles/model_resourcereference.go new file mode 100644 index 00000000000..3e5faa3a3d7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_resourcereference.go @@ -0,0 +1,8 @@ +package profiles + +// 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/cdn/2024-02-01/profiles/model_resourceusage.go b/resource-manager/cdn/2024-02-01/profiles/model_resourceusage.go new file mode 100644 index 00000000000..f56db4430e2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_resourceusage.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceUsage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Limit *int64 `json:"limit,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Unit *ResourceUsageUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_sku.go b/resource-manager/cdn/2024-02-01/profiles/model_sku.go new file mode 100644 index 00000000000..a70d546bfd6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_sku.go @@ -0,0 +1,8 @@ +package profiles + +// 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 { + Name *SkuName `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_ssouri.go b/resource-manager/cdn/2024-02-01/profiles/model_ssouri.go new file mode 100644 index 00000000000..ae93b0584f8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_ssouri.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsoUri struct { + SsoUriValue *string `json:"ssoUriValue,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/model_supportedoptimizationtypeslistresult.go b/resource-manager/cdn/2024-02-01/profiles/model_supportedoptimizationtypeslistresult.go new file mode 100644 index 00000000000..1242943b3db --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/model_supportedoptimizationtypeslistresult.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedOptimizationTypesListResult struct { + SupportedOptimizationTypes *[]OptimizationType `json:"supportedOptimizationTypes,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/profiles/predicates.go b/resource-manager/cdn/2024-02-01/profiles/predicates.go new file mode 100644 index 00000000000..f48c2803370 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/predicates.go @@ -0,0 +1,60 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p ProfileOperationPredicate) Matches(input Profile) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && *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 ResourceUsageOperationPredicate struct { + CurrentValue *int64 + Limit *int64 + ResourceType *string +} + +func (p ResourceUsageOperationPredicate) Matches(input ResourceUsage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + return true +} diff --git a/resource-manager/cdn/2024-02-01/profiles/version.go b/resource-manager/cdn/2024-02-01/profiles/version.go new file mode 100644 index 00000000000..f2311a98c08 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/profiles/version.go @@ -0,0 +1,12 @@ +package profiles + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/profiles/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/routes/README.md b/resource-manager/cdn/2024-02-01/routes/README.md new file mode 100644 index 00000000000..7f52755c2de --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/routes` Documentation + +The `routes` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/routes" +``` + + +### Client Initialization + +```go +client := routes.NewRoutesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RoutesClient.Create` + +```go +ctx := context.TODO() +id := routes.NewRouteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue", "routeValue") + +payload := routes.Route{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RoutesClient.Delete` + +```go +ctx := context.TODO() +id := routes.NewRouteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue", "routeValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RoutesClient.Get` + +```go +ctx := context.TODO() +id := routes.NewRouteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue", "routeValue") + +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: `RoutesClient.ListByEndpoint` + +```go +ctx := context.TODO() +id := routes.NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + +// alternatively `client.ListByEndpoint(ctx, id)` can be used to do batched pagination +items, err := client.ListByEndpointComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RoutesClient.Update` + +```go +ctx := context.TODO() +id := routes.NewRouteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue", "routeValue") + +payload := routes.RouteUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/routes/client.go b/resource-manager/cdn/2024-02-01/routes/client.go new file mode 100644 index 00000000000..4372f694741 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/client.go @@ -0,0 +1,26 @@ +package routes + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RoutesClient struct { + Client *resourcemanager.Client +} + +func NewRoutesClientWithBaseURI(sdkApi sdkEnv.Api) (*RoutesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "routes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RoutesClient: %+v", err) + } + + return &RoutesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/routes/constants.go b/resource-manager/cdn/2024-02-01/routes/constants.go new file mode 100644 index 00000000000..86d0195a3fb --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/constants.go @@ -0,0 +1,362 @@ +package routes + +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 AFDEndpointProtocols string + +const ( + AFDEndpointProtocolsHTTP AFDEndpointProtocols = "Http" + AFDEndpointProtocolsHTTPS AFDEndpointProtocols = "Https" +) + +func PossibleValuesForAFDEndpointProtocols() []string { + return []string{ + string(AFDEndpointProtocolsHTTP), + string(AFDEndpointProtocolsHTTPS), + } +} + +func (s *AFDEndpointProtocols) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAFDEndpointProtocols(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAFDEndpointProtocols(input string) (*AFDEndpointProtocols, error) { + vals := map[string]AFDEndpointProtocols{ + "http": AFDEndpointProtocolsHTTP, + "https": AFDEndpointProtocolsHTTPS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AFDEndpointProtocols(input) + return &out, nil +} + +type AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type AfdQueryStringCachingBehavior string + +const ( + AfdQueryStringCachingBehaviorIgnoreQueryString AfdQueryStringCachingBehavior = "IgnoreQueryString" + AfdQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings AfdQueryStringCachingBehavior = "IgnoreSpecifiedQueryStrings" + AfdQueryStringCachingBehaviorIncludeSpecifiedQueryStrings AfdQueryStringCachingBehavior = "IncludeSpecifiedQueryStrings" + AfdQueryStringCachingBehaviorUseQueryString AfdQueryStringCachingBehavior = "UseQueryString" +) + +func PossibleValuesForAfdQueryStringCachingBehavior() []string { + return []string{ + string(AfdQueryStringCachingBehaviorIgnoreQueryString), + string(AfdQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings), + string(AfdQueryStringCachingBehaviorIncludeSpecifiedQueryStrings), + string(AfdQueryStringCachingBehaviorUseQueryString), + } +} + +func (s *AfdQueryStringCachingBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdQueryStringCachingBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdQueryStringCachingBehavior(input string) (*AfdQueryStringCachingBehavior, error) { + vals := map[string]AfdQueryStringCachingBehavior{ + "ignorequerystring": AfdQueryStringCachingBehaviorIgnoreQueryString, + "ignorespecifiedquerystrings": AfdQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings, + "includespecifiedquerystrings": AfdQueryStringCachingBehaviorIncludeSpecifiedQueryStrings, + "usequerystring": AfdQueryStringCachingBehaviorUseQueryString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdQueryStringCachingBehavior(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type EnabledState string + +const ( + EnabledStateDisabled EnabledState = "Disabled" + EnabledStateEnabled EnabledState = "Enabled" +) + +func PossibleValuesForEnabledState() []string { + return []string{ + string(EnabledStateDisabled), + string(EnabledStateEnabled), + } +} + +func (s *EnabledState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEnabledState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEnabledState(input string) (*EnabledState, error) { + vals := map[string]EnabledState{ + "disabled": EnabledStateDisabled, + "enabled": EnabledStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnabledState(input) + return &out, nil +} + +type ForwardingProtocol string + +const ( + ForwardingProtocolHTTPOnly ForwardingProtocol = "HttpOnly" + ForwardingProtocolHTTPSOnly ForwardingProtocol = "HttpsOnly" + ForwardingProtocolMatchRequest ForwardingProtocol = "MatchRequest" +) + +func PossibleValuesForForwardingProtocol() []string { + return []string{ + string(ForwardingProtocolHTTPOnly), + string(ForwardingProtocolHTTPSOnly), + string(ForwardingProtocolMatchRequest), + } +} + +func (s *ForwardingProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseForwardingProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseForwardingProtocol(input string) (*ForwardingProtocol, error) { + vals := map[string]ForwardingProtocol{ + "httponly": ForwardingProtocolHTTPOnly, + "httpsonly": ForwardingProtocolHTTPSOnly, + "matchrequest": ForwardingProtocolMatchRequest, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ForwardingProtocol(input) + return &out, nil +} + +type HTTPSRedirect string + +const ( + HTTPSRedirectDisabled HTTPSRedirect = "Disabled" + HTTPSRedirectEnabled HTTPSRedirect = "Enabled" +) + +func PossibleValuesForHTTPSRedirect() []string { + return []string{ + string(HTTPSRedirectDisabled), + string(HTTPSRedirectEnabled), + } +} + +func (s *HTTPSRedirect) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHTTPSRedirect(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHTTPSRedirect(input string) (*HTTPSRedirect, error) { + vals := map[string]HTTPSRedirect{ + "disabled": HTTPSRedirectDisabled, + "enabled": HTTPSRedirectEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HTTPSRedirect(input) + return &out, nil +} + +type LinkToDefaultDomain string + +const ( + LinkToDefaultDomainDisabled LinkToDefaultDomain = "Disabled" + LinkToDefaultDomainEnabled LinkToDefaultDomain = "Enabled" +) + +func PossibleValuesForLinkToDefaultDomain() []string { + return []string{ + string(LinkToDefaultDomainDisabled), + string(LinkToDefaultDomainEnabled), + } +} + +func (s *LinkToDefaultDomain) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLinkToDefaultDomain(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLinkToDefaultDomain(input string) (*LinkToDefaultDomain, error) { + vals := map[string]LinkToDefaultDomain{ + "disabled": LinkToDefaultDomainDisabled, + "enabled": LinkToDefaultDomainEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LinkToDefaultDomain(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/routes/id_afdendpoint.go b/resource-manager/cdn/2024-02-01/routes/id_afdendpoint.go new file mode 100644 index 00000000000..efe2ad8c0ca --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/id_afdendpoint.go @@ -0,0 +1,139 @@ +package routes + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AfdEndpointId{}) +} + +var _ resourceids.ResourceId = &AfdEndpointId{} + +// AfdEndpointId is a struct representing the Resource ID for a Afd Endpoint +type AfdEndpointId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + AfdEndpointName string +} + +// NewAfdEndpointID returns a new AfdEndpointId struct +func NewAfdEndpointID(subscriptionId string, resourceGroupName string, profileName string, afdEndpointName string) AfdEndpointId { + return AfdEndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + AfdEndpointName: afdEndpointName, + } +} + +// ParseAfdEndpointID parses 'input' into a AfdEndpointId +func ParseAfdEndpointID(input string) (*AfdEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&AfdEndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AfdEndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAfdEndpointIDInsensitively parses 'input' case-insensitively into a AfdEndpointId +// note: this method should only be used for API response data and not user input +func ParseAfdEndpointIDInsensitively(input string) (*AfdEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&AfdEndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AfdEndpointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AfdEndpointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.AfdEndpointName, ok = input.Parsed["afdEndpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "afdEndpointName", input) + } + + return nil +} + +// ValidateAfdEndpointID checks that 'input' can be parsed as a Afd Endpoint ID +func ValidateAfdEndpointID(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 := ParseAfdEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Afd Endpoint ID +func (id AfdEndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/afdEndpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.AfdEndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Afd Endpoint ID +func (id AfdEndpointId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticAfdEndpoints", "afdEndpoints", "afdEndpoints"), + resourceids.UserSpecifiedSegment("afdEndpointName", "afdEndpointValue"), + } +} + +// String returns a human-readable description of this Afd Endpoint ID +func (id AfdEndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Afd Endpoint Name: %q", id.AfdEndpointName), + } + return fmt.Sprintf("Afd Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/routes/id_afdendpoint_test.go b/resource-manager/cdn/2024-02-01/routes/id_afdendpoint_test.go new file mode 100644 index 00000000000..19198ee79d0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/id_afdendpoint_test.go @@ -0,0 +1,327 @@ +package routes + +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 = &AfdEndpointId{} + +func TestNewAfdEndpointID(t *testing.T) { + id := NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.AfdEndpointName != "afdEndpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'AfdEndpointName'", id.AfdEndpointName, "afdEndpointValue") + } +} + +func TestFormatAfdEndpointID(t *testing.T) { + actual := NewAfdEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAfdEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AfdEndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue", + Expected: &AfdEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + AfdEndpointName: "afdEndpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAfdEndpointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.AfdEndpointName != v.Expected.AfdEndpointName { + t.Fatalf("Expected %q but got %q for AfdEndpointName", v.Expected.AfdEndpointName, actual.AfdEndpointName) + } + + } +} + +func TestParseAfdEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AfdEndpointId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue", + Expected: &AfdEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + AfdEndpointName: "afdEndpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE", + Expected: &AfdEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + AfdEndpointName: "aFdEnDpOiNtVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAfdEndpointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.AfdEndpointName != v.Expected.AfdEndpointName { + t.Fatalf("Expected %q but got %q for AfdEndpointName", v.Expected.AfdEndpointName, actual.AfdEndpointName) + } + + } +} + +func TestSegmentsForAfdEndpointId(t *testing.T) { + segments := AfdEndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AfdEndpointId 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/cdn/2024-02-01/routes/id_route.go b/resource-manager/cdn/2024-02-01/routes/id_route.go new file mode 100644 index 00000000000..b787d2f249e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/id_route.go @@ -0,0 +1,148 @@ +package routes + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RouteId{}) +} + +var _ resourceids.ResourceId = &RouteId{} + +// RouteId is a struct representing the Resource ID for a Route +type RouteId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + AfdEndpointName string + RouteName string +} + +// NewRouteID returns a new RouteId struct +func NewRouteID(subscriptionId string, resourceGroupName string, profileName string, afdEndpointName string, routeName string) RouteId { + return RouteId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + AfdEndpointName: afdEndpointName, + RouteName: routeName, + } +} + +// ParseRouteID parses 'input' into a RouteId +func ParseRouteID(input string) (*RouteId, error) { + parser := resourceids.NewParserFromResourceIdType(&RouteId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RouteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRouteIDInsensitively parses 'input' case-insensitively into a RouteId +// note: this method should only be used for API response data and not user input +func ParseRouteIDInsensitively(input string) (*RouteId, error) { + parser := resourceids.NewParserFromResourceIdType(&RouteId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RouteId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RouteId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.AfdEndpointName, ok = input.Parsed["afdEndpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "afdEndpointName", input) + } + + if id.RouteName, ok = input.Parsed["routeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "routeName", input) + } + + return nil +} + +// ValidateRouteID checks that 'input' can be parsed as a Route ID +func ValidateRouteID(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 := ParseRouteID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Route ID +func (id RouteId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/afdEndpoints/%s/routes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.AfdEndpointName, id.RouteName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Route ID +func (id RouteId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticAfdEndpoints", "afdEndpoints", "afdEndpoints"), + resourceids.UserSpecifiedSegment("afdEndpointName", "afdEndpointValue"), + resourceids.StaticSegment("staticRoutes", "routes", "routes"), + resourceids.UserSpecifiedSegment("routeName", "routeValue"), + } +} + +// String returns a human-readable description of this Route ID +func (id RouteId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Afd Endpoint Name: %q", id.AfdEndpointName), + fmt.Sprintf("Route Name: %q", id.RouteName), + } + return fmt.Sprintf("Route (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/routes/id_route_test.go b/resource-manager/cdn/2024-02-01/routes/id_route_test.go new file mode 100644 index 00000000000..f4de3b2a2c7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/id_route_test.go @@ -0,0 +1,372 @@ +package routes + +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 = &RouteId{} + +func TestNewRouteID(t *testing.T) { + id := NewRouteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue", "routeValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.AfdEndpointName != "afdEndpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'AfdEndpointName'", id.AfdEndpointName, "afdEndpointValue") + } + + if id.RouteName != "routeValue" { + t.Fatalf("Expected %q but got %q for Segment 'RouteName'", id.RouteName, "routeValue") + } +} + +func TestFormatRouteID(t *testing.T) { + actual := NewRouteID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "afdEndpointValue", "routeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/routes/routeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRouteID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RouteId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/routes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/routes/routeValue", + Expected: &RouteId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + AfdEndpointName: "afdEndpointValue", + RouteName: "routeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/routes/routeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRouteID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.AfdEndpointName != v.Expected.AfdEndpointName { + t.Fatalf("Expected %q but got %q for AfdEndpointName", v.Expected.AfdEndpointName, actual.AfdEndpointName) + } + + if actual.RouteName != v.Expected.RouteName { + t.Fatalf("Expected %q but got %q for RouteName", v.Expected.RouteName, actual.RouteName) + } + + } +} + +func TestParseRouteIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RouteId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/routes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE/rOuTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/routes/routeValue", + Expected: &RouteId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + AfdEndpointName: "afdEndpointValue", + RouteName: "routeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/afdEndpoints/afdEndpointValue/routes/routeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE/rOuTeS/rOuTeVaLuE", + Expected: &RouteId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + AfdEndpointName: "aFdEnDpOiNtVaLuE", + RouteName: "rOuTeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/aFdEnDpOiNtS/aFdEnDpOiNtVaLuE/rOuTeS/rOuTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRouteIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.AfdEndpointName != v.Expected.AfdEndpointName { + t.Fatalf("Expected %q but got %q for AfdEndpointName", v.Expected.AfdEndpointName, actual.AfdEndpointName) + } + + if actual.RouteName != v.Expected.RouteName { + t.Fatalf("Expected %q but got %q for RouteName", v.Expected.RouteName, actual.RouteName) + } + + } +} + +func TestSegmentsForRouteId(t *testing.T) { + segments := RouteId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RouteId 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/cdn/2024-02-01/routes/method_create.go b/resource-manager/cdn/2024-02-01/routes/method_create.go new file mode 100644 index 00000000000..a2df43fefb7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/method_create.go @@ -0,0 +1,76 @@ +package routes + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Route +} + +// Create ... +func (c RoutesClient) Create(ctx context.Context, id RouteId, input Route) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c RoutesClient) CreateThenPoll(ctx context.Context, id RouteId, input Route) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/routes/method_delete.go b/resource-manager/cdn/2024-02-01/routes/method_delete.go new file mode 100644 index 00000000000..f6cee23c133 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/method_delete.go @@ -0,0 +1,71 @@ +package routes + +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 RoutesClient) Delete(ctx context.Context, id RouteId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c RoutesClient) DeleteThenPoll(ctx context.Context, id RouteId) 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/cdn/2024-02-01/routes/method_get.go b/resource-manager/cdn/2024-02-01/routes/method_get.go new file mode 100644 index 00000000000..8f641d28c5b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/method_get.go @@ -0,0 +1,54 @@ +package routes + +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 *Route +} + +// Get ... +func (c RoutesClient) Get(ctx context.Context, id RouteId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Route + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/routes/method_listbyendpoint.go b/resource-manager/cdn/2024-02-01/routes/method_listbyendpoint.go new file mode 100644 index 00000000000..ecac0980ee1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/method_listbyendpoint.go @@ -0,0 +1,105 @@ +package routes + +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 ListByEndpointOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Route +} + +type ListByEndpointCompleteResult struct { + LatestHttpResponse *http.Response + Items []Route +} + +type ListByEndpointCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByEndpointCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByEndpoint ... +func (c RoutesClient) ListByEndpoint(ctx context.Context, id AfdEndpointId) (result ListByEndpointOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByEndpointCustomPager{}, + Path: fmt.Sprintf("%s/routes", 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 *[]Route `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByEndpointComplete retrieves all the results into a single object +func (c RoutesClient) ListByEndpointComplete(ctx context.Context, id AfdEndpointId) (ListByEndpointCompleteResult, error) { + return c.ListByEndpointCompleteMatchingPredicate(ctx, id, RouteOperationPredicate{}) +} + +// ListByEndpointCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RoutesClient) ListByEndpointCompleteMatchingPredicate(ctx context.Context, id AfdEndpointId, predicate RouteOperationPredicate) (result ListByEndpointCompleteResult, err error) { + items := make([]Route, 0) + + resp, err := c.ListByEndpoint(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByEndpointCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/routes/method_update.go b/resource-manager/cdn/2024-02-01/routes/method_update.go new file mode 100644 index 00000000000..675feac0920 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/method_update.go @@ -0,0 +1,75 @@ +package routes + +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 + Model *Route +} + +// Update ... +func (c RoutesClient) Update(ctx context.Context, id RouteId, input RouteUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c RoutesClient) UpdateThenPoll(ctx context.Context, id RouteId, input RouteUpdateParameters) 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/cdn/2024-02-01/routes/model_activatedresourcereference.go b/resource-manager/cdn/2024-02-01/routes/model_activatedresourcereference.go new file mode 100644 index 00000000000..d8e6755a6d5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_activatedresourcereference.go @@ -0,0 +1,9 @@ +package routes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActivatedResourceReference struct { + Id *string `json:"id,omitempty"` + IsActive *bool `json:"isActive,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/routes/model_afdroutecacheconfiguration.go b/resource-manager/cdn/2024-02-01/routes/model_afdroutecacheconfiguration.go new file mode 100644 index 00000000000..958a2a2c8dc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_afdroutecacheconfiguration.go @@ -0,0 +1,10 @@ +package routes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AfdRouteCacheConfiguration struct { + CompressionSettings *CompressionSettings `json:"compressionSettings,omitempty"` + QueryParameters *string `json:"queryParameters,omitempty"` + QueryStringCachingBehavior *AfdQueryStringCachingBehavior `json:"queryStringCachingBehavior,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/routes/model_compressionsettings.go b/resource-manager/cdn/2024-02-01/routes/model_compressionsettings.go new file mode 100644 index 00000000000..a8bf44d6e7f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_compressionsettings.go @@ -0,0 +1,9 @@ +package routes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CompressionSettings struct { + ContentTypesToCompress *[]string `json:"contentTypesToCompress,omitempty"` + IsCompressionEnabled *bool `json:"isCompressionEnabled,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/routes/model_resourcereference.go b/resource-manager/cdn/2024-02-01/routes/model_resourcereference.go new file mode 100644 index 00000000000..a5bfb930279 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_resourcereference.go @@ -0,0 +1,8 @@ +package routes + +// 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/cdn/2024-02-01/routes/model_route.go b/resource-manager/cdn/2024-02-01/routes/model_route.go new file mode 100644 index 00000000000..aa2a2d24bad --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_route.go @@ -0,0 +1,16 @@ +package routes + +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 Route struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RouteProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/routes/model_routeproperties.go b/resource-manager/cdn/2024-02-01/routes/model_routeproperties.go new file mode 100644 index 00000000000..12df1741806 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_routeproperties.go @@ -0,0 +1,21 @@ +package routes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RouteProperties struct { + CacheConfiguration *AfdRouteCacheConfiguration `json:"cacheConfiguration,omitempty"` + CustomDomains *[]ActivatedResourceReference `json:"customDomains,omitempty"` + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + EnabledState *EnabledState `json:"enabledState,omitempty"` + EndpointName *string `json:"endpointName,omitempty"` + ForwardingProtocol *ForwardingProtocol `json:"forwardingProtocol,omitempty"` + HTTPSRedirect *HTTPSRedirect `json:"httpsRedirect,omitempty"` + LinkToDefaultDomain *LinkToDefaultDomain `json:"linkToDefaultDomain,omitempty"` + OriginGroup *ResourceReference `json:"originGroup,omitempty"` + OriginPath *string `json:"originPath,omitempty"` + PatternsToMatch *[]string `json:"patternsToMatch,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` + RuleSets *[]ResourceReference `json:"ruleSets,omitempty"` + SupportedProtocols *[]AFDEndpointProtocols `json:"supportedProtocols,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/routes/model_routeupdateparameters.go b/resource-manager/cdn/2024-02-01/routes/model_routeupdateparameters.go new file mode 100644 index 00000000000..8694841b13a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_routeupdateparameters.go @@ -0,0 +1,8 @@ +package routes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RouteUpdateParameters struct { + Properties *RouteUpdatePropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/routes/model_routeupdatepropertiesparameters.go b/resource-manager/cdn/2024-02-01/routes/model_routeupdatepropertiesparameters.go new file mode 100644 index 00000000000..bae7745f669 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/model_routeupdatepropertiesparameters.go @@ -0,0 +1,19 @@ +package routes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RouteUpdatePropertiesParameters struct { + CacheConfiguration *AfdRouteCacheConfiguration `json:"cacheConfiguration,omitempty"` + CustomDomains *[]ActivatedResourceReference `json:"customDomains,omitempty"` + EnabledState *EnabledState `json:"enabledState,omitempty"` + EndpointName *string `json:"endpointName,omitempty"` + ForwardingProtocol *ForwardingProtocol `json:"forwardingProtocol,omitempty"` + HTTPSRedirect *HTTPSRedirect `json:"httpsRedirect,omitempty"` + LinkToDefaultDomain *LinkToDefaultDomain `json:"linkToDefaultDomain,omitempty"` + OriginGroup *ResourceReference `json:"originGroup,omitempty"` + OriginPath *string `json:"originPath,omitempty"` + PatternsToMatch *[]string `json:"patternsToMatch,omitempty"` + RuleSets *[]ResourceReference `json:"ruleSets,omitempty"` + SupportedProtocols *[]AFDEndpointProtocols `json:"supportedProtocols,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/routes/predicates.go b/resource-manager/cdn/2024-02-01/routes/predicates.go new file mode 100644 index 00000000000..81b2f212359 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/predicates.go @@ -0,0 +1,27 @@ +package routes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RouteOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RouteOperationPredicate) Matches(input Route) 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/cdn/2024-02-01/routes/version.go b/resource-manager/cdn/2024-02-01/routes/version.go new file mode 100644 index 00000000000..6d4c5bcd427 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/routes/version.go @@ -0,0 +1,12 @@ +package routes + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/routes/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/rules/README.md b/resource-manager/cdn/2024-02-01/rules/README.md new file mode 100644 index 00000000000..5376024e84d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/rules` Documentation + +The `rules` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/rules" +``` + + +### Client Initialization + +```go +client := rules.NewRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RulesClient.Create` + +```go +ctx := context.TODO() +id := rules.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue", "ruleValue") + +payload := rules.Rule{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RulesClient.Delete` + +```go +ctx := context.TODO() +id := rules.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue", "ruleValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RulesClient.Get` + +```go +ctx := context.TODO() +id := rules.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue", "ruleValue") + +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: `RulesClient.ListByRuleSet` + +```go +ctx := context.TODO() +id := rules.NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue") + +// alternatively `client.ListByRuleSet(ctx, id)` can be used to do batched pagination +items, err := client.ListByRuleSetComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RulesClient.Update` + +```go +ctx := context.TODO() +id := rules.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue", "ruleValue") + +payload := rules.RuleUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/rules/client.go b/resource-manager/cdn/2024-02-01/rules/client.go new file mode 100644 index 00000000000..d145cf8c38a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/client.go @@ -0,0 +1,26 @@ +package rules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RulesClient struct { + Client *resourcemanager.Client +} + +func NewRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*RulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "rules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RulesClient: %+v", err) + } + + return &RulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/constants.go b/resource-manager/cdn/2024-02-01/rules/constants.go new file mode 100644 index 00000000000..5a6cc728f67 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/constants.go @@ -0,0 +1,2268 @@ +package rules + +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 AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type Algorithm string + +const ( + AlgorithmSHATwoFiveSix Algorithm = "SHA256" +) + +func PossibleValuesForAlgorithm() []string { + return []string{ + string(AlgorithmSHATwoFiveSix), + } +} + +func (s *Algorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlgorithm(input string) (*Algorithm, error) { + vals := map[string]Algorithm{ + "sha256": AlgorithmSHATwoFiveSix, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Algorithm(input) + return &out, nil +} + +type CacheBehavior string + +const ( + CacheBehaviorBypassCache CacheBehavior = "BypassCache" + CacheBehaviorOverride CacheBehavior = "Override" + CacheBehaviorSetIfMissing CacheBehavior = "SetIfMissing" +) + +func PossibleValuesForCacheBehavior() []string { + return []string{ + string(CacheBehaviorBypassCache), + string(CacheBehaviorOverride), + string(CacheBehaviorSetIfMissing), + } +} + +func (s *CacheBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCacheBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCacheBehavior(input string) (*CacheBehavior, error) { + vals := map[string]CacheBehavior{ + "bypasscache": CacheBehaviorBypassCache, + "override": CacheBehaviorOverride, + "setifmissing": CacheBehaviorSetIfMissing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CacheBehavior(input) + return &out, nil +} + +type CacheType string + +const ( + CacheTypeAll CacheType = "All" +) + +func PossibleValuesForCacheType() []string { + return []string{ + string(CacheTypeAll), + } +} + +func (s *CacheType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCacheType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCacheType(input string) (*CacheType, error) { + vals := map[string]CacheType{ + "all": CacheTypeAll, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CacheType(input) + return &out, nil +} + +type ClientPortOperator string + +const ( + ClientPortOperatorAny ClientPortOperator = "Any" + ClientPortOperatorBeginsWith ClientPortOperator = "BeginsWith" + ClientPortOperatorContains ClientPortOperator = "Contains" + ClientPortOperatorEndsWith ClientPortOperator = "EndsWith" + ClientPortOperatorEqual ClientPortOperator = "Equal" + ClientPortOperatorGreaterThan ClientPortOperator = "GreaterThan" + ClientPortOperatorGreaterThanOrEqual ClientPortOperator = "GreaterThanOrEqual" + ClientPortOperatorLessThan ClientPortOperator = "LessThan" + ClientPortOperatorLessThanOrEqual ClientPortOperator = "LessThanOrEqual" + ClientPortOperatorRegEx ClientPortOperator = "RegEx" +) + +func PossibleValuesForClientPortOperator() []string { + return []string{ + string(ClientPortOperatorAny), + string(ClientPortOperatorBeginsWith), + string(ClientPortOperatorContains), + string(ClientPortOperatorEndsWith), + string(ClientPortOperatorEqual), + string(ClientPortOperatorGreaterThan), + string(ClientPortOperatorGreaterThanOrEqual), + string(ClientPortOperatorLessThan), + string(ClientPortOperatorLessThanOrEqual), + string(ClientPortOperatorRegEx), + } +} + +func (s *ClientPortOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientPortOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientPortOperator(input string) (*ClientPortOperator, error) { + vals := map[string]ClientPortOperator{ + "any": ClientPortOperatorAny, + "beginswith": ClientPortOperatorBeginsWith, + "contains": ClientPortOperatorContains, + "endswith": ClientPortOperatorEndsWith, + "equal": ClientPortOperatorEqual, + "greaterthan": ClientPortOperatorGreaterThan, + "greaterthanorequal": ClientPortOperatorGreaterThanOrEqual, + "lessthan": ClientPortOperatorLessThan, + "lessthanorequal": ClientPortOperatorLessThanOrEqual, + "regex": ClientPortOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientPortOperator(input) + return &out, nil +} + +type CookiesOperator string + +const ( + CookiesOperatorAny CookiesOperator = "Any" + CookiesOperatorBeginsWith CookiesOperator = "BeginsWith" + CookiesOperatorContains CookiesOperator = "Contains" + CookiesOperatorEndsWith CookiesOperator = "EndsWith" + CookiesOperatorEqual CookiesOperator = "Equal" + CookiesOperatorGreaterThan CookiesOperator = "GreaterThan" + CookiesOperatorGreaterThanOrEqual CookiesOperator = "GreaterThanOrEqual" + CookiesOperatorLessThan CookiesOperator = "LessThan" + CookiesOperatorLessThanOrEqual CookiesOperator = "LessThanOrEqual" + CookiesOperatorRegEx CookiesOperator = "RegEx" +) + +func PossibleValuesForCookiesOperator() []string { + return []string{ + string(CookiesOperatorAny), + string(CookiesOperatorBeginsWith), + string(CookiesOperatorContains), + string(CookiesOperatorEndsWith), + string(CookiesOperatorEqual), + string(CookiesOperatorGreaterThan), + string(CookiesOperatorGreaterThanOrEqual), + string(CookiesOperatorLessThan), + string(CookiesOperatorLessThanOrEqual), + string(CookiesOperatorRegEx), + } +} + +func (s *CookiesOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCookiesOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCookiesOperator(input string) (*CookiesOperator, error) { + vals := map[string]CookiesOperator{ + "any": CookiesOperatorAny, + "beginswith": CookiesOperatorBeginsWith, + "contains": CookiesOperatorContains, + "endswith": CookiesOperatorEndsWith, + "equal": CookiesOperatorEqual, + "greaterthan": CookiesOperatorGreaterThan, + "greaterthanorequal": CookiesOperatorGreaterThanOrEqual, + "lessthan": CookiesOperatorLessThan, + "lessthanorequal": CookiesOperatorLessThanOrEqual, + "regex": CookiesOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CookiesOperator(input) + return &out, nil +} + +type DeliveryRuleActionName string + +const ( + DeliveryRuleActionNameCacheExpiration DeliveryRuleActionName = "CacheExpiration" + DeliveryRuleActionNameCacheKeyQueryString DeliveryRuleActionName = "CacheKeyQueryString" + DeliveryRuleActionNameModifyRequestHeader DeliveryRuleActionName = "ModifyRequestHeader" + DeliveryRuleActionNameModifyResponseHeader DeliveryRuleActionName = "ModifyResponseHeader" + DeliveryRuleActionNameOriginGroupOverride DeliveryRuleActionName = "OriginGroupOverride" + DeliveryRuleActionNameRouteConfigurationOverride DeliveryRuleActionName = "RouteConfigurationOverride" + DeliveryRuleActionNameUrlRedirect DeliveryRuleActionName = "UrlRedirect" + DeliveryRuleActionNameUrlRewrite DeliveryRuleActionName = "UrlRewrite" + DeliveryRuleActionNameUrlSigning DeliveryRuleActionName = "UrlSigning" +) + +func PossibleValuesForDeliveryRuleActionName() []string { + return []string{ + string(DeliveryRuleActionNameCacheExpiration), + string(DeliveryRuleActionNameCacheKeyQueryString), + string(DeliveryRuleActionNameModifyRequestHeader), + string(DeliveryRuleActionNameModifyResponseHeader), + string(DeliveryRuleActionNameOriginGroupOverride), + string(DeliveryRuleActionNameRouteConfigurationOverride), + string(DeliveryRuleActionNameUrlRedirect), + string(DeliveryRuleActionNameUrlRewrite), + string(DeliveryRuleActionNameUrlSigning), + } +} + +func (s *DeliveryRuleActionName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryRuleActionName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryRuleActionName(input string) (*DeliveryRuleActionName, error) { + vals := map[string]DeliveryRuleActionName{ + "cacheexpiration": DeliveryRuleActionNameCacheExpiration, + "cachekeyquerystring": DeliveryRuleActionNameCacheKeyQueryString, + "modifyrequestheader": DeliveryRuleActionNameModifyRequestHeader, + "modifyresponseheader": DeliveryRuleActionNameModifyResponseHeader, + "origingroupoverride": DeliveryRuleActionNameOriginGroupOverride, + "routeconfigurationoverride": DeliveryRuleActionNameRouteConfigurationOverride, + "urlredirect": DeliveryRuleActionNameUrlRedirect, + "urlrewrite": DeliveryRuleActionNameUrlRewrite, + "urlsigning": DeliveryRuleActionNameUrlSigning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryRuleActionName(input) + return &out, nil +} + +type DeliveryRuleActionParametersType string + +const ( + DeliveryRuleActionParametersTypeDeliveryRuleCacheExpirationActionParameters DeliveryRuleActionParametersType = "DeliveryRuleCacheExpirationActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleCacheKeyQueryStringBehaviorActionParameters DeliveryRuleActionParametersType = "DeliveryRuleCacheKeyQueryStringBehaviorActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleHeaderActionParameters DeliveryRuleActionParametersType = "DeliveryRuleHeaderActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleOriginGroupOverrideActionParameters DeliveryRuleActionParametersType = "DeliveryRuleOriginGroupOverrideActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleRouteConfigurationOverrideActionParameters DeliveryRuleActionParametersType = "DeliveryRuleRouteConfigurationOverrideActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleUrlRedirectActionParameters DeliveryRuleActionParametersType = "DeliveryRuleUrlRedirectActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleUrlRewriteActionParameters DeliveryRuleActionParametersType = "DeliveryRuleUrlRewriteActionParameters" + DeliveryRuleActionParametersTypeDeliveryRuleUrlSigningActionParameters DeliveryRuleActionParametersType = "DeliveryRuleUrlSigningActionParameters" +) + +func PossibleValuesForDeliveryRuleActionParametersType() []string { + return []string{ + string(DeliveryRuleActionParametersTypeDeliveryRuleCacheExpirationActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleCacheKeyQueryStringBehaviorActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleHeaderActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleOriginGroupOverrideActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleRouteConfigurationOverrideActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleUrlRedirectActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleUrlRewriteActionParameters), + string(DeliveryRuleActionParametersTypeDeliveryRuleUrlSigningActionParameters), + } +} + +func (s *DeliveryRuleActionParametersType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryRuleActionParametersType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryRuleActionParametersType(input string) (*DeliveryRuleActionParametersType, error) { + vals := map[string]DeliveryRuleActionParametersType{ + "deliveryrulecacheexpirationactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleCacheExpirationActionParameters, + "deliveryrulecachekeyquerystringbehavioractionparameters": DeliveryRuleActionParametersTypeDeliveryRuleCacheKeyQueryStringBehaviorActionParameters, + "deliveryruleheaderactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleHeaderActionParameters, + "deliveryruleorigingroupoverrideactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleOriginGroupOverrideActionParameters, + "deliveryrulerouteconfigurationoverrideactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleRouteConfigurationOverrideActionParameters, + "deliveryruleurlredirectactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleUrlRedirectActionParameters, + "deliveryruleurlrewriteactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleUrlRewriteActionParameters, + "deliveryruleurlsigningactionparameters": DeliveryRuleActionParametersTypeDeliveryRuleUrlSigningActionParameters, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryRuleActionParametersType(input) + return &out, nil +} + +type DeliveryRuleConditionParametersType string + +const ( + DeliveryRuleConditionParametersTypeDeliveryRuleClientPortConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleClientPortConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleCookiesConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleCookiesConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleHTTPVersionConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleHttpVersionConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleHostNameConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleHostNameConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleIsDeviceConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleIsDeviceConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRulePostArgsConditionParameters DeliveryRuleConditionParametersType = "DeliveryRulePostArgsConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleQueryStringConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleQueryStringConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRemoteAddressConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRemoteAddressConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestBodyConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestBodyConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestHeaderConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestHeaderConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestMethodConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestMethodConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestSchemeConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestSchemeConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleRequestUriConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleRequestUriConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleServerPortConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleServerPortConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleSocketAddrConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleSocketAddrConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleSslProtocolConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleSslProtocolConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleUrlFileExtensionMatchConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleUrlFileExtensionMatchConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleUrlFilenameConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleUrlFilenameConditionParameters" + DeliveryRuleConditionParametersTypeDeliveryRuleUrlPathMatchConditionParameters DeliveryRuleConditionParametersType = "DeliveryRuleUrlPathMatchConditionParameters" +) + +func PossibleValuesForDeliveryRuleConditionParametersType() []string { + return []string{ + string(DeliveryRuleConditionParametersTypeDeliveryRuleClientPortConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleCookiesConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleHTTPVersionConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleHostNameConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleIsDeviceConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRulePostArgsConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleQueryStringConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRemoteAddressConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestBodyConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestHeaderConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestMethodConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestSchemeConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleRequestUriConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleServerPortConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleSocketAddrConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleSslProtocolConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleUrlFileExtensionMatchConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleUrlFilenameConditionParameters), + string(DeliveryRuleConditionParametersTypeDeliveryRuleUrlPathMatchConditionParameters), + } +} + +func (s *DeliveryRuleConditionParametersType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryRuleConditionParametersType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryRuleConditionParametersType(input string) (*DeliveryRuleConditionParametersType, error) { + vals := map[string]DeliveryRuleConditionParametersType{ + "deliveryruleclientportconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleClientPortConditionParameters, + "deliveryrulecookiesconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleCookiesConditionParameters, + "deliveryrulehttpversionconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleHTTPVersionConditionParameters, + "deliveryrulehostnameconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleHostNameConditionParameters, + "deliveryruleisdeviceconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleIsDeviceConditionParameters, + "deliveryrulepostargsconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRulePostArgsConditionParameters, + "deliveryrulequerystringconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleQueryStringConditionParameters, + "deliveryruleremoteaddressconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRemoteAddressConditionParameters, + "deliveryrulerequestbodyconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestBodyConditionParameters, + "deliveryrulerequestheaderconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestHeaderConditionParameters, + "deliveryrulerequestmethodconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestMethodConditionParameters, + "deliveryrulerequestschemeconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestSchemeConditionParameters, + "deliveryrulerequesturiconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleRequestUriConditionParameters, + "deliveryruleserverportconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleServerPortConditionParameters, + "deliveryrulesocketaddrconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleSocketAddrConditionParameters, + "deliveryrulesslprotocolconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleSslProtocolConditionParameters, + "deliveryruleurlfileextensionmatchconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleUrlFileExtensionMatchConditionParameters, + "deliveryruleurlfilenameconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleUrlFilenameConditionParameters, + "deliveryruleurlpathmatchconditionparameters": DeliveryRuleConditionParametersTypeDeliveryRuleUrlPathMatchConditionParameters, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryRuleConditionParametersType(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type DestinationProtocol string + +const ( + DestinationProtocolHTTP DestinationProtocol = "Http" + DestinationProtocolHTTPS DestinationProtocol = "Https" + DestinationProtocolMatchRequest DestinationProtocol = "MatchRequest" +) + +func PossibleValuesForDestinationProtocol() []string { + return []string{ + string(DestinationProtocolHTTP), + string(DestinationProtocolHTTPS), + string(DestinationProtocolMatchRequest), + } +} + +func (s *DestinationProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDestinationProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDestinationProtocol(input string) (*DestinationProtocol, error) { + vals := map[string]DestinationProtocol{ + "http": DestinationProtocolHTTP, + "https": DestinationProtocolHTTPS, + "matchrequest": DestinationProtocolMatchRequest, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DestinationProtocol(input) + return &out, nil +} + +type ForwardingProtocol string + +const ( + ForwardingProtocolHTTPOnly ForwardingProtocol = "HttpOnly" + ForwardingProtocolHTTPSOnly ForwardingProtocol = "HttpsOnly" + ForwardingProtocolMatchRequest ForwardingProtocol = "MatchRequest" +) + +func PossibleValuesForForwardingProtocol() []string { + return []string{ + string(ForwardingProtocolHTTPOnly), + string(ForwardingProtocolHTTPSOnly), + string(ForwardingProtocolMatchRequest), + } +} + +func (s *ForwardingProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseForwardingProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseForwardingProtocol(input string) (*ForwardingProtocol, error) { + vals := map[string]ForwardingProtocol{ + "httponly": ForwardingProtocolHTTPOnly, + "httpsonly": ForwardingProtocolHTTPSOnly, + "matchrequest": ForwardingProtocolMatchRequest, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ForwardingProtocol(input) + return &out, nil +} + +type HTTPVersionOperator string + +const ( + HTTPVersionOperatorEqual HTTPVersionOperator = "Equal" +) + +func PossibleValuesForHTTPVersionOperator() []string { + return []string{ + string(HTTPVersionOperatorEqual), + } +} + +func (s *HTTPVersionOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHTTPVersionOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHTTPVersionOperator(input string) (*HTTPVersionOperator, error) { + vals := map[string]HTTPVersionOperator{ + "equal": HTTPVersionOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HTTPVersionOperator(input) + return &out, nil +} + +type HeaderAction string + +const ( + HeaderActionAppend HeaderAction = "Append" + HeaderActionDelete HeaderAction = "Delete" + HeaderActionOverwrite HeaderAction = "Overwrite" +) + +func PossibleValuesForHeaderAction() []string { + return []string{ + string(HeaderActionAppend), + string(HeaderActionDelete), + string(HeaderActionOverwrite), + } +} + +func (s *HeaderAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHeaderAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHeaderAction(input string) (*HeaderAction, error) { + vals := map[string]HeaderAction{ + "append": HeaderActionAppend, + "delete": HeaderActionDelete, + "overwrite": HeaderActionOverwrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HeaderAction(input) + return &out, nil +} + +type HostNameOperator string + +const ( + HostNameOperatorAny HostNameOperator = "Any" + HostNameOperatorBeginsWith HostNameOperator = "BeginsWith" + HostNameOperatorContains HostNameOperator = "Contains" + HostNameOperatorEndsWith HostNameOperator = "EndsWith" + HostNameOperatorEqual HostNameOperator = "Equal" + HostNameOperatorGreaterThan HostNameOperator = "GreaterThan" + HostNameOperatorGreaterThanOrEqual HostNameOperator = "GreaterThanOrEqual" + HostNameOperatorLessThan HostNameOperator = "LessThan" + HostNameOperatorLessThanOrEqual HostNameOperator = "LessThanOrEqual" + HostNameOperatorRegEx HostNameOperator = "RegEx" +) + +func PossibleValuesForHostNameOperator() []string { + return []string{ + string(HostNameOperatorAny), + string(HostNameOperatorBeginsWith), + string(HostNameOperatorContains), + string(HostNameOperatorEndsWith), + string(HostNameOperatorEqual), + string(HostNameOperatorGreaterThan), + string(HostNameOperatorGreaterThanOrEqual), + string(HostNameOperatorLessThan), + string(HostNameOperatorLessThanOrEqual), + string(HostNameOperatorRegEx), + } +} + +func (s *HostNameOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostNameOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHostNameOperator(input string) (*HostNameOperator, error) { + vals := map[string]HostNameOperator{ + "any": HostNameOperatorAny, + "beginswith": HostNameOperatorBeginsWith, + "contains": HostNameOperatorContains, + "endswith": HostNameOperatorEndsWith, + "equal": HostNameOperatorEqual, + "greaterthan": HostNameOperatorGreaterThan, + "greaterthanorequal": HostNameOperatorGreaterThanOrEqual, + "lessthan": HostNameOperatorLessThan, + "lessthanorequal": HostNameOperatorLessThanOrEqual, + "regex": HostNameOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostNameOperator(input) + return &out, nil +} + +type IsDeviceMatchValue string + +const ( + IsDeviceMatchValueDesktop IsDeviceMatchValue = "Desktop" + IsDeviceMatchValueMobile IsDeviceMatchValue = "Mobile" +) + +func PossibleValuesForIsDeviceMatchValue() []string { + return []string{ + string(IsDeviceMatchValueDesktop), + string(IsDeviceMatchValueMobile), + } +} + +func (s *IsDeviceMatchValue) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsDeviceMatchValue(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsDeviceMatchValue(input string) (*IsDeviceMatchValue, error) { + vals := map[string]IsDeviceMatchValue{ + "desktop": IsDeviceMatchValueDesktop, + "mobile": IsDeviceMatchValueMobile, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsDeviceMatchValue(input) + return &out, nil +} + +type IsDeviceOperator string + +const ( + IsDeviceOperatorEqual IsDeviceOperator = "Equal" +) + +func PossibleValuesForIsDeviceOperator() []string { + return []string{ + string(IsDeviceOperatorEqual), + } +} + +func (s *IsDeviceOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsDeviceOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsDeviceOperator(input string) (*IsDeviceOperator, error) { + vals := map[string]IsDeviceOperator{ + "equal": IsDeviceOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsDeviceOperator(input) + return &out, nil +} + +type MatchProcessingBehavior string + +const ( + MatchProcessingBehaviorContinue MatchProcessingBehavior = "Continue" + MatchProcessingBehaviorStop MatchProcessingBehavior = "Stop" +) + +func PossibleValuesForMatchProcessingBehavior() []string { + return []string{ + string(MatchProcessingBehaviorContinue), + string(MatchProcessingBehaviorStop), + } +} + +func (s *MatchProcessingBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchProcessingBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMatchProcessingBehavior(input string) (*MatchProcessingBehavior, error) { + vals := map[string]MatchProcessingBehavior{ + "continue": MatchProcessingBehaviorContinue, + "stop": MatchProcessingBehaviorStop, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MatchProcessingBehavior(input) + return &out, nil +} + +type MatchVariable string + +const ( + MatchVariableClientPort MatchVariable = "ClientPort" + MatchVariableCookies MatchVariable = "Cookies" + MatchVariableHTTPVersion MatchVariable = "HttpVersion" + MatchVariableHostName MatchVariable = "HostName" + MatchVariableIsDevice MatchVariable = "IsDevice" + MatchVariablePostArgs MatchVariable = "PostArgs" + MatchVariableQueryString MatchVariable = "QueryString" + MatchVariableRemoteAddress MatchVariable = "RemoteAddress" + MatchVariableRequestBody MatchVariable = "RequestBody" + MatchVariableRequestHeader MatchVariable = "RequestHeader" + MatchVariableRequestMethod MatchVariable = "RequestMethod" + MatchVariableRequestScheme MatchVariable = "RequestScheme" + MatchVariableRequestUri MatchVariable = "RequestUri" + MatchVariableServerPort MatchVariable = "ServerPort" + MatchVariableSocketAddr MatchVariable = "SocketAddr" + MatchVariableSslProtocol MatchVariable = "SslProtocol" + MatchVariableUrlFileExtension MatchVariable = "UrlFileExtension" + MatchVariableUrlFileName MatchVariable = "UrlFileName" + MatchVariableUrlPath MatchVariable = "UrlPath" +) + +func PossibleValuesForMatchVariable() []string { + return []string{ + string(MatchVariableClientPort), + string(MatchVariableCookies), + string(MatchVariableHTTPVersion), + string(MatchVariableHostName), + string(MatchVariableIsDevice), + string(MatchVariablePostArgs), + string(MatchVariableQueryString), + string(MatchVariableRemoteAddress), + string(MatchVariableRequestBody), + string(MatchVariableRequestHeader), + string(MatchVariableRequestMethod), + string(MatchVariableRequestScheme), + string(MatchVariableRequestUri), + string(MatchVariableServerPort), + string(MatchVariableSocketAddr), + string(MatchVariableSslProtocol), + string(MatchVariableUrlFileExtension), + string(MatchVariableUrlFileName), + string(MatchVariableUrlPath), + } +} + +func (s *MatchVariable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchVariable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMatchVariable(input string) (*MatchVariable, error) { + vals := map[string]MatchVariable{ + "clientport": MatchVariableClientPort, + "cookies": MatchVariableCookies, + "httpversion": MatchVariableHTTPVersion, + "hostname": MatchVariableHostName, + "isdevice": MatchVariableIsDevice, + "postargs": MatchVariablePostArgs, + "querystring": MatchVariableQueryString, + "remoteaddress": MatchVariableRemoteAddress, + "requestbody": MatchVariableRequestBody, + "requestheader": MatchVariableRequestHeader, + "requestmethod": MatchVariableRequestMethod, + "requestscheme": MatchVariableRequestScheme, + "requesturi": MatchVariableRequestUri, + "serverport": MatchVariableServerPort, + "socketaddr": MatchVariableSocketAddr, + "sslprotocol": MatchVariableSslProtocol, + "urlfileextension": MatchVariableUrlFileExtension, + "urlfilename": MatchVariableUrlFileName, + "urlpath": MatchVariableUrlPath, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MatchVariable(input) + return &out, nil +} + +type Operator string + +const ( + OperatorEqual Operator = "Equal" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorEqual), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "equal": OperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type ParamIndicator string + +const ( + ParamIndicatorExpires ParamIndicator = "Expires" + ParamIndicatorKeyId ParamIndicator = "KeyId" + ParamIndicatorSignature ParamIndicator = "Signature" +) + +func PossibleValuesForParamIndicator() []string { + return []string{ + string(ParamIndicatorExpires), + string(ParamIndicatorKeyId), + string(ParamIndicatorSignature), + } +} + +func (s *ParamIndicator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseParamIndicator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseParamIndicator(input string) (*ParamIndicator, error) { + vals := map[string]ParamIndicator{ + "expires": ParamIndicatorExpires, + "keyid": ParamIndicatorKeyId, + "signature": ParamIndicatorSignature, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ParamIndicator(input) + return &out, nil +} + +type PostArgsOperator string + +const ( + PostArgsOperatorAny PostArgsOperator = "Any" + PostArgsOperatorBeginsWith PostArgsOperator = "BeginsWith" + PostArgsOperatorContains PostArgsOperator = "Contains" + PostArgsOperatorEndsWith PostArgsOperator = "EndsWith" + PostArgsOperatorEqual PostArgsOperator = "Equal" + PostArgsOperatorGreaterThan PostArgsOperator = "GreaterThan" + PostArgsOperatorGreaterThanOrEqual PostArgsOperator = "GreaterThanOrEqual" + PostArgsOperatorLessThan PostArgsOperator = "LessThan" + PostArgsOperatorLessThanOrEqual PostArgsOperator = "LessThanOrEqual" + PostArgsOperatorRegEx PostArgsOperator = "RegEx" +) + +func PossibleValuesForPostArgsOperator() []string { + return []string{ + string(PostArgsOperatorAny), + string(PostArgsOperatorBeginsWith), + string(PostArgsOperatorContains), + string(PostArgsOperatorEndsWith), + string(PostArgsOperatorEqual), + string(PostArgsOperatorGreaterThan), + string(PostArgsOperatorGreaterThanOrEqual), + string(PostArgsOperatorLessThan), + string(PostArgsOperatorLessThanOrEqual), + string(PostArgsOperatorRegEx), + } +} + +func (s *PostArgsOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePostArgsOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePostArgsOperator(input string) (*PostArgsOperator, error) { + vals := map[string]PostArgsOperator{ + "any": PostArgsOperatorAny, + "beginswith": PostArgsOperatorBeginsWith, + "contains": PostArgsOperatorContains, + "endswith": PostArgsOperatorEndsWith, + "equal": PostArgsOperatorEqual, + "greaterthan": PostArgsOperatorGreaterThan, + "greaterthanorequal": PostArgsOperatorGreaterThanOrEqual, + "lessthan": PostArgsOperatorLessThan, + "lessthanorequal": PostArgsOperatorLessThanOrEqual, + "regex": PostArgsOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PostArgsOperator(input) + return &out, nil +} + +type QueryStringBehavior string + +const ( + QueryStringBehaviorExclude QueryStringBehavior = "Exclude" + QueryStringBehaviorExcludeAll QueryStringBehavior = "ExcludeAll" + QueryStringBehaviorInclude QueryStringBehavior = "Include" + QueryStringBehaviorIncludeAll QueryStringBehavior = "IncludeAll" +) + +func PossibleValuesForQueryStringBehavior() []string { + return []string{ + string(QueryStringBehaviorExclude), + string(QueryStringBehaviorExcludeAll), + string(QueryStringBehaviorInclude), + string(QueryStringBehaviorIncludeAll), + } +} + +func (s *QueryStringBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryStringBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryStringBehavior(input string) (*QueryStringBehavior, error) { + vals := map[string]QueryStringBehavior{ + "exclude": QueryStringBehaviorExclude, + "excludeall": QueryStringBehaviorExcludeAll, + "include": QueryStringBehaviorInclude, + "includeall": QueryStringBehaviorIncludeAll, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryStringBehavior(input) + return &out, nil +} + +type QueryStringOperator string + +const ( + QueryStringOperatorAny QueryStringOperator = "Any" + QueryStringOperatorBeginsWith QueryStringOperator = "BeginsWith" + QueryStringOperatorContains QueryStringOperator = "Contains" + QueryStringOperatorEndsWith QueryStringOperator = "EndsWith" + QueryStringOperatorEqual QueryStringOperator = "Equal" + QueryStringOperatorGreaterThan QueryStringOperator = "GreaterThan" + QueryStringOperatorGreaterThanOrEqual QueryStringOperator = "GreaterThanOrEqual" + QueryStringOperatorLessThan QueryStringOperator = "LessThan" + QueryStringOperatorLessThanOrEqual QueryStringOperator = "LessThanOrEqual" + QueryStringOperatorRegEx QueryStringOperator = "RegEx" +) + +func PossibleValuesForQueryStringOperator() []string { + return []string{ + string(QueryStringOperatorAny), + string(QueryStringOperatorBeginsWith), + string(QueryStringOperatorContains), + string(QueryStringOperatorEndsWith), + string(QueryStringOperatorEqual), + string(QueryStringOperatorGreaterThan), + string(QueryStringOperatorGreaterThanOrEqual), + string(QueryStringOperatorLessThan), + string(QueryStringOperatorLessThanOrEqual), + string(QueryStringOperatorRegEx), + } +} + +func (s *QueryStringOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryStringOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryStringOperator(input string) (*QueryStringOperator, error) { + vals := map[string]QueryStringOperator{ + "any": QueryStringOperatorAny, + "beginswith": QueryStringOperatorBeginsWith, + "contains": QueryStringOperatorContains, + "endswith": QueryStringOperatorEndsWith, + "equal": QueryStringOperatorEqual, + "greaterthan": QueryStringOperatorGreaterThan, + "greaterthanorequal": QueryStringOperatorGreaterThanOrEqual, + "lessthan": QueryStringOperatorLessThan, + "lessthanorequal": QueryStringOperatorLessThanOrEqual, + "regex": QueryStringOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryStringOperator(input) + return &out, nil +} + +type RedirectType string + +const ( + RedirectTypeFound RedirectType = "Found" + RedirectTypeMoved RedirectType = "Moved" + RedirectTypePermanentRedirect RedirectType = "PermanentRedirect" + RedirectTypeTemporaryRedirect RedirectType = "TemporaryRedirect" +) + +func PossibleValuesForRedirectType() []string { + return []string{ + string(RedirectTypeFound), + string(RedirectTypeMoved), + string(RedirectTypePermanentRedirect), + string(RedirectTypeTemporaryRedirect), + } +} + +func (s *RedirectType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRedirectType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRedirectType(input string) (*RedirectType, error) { + vals := map[string]RedirectType{ + "found": RedirectTypeFound, + "moved": RedirectTypeMoved, + "permanentredirect": RedirectTypePermanentRedirect, + "temporaryredirect": RedirectTypeTemporaryRedirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RedirectType(input) + return &out, nil +} + +type RemoteAddressOperator string + +const ( + RemoteAddressOperatorAny RemoteAddressOperator = "Any" + RemoteAddressOperatorGeoMatch RemoteAddressOperator = "GeoMatch" + RemoteAddressOperatorIPMatch RemoteAddressOperator = "IPMatch" +) + +func PossibleValuesForRemoteAddressOperator() []string { + return []string{ + string(RemoteAddressOperatorAny), + string(RemoteAddressOperatorGeoMatch), + string(RemoteAddressOperatorIPMatch), + } +} + +func (s *RemoteAddressOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRemoteAddressOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRemoteAddressOperator(input string) (*RemoteAddressOperator, error) { + vals := map[string]RemoteAddressOperator{ + "any": RemoteAddressOperatorAny, + "geomatch": RemoteAddressOperatorGeoMatch, + "ipmatch": RemoteAddressOperatorIPMatch, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RemoteAddressOperator(input) + return &out, nil +} + +type RequestBodyOperator string + +const ( + RequestBodyOperatorAny RequestBodyOperator = "Any" + RequestBodyOperatorBeginsWith RequestBodyOperator = "BeginsWith" + RequestBodyOperatorContains RequestBodyOperator = "Contains" + RequestBodyOperatorEndsWith RequestBodyOperator = "EndsWith" + RequestBodyOperatorEqual RequestBodyOperator = "Equal" + RequestBodyOperatorGreaterThan RequestBodyOperator = "GreaterThan" + RequestBodyOperatorGreaterThanOrEqual RequestBodyOperator = "GreaterThanOrEqual" + RequestBodyOperatorLessThan RequestBodyOperator = "LessThan" + RequestBodyOperatorLessThanOrEqual RequestBodyOperator = "LessThanOrEqual" + RequestBodyOperatorRegEx RequestBodyOperator = "RegEx" +) + +func PossibleValuesForRequestBodyOperator() []string { + return []string{ + string(RequestBodyOperatorAny), + string(RequestBodyOperatorBeginsWith), + string(RequestBodyOperatorContains), + string(RequestBodyOperatorEndsWith), + string(RequestBodyOperatorEqual), + string(RequestBodyOperatorGreaterThan), + string(RequestBodyOperatorGreaterThanOrEqual), + string(RequestBodyOperatorLessThan), + string(RequestBodyOperatorLessThanOrEqual), + string(RequestBodyOperatorRegEx), + } +} + +func (s *RequestBodyOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestBodyOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestBodyOperator(input string) (*RequestBodyOperator, error) { + vals := map[string]RequestBodyOperator{ + "any": RequestBodyOperatorAny, + "beginswith": RequestBodyOperatorBeginsWith, + "contains": RequestBodyOperatorContains, + "endswith": RequestBodyOperatorEndsWith, + "equal": RequestBodyOperatorEqual, + "greaterthan": RequestBodyOperatorGreaterThan, + "greaterthanorequal": RequestBodyOperatorGreaterThanOrEqual, + "lessthan": RequestBodyOperatorLessThan, + "lessthanorequal": RequestBodyOperatorLessThanOrEqual, + "regex": RequestBodyOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestBodyOperator(input) + return &out, nil +} + +type RequestHeaderOperator string + +const ( + RequestHeaderOperatorAny RequestHeaderOperator = "Any" + RequestHeaderOperatorBeginsWith RequestHeaderOperator = "BeginsWith" + RequestHeaderOperatorContains RequestHeaderOperator = "Contains" + RequestHeaderOperatorEndsWith RequestHeaderOperator = "EndsWith" + RequestHeaderOperatorEqual RequestHeaderOperator = "Equal" + RequestHeaderOperatorGreaterThan RequestHeaderOperator = "GreaterThan" + RequestHeaderOperatorGreaterThanOrEqual RequestHeaderOperator = "GreaterThanOrEqual" + RequestHeaderOperatorLessThan RequestHeaderOperator = "LessThan" + RequestHeaderOperatorLessThanOrEqual RequestHeaderOperator = "LessThanOrEqual" + RequestHeaderOperatorRegEx RequestHeaderOperator = "RegEx" +) + +func PossibleValuesForRequestHeaderOperator() []string { + return []string{ + string(RequestHeaderOperatorAny), + string(RequestHeaderOperatorBeginsWith), + string(RequestHeaderOperatorContains), + string(RequestHeaderOperatorEndsWith), + string(RequestHeaderOperatorEqual), + string(RequestHeaderOperatorGreaterThan), + string(RequestHeaderOperatorGreaterThanOrEqual), + string(RequestHeaderOperatorLessThan), + string(RequestHeaderOperatorLessThanOrEqual), + string(RequestHeaderOperatorRegEx), + } +} + +func (s *RequestHeaderOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestHeaderOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestHeaderOperator(input string) (*RequestHeaderOperator, error) { + vals := map[string]RequestHeaderOperator{ + "any": RequestHeaderOperatorAny, + "beginswith": RequestHeaderOperatorBeginsWith, + "contains": RequestHeaderOperatorContains, + "endswith": RequestHeaderOperatorEndsWith, + "equal": RequestHeaderOperatorEqual, + "greaterthan": RequestHeaderOperatorGreaterThan, + "greaterthanorequal": RequestHeaderOperatorGreaterThanOrEqual, + "lessthan": RequestHeaderOperatorLessThan, + "lessthanorequal": RequestHeaderOperatorLessThanOrEqual, + "regex": RequestHeaderOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestHeaderOperator(input) + return &out, nil +} + +type RequestMethodMatchValue string + +const ( + RequestMethodMatchValueDELETE RequestMethodMatchValue = "DELETE" + RequestMethodMatchValueGET RequestMethodMatchValue = "GET" + RequestMethodMatchValueHEAD RequestMethodMatchValue = "HEAD" + RequestMethodMatchValueOPTIONS RequestMethodMatchValue = "OPTIONS" + RequestMethodMatchValuePOST RequestMethodMatchValue = "POST" + RequestMethodMatchValuePUT RequestMethodMatchValue = "PUT" + RequestMethodMatchValueTRACE RequestMethodMatchValue = "TRACE" +) + +func PossibleValuesForRequestMethodMatchValue() []string { + return []string{ + string(RequestMethodMatchValueDELETE), + string(RequestMethodMatchValueGET), + string(RequestMethodMatchValueHEAD), + string(RequestMethodMatchValueOPTIONS), + string(RequestMethodMatchValuePOST), + string(RequestMethodMatchValuePUT), + string(RequestMethodMatchValueTRACE), + } +} + +func (s *RequestMethodMatchValue) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestMethodMatchValue(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestMethodMatchValue(input string) (*RequestMethodMatchValue, error) { + vals := map[string]RequestMethodMatchValue{ + "delete": RequestMethodMatchValueDELETE, + "get": RequestMethodMatchValueGET, + "head": RequestMethodMatchValueHEAD, + "options": RequestMethodMatchValueOPTIONS, + "post": RequestMethodMatchValuePOST, + "put": RequestMethodMatchValuePUT, + "trace": RequestMethodMatchValueTRACE, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestMethodMatchValue(input) + return &out, nil +} + +type RequestMethodOperator string + +const ( + RequestMethodOperatorEqual RequestMethodOperator = "Equal" +) + +func PossibleValuesForRequestMethodOperator() []string { + return []string{ + string(RequestMethodOperatorEqual), + } +} + +func (s *RequestMethodOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestMethodOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestMethodOperator(input string) (*RequestMethodOperator, error) { + vals := map[string]RequestMethodOperator{ + "equal": RequestMethodOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestMethodOperator(input) + return &out, nil +} + +type RequestSchemeMatchValue string + +const ( + RequestSchemeMatchValueHTTP RequestSchemeMatchValue = "HTTP" + RequestSchemeMatchValueHTTPS RequestSchemeMatchValue = "HTTPS" +) + +func PossibleValuesForRequestSchemeMatchValue() []string { + return []string{ + string(RequestSchemeMatchValueHTTP), + string(RequestSchemeMatchValueHTTPS), + } +} + +func (s *RequestSchemeMatchValue) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestSchemeMatchValue(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestSchemeMatchValue(input string) (*RequestSchemeMatchValue, error) { + vals := map[string]RequestSchemeMatchValue{ + "http": RequestSchemeMatchValueHTTP, + "https": RequestSchemeMatchValueHTTPS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestSchemeMatchValue(input) + return &out, nil +} + +type RequestUriOperator string + +const ( + RequestUriOperatorAny RequestUriOperator = "Any" + RequestUriOperatorBeginsWith RequestUriOperator = "BeginsWith" + RequestUriOperatorContains RequestUriOperator = "Contains" + RequestUriOperatorEndsWith RequestUriOperator = "EndsWith" + RequestUriOperatorEqual RequestUriOperator = "Equal" + RequestUriOperatorGreaterThan RequestUriOperator = "GreaterThan" + RequestUriOperatorGreaterThanOrEqual RequestUriOperator = "GreaterThanOrEqual" + RequestUriOperatorLessThan RequestUriOperator = "LessThan" + RequestUriOperatorLessThanOrEqual RequestUriOperator = "LessThanOrEqual" + RequestUriOperatorRegEx RequestUriOperator = "RegEx" +) + +func PossibleValuesForRequestUriOperator() []string { + return []string{ + string(RequestUriOperatorAny), + string(RequestUriOperatorBeginsWith), + string(RequestUriOperatorContains), + string(RequestUriOperatorEndsWith), + string(RequestUriOperatorEqual), + string(RequestUriOperatorGreaterThan), + string(RequestUriOperatorGreaterThanOrEqual), + string(RequestUriOperatorLessThan), + string(RequestUriOperatorLessThanOrEqual), + string(RequestUriOperatorRegEx), + } +} + +func (s *RequestUriOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRequestUriOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRequestUriOperator(input string) (*RequestUriOperator, error) { + vals := map[string]RequestUriOperator{ + "any": RequestUriOperatorAny, + "beginswith": RequestUriOperatorBeginsWith, + "contains": RequestUriOperatorContains, + "endswith": RequestUriOperatorEndsWith, + "equal": RequestUriOperatorEqual, + "greaterthan": RequestUriOperatorGreaterThan, + "greaterthanorequal": RequestUriOperatorGreaterThanOrEqual, + "lessthan": RequestUriOperatorLessThan, + "lessthanorequal": RequestUriOperatorLessThanOrEqual, + "regex": RequestUriOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RequestUriOperator(input) + return &out, nil +} + +type RuleCacheBehavior string + +const ( + RuleCacheBehaviorHonorOrigin RuleCacheBehavior = "HonorOrigin" + RuleCacheBehaviorOverrideAlways RuleCacheBehavior = "OverrideAlways" + RuleCacheBehaviorOverrideIfOriginMissing RuleCacheBehavior = "OverrideIfOriginMissing" +) + +func PossibleValuesForRuleCacheBehavior() []string { + return []string{ + string(RuleCacheBehaviorHonorOrigin), + string(RuleCacheBehaviorOverrideAlways), + string(RuleCacheBehaviorOverrideIfOriginMissing), + } +} + +func (s *RuleCacheBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleCacheBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleCacheBehavior(input string) (*RuleCacheBehavior, error) { + vals := map[string]RuleCacheBehavior{ + "honororigin": RuleCacheBehaviorHonorOrigin, + "overridealways": RuleCacheBehaviorOverrideAlways, + "overrideiforiginmissing": RuleCacheBehaviorOverrideIfOriginMissing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleCacheBehavior(input) + return &out, nil +} + +type RuleIsCompressionEnabled string + +const ( + RuleIsCompressionEnabledDisabled RuleIsCompressionEnabled = "Disabled" + RuleIsCompressionEnabledEnabled RuleIsCompressionEnabled = "Enabled" +) + +func PossibleValuesForRuleIsCompressionEnabled() []string { + return []string{ + string(RuleIsCompressionEnabledDisabled), + string(RuleIsCompressionEnabledEnabled), + } +} + +func (s *RuleIsCompressionEnabled) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleIsCompressionEnabled(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleIsCompressionEnabled(input string) (*RuleIsCompressionEnabled, error) { + vals := map[string]RuleIsCompressionEnabled{ + "disabled": RuleIsCompressionEnabledDisabled, + "enabled": RuleIsCompressionEnabledEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleIsCompressionEnabled(input) + return &out, nil +} + +type RuleQueryStringCachingBehavior string + +const ( + RuleQueryStringCachingBehaviorIgnoreQueryString RuleQueryStringCachingBehavior = "IgnoreQueryString" + RuleQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings RuleQueryStringCachingBehavior = "IgnoreSpecifiedQueryStrings" + RuleQueryStringCachingBehaviorIncludeSpecifiedQueryStrings RuleQueryStringCachingBehavior = "IncludeSpecifiedQueryStrings" + RuleQueryStringCachingBehaviorUseQueryString RuleQueryStringCachingBehavior = "UseQueryString" +) + +func PossibleValuesForRuleQueryStringCachingBehavior() []string { + return []string{ + string(RuleQueryStringCachingBehaviorIgnoreQueryString), + string(RuleQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings), + string(RuleQueryStringCachingBehaviorIncludeSpecifiedQueryStrings), + string(RuleQueryStringCachingBehaviorUseQueryString), + } +} + +func (s *RuleQueryStringCachingBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleQueryStringCachingBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleQueryStringCachingBehavior(input string) (*RuleQueryStringCachingBehavior, error) { + vals := map[string]RuleQueryStringCachingBehavior{ + "ignorequerystring": RuleQueryStringCachingBehaviorIgnoreQueryString, + "ignorespecifiedquerystrings": RuleQueryStringCachingBehaviorIgnoreSpecifiedQueryStrings, + "includespecifiedquerystrings": RuleQueryStringCachingBehaviorIncludeSpecifiedQueryStrings, + "usequerystring": RuleQueryStringCachingBehaviorUseQueryString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleQueryStringCachingBehavior(input) + return &out, nil +} + +type ServerPortOperator string + +const ( + ServerPortOperatorAny ServerPortOperator = "Any" + ServerPortOperatorBeginsWith ServerPortOperator = "BeginsWith" + ServerPortOperatorContains ServerPortOperator = "Contains" + ServerPortOperatorEndsWith ServerPortOperator = "EndsWith" + ServerPortOperatorEqual ServerPortOperator = "Equal" + ServerPortOperatorGreaterThan ServerPortOperator = "GreaterThan" + ServerPortOperatorGreaterThanOrEqual ServerPortOperator = "GreaterThanOrEqual" + ServerPortOperatorLessThan ServerPortOperator = "LessThan" + ServerPortOperatorLessThanOrEqual ServerPortOperator = "LessThanOrEqual" + ServerPortOperatorRegEx ServerPortOperator = "RegEx" +) + +func PossibleValuesForServerPortOperator() []string { + return []string{ + string(ServerPortOperatorAny), + string(ServerPortOperatorBeginsWith), + string(ServerPortOperatorContains), + string(ServerPortOperatorEndsWith), + string(ServerPortOperatorEqual), + string(ServerPortOperatorGreaterThan), + string(ServerPortOperatorGreaterThanOrEqual), + string(ServerPortOperatorLessThan), + string(ServerPortOperatorLessThanOrEqual), + string(ServerPortOperatorRegEx), + } +} + +func (s *ServerPortOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerPortOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerPortOperator(input string) (*ServerPortOperator, error) { + vals := map[string]ServerPortOperator{ + "any": ServerPortOperatorAny, + "beginswith": ServerPortOperatorBeginsWith, + "contains": ServerPortOperatorContains, + "endswith": ServerPortOperatorEndsWith, + "equal": ServerPortOperatorEqual, + "greaterthan": ServerPortOperatorGreaterThan, + "greaterthanorequal": ServerPortOperatorGreaterThanOrEqual, + "lessthan": ServerPortOperatorLessThan, + "lessthanorequal": ServerPortOperatorLessThanOrEqual, + "regex": ServerPortOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerPortOperator(input) + return &out, nil +} + +type SocketAddrOperator string + +const ( + SocketAddrOperatorAny SocketAddrOperator = "Any" + SocketAddrOperatorIPMatch SocketAddrOperator = "IPMatch" +) + +func PossibleValuesForSocketAddrOperator() []string { + return []string{ + string(SocketAddrOperatorAny), + string(SocketAddrOperatorIPMatch), + } +} + +func (s *SocketAddrOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSocketAddrOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSocketAddrOperator(input string) (*SocketAddrOperator, error) { + vals := map[string]SocketAddrOperator{ + "any": SocketAddrOperatorAny, + "ipmatch": SocketAddrOperatorIPMatch, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SocketAddrOperator(input) + return &out, nil +} + +type SslProtocol string + +const ( + SslProtocolTLSvOne SslProtocol = "TLSv1" + SslProtocolTLSvOnePointOne SslProtocol = "TLSv1.1" + SslProtocolTLSvOnePointTwo SslProtocol = "TLSv1.2" +) + +func PossibleValuesForSslProtocol() []string { + return []string{ + string(SslProtocolTLSvOne), + string(SslProtocolTLSvOnePointOne), + string(SslProtocolTLSvOnePointTwo), + } +} + +func (s *SslProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSslProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSslProtocol(input string) (*SslProtocol, error) { + vals := map[string]SslProtocol{ + "tlsv1": SslProtocolTLSvOne, + "tlsv1.1": SslProtocolTLSvOnePointOne, + "tlsv1.2": SslProtocolTLSvOnePointTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SslProtocol(input) + return &out, nil +} + +type SslProtocolOperator string + +const ( + SslProtocolOperatorEqual SslProtocolOperator = "Equal" +) + +func PossibleValuesForSslProtocolOperator() []string { + return []string{ + string(SslProtocolOperatorEqual), + } +} + +func (s *SslProtocolOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSslProtocolOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSslProtocolOperator(input string) (*SslProtocolOperator, error) { + vals := map[string]SslProtocolOperator{ + "equal": SslProtocolOperatorEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SslProtocolOperator(input) + return &out, nil +} + +type Transform string + +const ( + TransformLowercase Transform = "Lowercase" + TransformRemoveNulls Transform = "RemoveNulls" + TransformTrim Transform = "Trim" + TransformUppercase Transform = "Uppercase" + TransformUrlDecode Transform = "UrlDecode" + TransformUrlEncode Transform = "UrlEncode" +) + +func PossibleValuesForTransform() []string { + return []string{ + string(TransformLowercase), + string(TransformRemoveNulls), + string(TransformTrim), + string(TransformUppercase), + string(TransformUrlDecode), + string(TransformUrlEncode), + } +} + +func (s *Transform) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTransform(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTransform(input string) (*Transform, error) { + vals := map[string]Transform{ + "lowercase": TransformLowercase, + "removenulls": TransformRemoveNulls, + "trim": TransformTrim, + "uppercase": TransformUppercase, + "urldecode": TransformUrlDecode, + "urlencode": TransformUrlEncode, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Transform(input) + return &out, nil +} + +type UrlFileExtensionOperator string + +const ( + UrlFileExtensionOperatorAny UrlFileExtensionOperator = "Any" + UrlFileExtensionOperatorBeginsWith UrlFileExtensionOperator = "BeginsWith" + UrlFileExtensionOperatorContains UrlFileExtensionOperator = "Contains" + UrlFileExtensionOperatorEndsWith UrlFileExtensionOperator = "EndsWith" + UrlFileExtensionOperatorEqual UrlFileExtensionOperator = "Equal" + UrlFileExtensionOperatorGreaterThan UrlFileExtensionOperator = "GreaterThan" + UrlFileExtensionOperatorGreaterThanOrEqual UrlFileExtensionOperator = "GreaterThanOrEqual" + UrlFileExtensionOperatorLessThan UrlFileExtensionOperator = "LessThan" + UrlFileExtensionOperatorLessThanOrEqual UrlFileExtensionOperator = "LessThanOrEqual" + UrlFileExtensionOperatorRegEx UrlFileExtensionOperator = "RegEx" +) + +func PossibleValuesForUrlFileExtensionOperator() []string { + return []string{ + string(UrlFileExtensionOperatorAny), + string(UrlFileExtensionOperatorBeginsWith), + string(UrlFileExtensionOperatorContains), + string(UrlFileExtensionOperatorEndsWith), + string(UrlFileExtensionOperatorEqual), + string(UrlFileExtensionOperatorGreaterThan), + string(UrlFileExtensionOperatorGreaterThanOrEqual), + string(UrlFileExtensionOperatorLessThan), + string(UrlFileExtensionOperatorLessThanOrEqual), + string(UrlFileExtensionOperatorRegEx), + } +} + +func (s *UrlFileExtensionOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUrlFileExtensionOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUrlFileExtensionOperator(input string) (*UrlFileExtensionOperator, error) { + vals := map[string]UrlFileExtensionOperator{ + "any": UrlFileExtensionOperatorAny, + "beginswith": UrlFileExtensionOperatorBeginsWith, + "contains": UrlFileExtensionOperatorContains, + "endswith": UrlFileExtensionOperatorEndsWith, + "equal": UrlFileExtensionOperatorEqual, + "greaterthan": UrlFileExtensionOperatorGreaterThan, + "greaterthanorequal": UrlFileExtensionOperatorGreaterThanOrEqual, + "lessthan": UrlFileExtensionOperatorLessThan, + "lessthanorequal": UrlFileExtensionOperatorLessThanOrEqual, + "regex": UrlFileExtensionOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UrlFileExtensionOperator(input) + return &out, nil +} + +type UrlFileNameOperator string + +const ( + UrlFileNameOperatorAny UrlFileNameOperator = "Any" + UrlFileNameOperatorBeginsWith UrlFileNameOperator = "BeginsWith" + UrlFileNameOperatorContains UrlFileNameOperator = "Contains" + UrlFileNameOperatorEndsWith UrlFileNameOperator = "EndsWith" + UrlFileNameOperatorEqual UrlFileNameOperator = "Equal" + UrlFileNameOperatorGreaterThan UrlFileNameOperator = "GreaterThan" + UrlFileNameOperatorGreaterThanOrEqual UrlFileNameOperator = "GreaterThanOrEqual" + UrlFileNameOperatorLessThan UrlFileNameOperator = "LessThan" + UrlFileNameOperatorLessThanOrEqual UrlFileNameOperator = "LessThanOrEqual" + UrlFileNameOperatorRegEx UrlFileNameOperator = "RegEx" +) + +func PossibleValuesForUrlFileNameOperator() []string { + return []string{ + string(UrlFileNameOperatorAny), + string(UrlFileNameOperatorBeginsWith), + string(UrlFileNameOperatorContains), + string(UrlFileNameOperatorEndsWith), + string(UrlFileNameOperatorEqual), + string(UrlFileNameOperatorGreaterThan), + string(UrlFileNameOperatorGreaterThanOrEqual), + string(UrlFileNameOperatorLessThan), + string(UrlFileNameOperatorLessThanOrEqual), + string(UrlFileNameOperatorRegEx), + } +} + +func (s *UrlFileNameOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUrlFileNameOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUrlFileNameOperator(input string) (*UrlFileNameOperator, error) { + vals := map[string]UrlFileNameOperator{ + "any": UrlFileNameOperatorAny, + "beginswith": UrlFileNameOperatorBeginsWith, + "contains": UrlFileNameOperatorContains, + "endswith": UrlFileNameOperatorEndsWith, + "equal": UrlFileNameOperatorEqual, + "greaterthan": UrlFileNameOperatorGreaterThan, + "greaterthanorequal": UrlFileNameOperatorGreaterThanOrEqual, + "lessthan": UrlFileNameOperatorLessThan, + "lessthanorequal": UrlFileNameOperatorLessThanOrEqual, + "regex": UrlFileNameOperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UrlFileNameOperator(input) + return &out, nil +} + +type UrlPathOperator string + +const ( + UrlPathOperatorAny UrlPathOperator = "Any" + UrlPathOperatorBeginsWith UrlPathOperator = "BeginsWith" + UrlPathOperatorContains UrlPathOperator = "Contains" + UrlPathOperatorEndsWith UrlPathOperator = "EndsWith" + UrlPathOperatorEqual UrlPathOperator = "Equal" + UrlPathOperatorGreaterThan UrlPathOperator = "GreaterThan" + UrlPathOperatorGreaterThanOrEqual UrlPathOperator = "GreaterThanOrEqual" + UrlPathOperatorLessThan UrlPathOperator = "LessThan" + UrlPathOperatorLessThanOrEqual UrlPathOperator = "LessThanOrEqual" + UrlPathOperatorRegEx UrlPathOperator = "RegEx" + UrlPathOperatorWildcard UrlPathOperator = "Wildcard" +) + +func PossibleValuesForUrlPathOperator() []string { + return []string{ + string(UrlPathOperatorAny), + string(UrlPathOperatorBeginsWith), + string(UrlPathOperatorContains), + string(UrlPathOperatorEndsWith), + string(UrlPathOperatorEqual), + string(UrlPathOperatorGreaterThan), + string(UrlPathOperatorGreaterThanOrEqual), + string(UrlPathOperatorLessThan), + string(UrlPathOperatorLessThanOrEqual), + string(UrlPathOperatorRegEx), + string(UrlPathOperatorWildcard), + } +} + +func (s *UrlPathOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUrlPathOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUrlPathOperator(input string) (*UrlPathOperator, error) { + vals := map[string]UrlPathOperator{ + "any": UrlPathOperatorAny, + "beginswith": UrlPathOperatorBeginsWith, + "contains": UrlPathOperatorContains, + "endswith": UrlPathOperatorEndsWith, + "equal": UrlPathOperatorEqual, + "greaterthan": UrlPathOperatorGreaterThan, + "greaterthanorequal": UrlPathOperatorGreaterThanOrEqual, + "lessthan": UrlPathOperatorLessThan, + "lessthanorequal": UrlPathOperatorLessThanOrEqual, + "regex": UrlPathOperatorRegEx, + "wildcard": UrlPathOperatorWildcard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UrlPathOperator(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/id_rule.go b/resource-manager/cdn/2024-02-01/rules/id_rule.go new file mode 100644 index 00000000000..2dbf92ab508 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/id_rule.go @@ -0,0 +1,148 @@ +package rules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RuleId{}) +} + +var _ resourceids.ResourceId = &RuleId{} + +// RuleId is a struct representing the Resource ID for a Rule +type RuleId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + RuleSetName string + RuleName string +} + +// NewRuleID returns a new RuleId struct +func NewRuleID(subscriptionId string, resourceGroupName string, profileName string, ruleSetName string, ruleName string) RuleId { + return RuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + RuleSetName: ruleSetName, + RuleName: ruleName, + } +} + +// ParseRuleID parses 'input' into a RuleId +func ParseRuleID(input string) (*RuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRuleIDInsensitively parses 'input' case-insensitively into a RuleId +// note: this method should only be used for API response data and not user input +func ParseRuleIDInsensitively(input string) (*RuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.RuleSetName, ok = input.Parsed["ruleSetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleSetName", input) + } + + if id.RuleName, ok = input.Parsed["ruleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleName", input) + } + + return nil +} + +// ValidateRuleID checks that 'input' can be parsed as a Rule ID +func ValidateRuleID(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 := ParseRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rule ID +func (id RuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/ruleSets/%s/rules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.RuleSetName, id.RuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rule ID +func (id RuleId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticRuleSets", "ruleSets", "ruleSets"), + resourceids.UserSpecifiedSegment("ruleSetName", "ruleSetValue"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleName", "ruleValue"), + } +} + +// String returns a human-readable description of this Rule ID +func (id RuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Rule Set Name: %q", id.RuleSetName), + fmt.Sprintf("Rule Name: %q", id.RuleName), + } + return fmt.Sprintf("Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/rules/id_rule_test.go b/resource-manager/cdn/2024-02-01/rules/id_rule_test.go new file mode 100644 index 00000000000..1ae5c7da749 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/id_rule_test.go @@ -0,0 +1,372 @@ +package rules + +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 = &RuleId{} + +func TestNewRuleID(t *testing.T) { + id := NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue", "ruleValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.RuleSetName != "ruleSetValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleSetName'", id.RuleSetName, "ruleSetValue") + } + + if id.RuleName != "ruleValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleName'", id.RuleName, "ruleValue") + } +} + +func TestFormatRuleID(t *testing.T) { + actual := NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue", "ruleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/rules/ruleValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/rules/ruleValue", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + RuleSetName: "ruleSetValue", + RuleName: "ruleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/rules/ruleValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.RuleSetName != v.Expected.RuleSetName { + t.Fatalf("Expected %q but got %q for RuleSetName", v.Expected.RuleSetName, actual.RuleSetName) + } + + if actual.RuleName != v.Expected.RuleName { + t.Fatalf("Expected %q but got %q for RuleName", v.Expected.RuleName, actual.RuleName) + } + + } +} + +func TestParseRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/rules/ruleValue", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + RuleSetName: "ruleSetValue", + RuleName: "ruleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/rules/ruleValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE/rUlEs/rUlEvAlUe", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + RuleSetName: "rUlEsEtVaLuE", + RuleName: "rUlEvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE/rUlEs/rUlEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.RuleSetName != v.Expected.RuleSetName { + t.Fatalf("Expected %q but got %q for RuleSetName", v.Expected.RuleSetName, actual.RuleSetName) + } + + if actual.RuleName != v.Expected.RuleName { + t.Fatalf("Expected %q but got %q for RuleName", v.Expected.RuleName, actual.RuleName) + } + + } +} + +func TestSegmentsForRuleId(t *testing.T) { + segments := RuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RuleId 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/cdn/2024-02-01/rules/id_ruleset.go b/resource-manager/cdn/2024-02-01/rules/id_ruleset.go new file mode 100644 index 00000000000..840a2491778 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/id_ruleset.go @@ -0,0 +1,139 @@ +package rules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RuleSetId{}) +} + +var _ resourceids.ResourceId = &RuleSetId{} + +// RuleSetId is a struct representing the Resource ID for a Rule Set +type RuleSetId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + RuleSetName string +} + +// NewRuleSetID returns a new RuleSetId struct +func NewRuleSetID(subscriptionId string, resourceGroupName string, profileName string, ruleSetName string) RuleSetId { + return RuleSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + RuleSetName: ruleSetName, + } +} + +// ParseRuleSetID parses 'input' into a RuleSetId +func ParseRuleSetID(input string) (*RuleSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRuleSetIDInsensitively parses 'input' case-insensitively into a RuleSetId +// note: this method should only be used for API response data and not user input +func ParseRuleSetIDInsensitively(input string) (*RuleSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RuleSetId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.RuleSetName, ok = input.Parsed["ruleSetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleSetName", input) + } + + return nil +} + +// ValidateRuleSetID checks that 'input' can be parsed as a Rule Set ID +func ValidateRuleSetID(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 := ParseRuleSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rule Set ID +func (id RuleSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/ruleSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.RuleSetName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rule Set ID +func (id RuleSetId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticRuleSets", "ruleSets", "ruleSets"), + resourceids.UserSpecifiedSegment("ruleSetName", "ruleSetValue"), + } +} + +// String returns a human-readable description of this Rule Set ID +func (id RuleSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Rule Set Name: %q", id.RuleSetName), + } + return fmt.Sprintf("Rule Set (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/rules/id_ruleset_test.go b/resource-manager/cdn/2024-02-01/rules/id_ruleset_test.go new file mode 100644 index 00000000000..5310f397871 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/id_ruleset_test.go @@ -0,0 +1,327 @@ +package rules + +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 = &RuleSetId{} + +func TestNewRuleSetID(t *testing.T) { + id := NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.RuleSetName != "ruleSetValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleSetName'", id.RuleSetName, "ruleSetValue") + } +} + +func TestFormatRuleSetID(t *testing.T) { + actual := NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRuleSetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleSetId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue", + Expected: &RuleSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + RuleSetName: "ruleSetValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleSetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.RuleSetName != v.Expected.RuleSetName { + t.Fatalf("Expected %q but got %q for RuleSetName", v.Expected.RuleSetName, actual.RuleSetName) + } + + } +} + +func TestParseRuleSetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleSetId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue", + Expected: &RuleSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + RuleSetName: "ruleSetValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE", + Expected: &RuleSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + RuleSetName: "rUlEsEtVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleSetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.RuleSetName != v.Expected.RuleSetName { + t.Fatalf("Expected %q but got %q for RuleSetName", v.Expected.RuleSetName, actual.RuleSetName) + } + + } +} + +func TestSegmentsForRuleSetId(t *testing.T) { + segments := RuleSetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RuleSetId 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/cdn/2024-02-01/rules/method_create.go b/resource-manager/cdn/2024-02-01/rules/method_create.go new file mode 100644 index 00000000000..84a6f02dc5e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/method_create.go @@ -0,0 +1,76 @@ +package rules + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Rule +} + +// Create ... +func (c RulesClient) Create(ctx context.Context, id RuleId, input Rule) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c RulesClient) CreateThenPoll(ctx context.Context, id RuleId, input Rule) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/method_delete.go b/resource-manager/cdn/2024-02-01/rules/method_delete.go new file mode 100644 index 00000000000..beb0bc70b2e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/method_delete.go @@ -0,0 +1,71 @@ +package rules + +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 RulesClient) Delete(ctx context.Context, id RuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c RulesClient) DeleteThenPoll(ctx context.Context, id RuleId) 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/cdn/2024-02-01/rules/method_get.go b/resource-manager/cdn/2024-02-01/rules/method_get.go new file mode 100644 index 00000000000..9337bed8a1b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/method_get.go @@ -0,0 +1,54 @@ +package rules + +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 *Rule +} + +// Get ... +func (c RulesClient) Get(ctx context.Context, id RuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Rule + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/rules/method_listbyruleset.go b/resource-manager/cdn/2024-02-01/rules/method_listbyruleset.go new file mode 100644 index 00000000000..45074b4d014 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/method_listbyruleset.go @@ -0,0 +1,105 @@ +package rules + +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 ListByRuleSetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Rule +} + +type ListByRuleSetCompleteResult struct { + LatestHttpResponse *http.Response + Items []Rule +} + +type ListByRuleSetCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByRuleSetCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByRuleSet ... +func (c RulesClient) ListByRuleSet(ctx context.Context, id RuleSetId) (result ListByRuleSetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByRuleSetCustomPager{}, + Path: fmt.Sprintf("%s/rules", 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 *[]Rule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByRuleSetComplete retrieves all the results into a single object +func (c RulesClient) ListByRuleSetComplete(ctx context.Context, id RuleSetId) (ListByRuleSetCompleteResult, error) { + return c.ListByRuleSetCompleteMatchingPredicate(ctx, id, RuleOperationPredicate{}) +} + +// ListByRuleSetCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RulesClient) ListByRuleSetCompleteMatchingPredicate(ctx context.Context, id RuleSetId, predicate RuleOperationPredicate) (result ListByRuleSetCompleteResult, err error) { + items := make([]Rule, 0) + + resp, err := c.ListByRuleSet(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByRuleSetCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/rules/method_update.go b/resource-manager/cdn/2024-02-01/rules/method_update.go new file mode 100644 index 00000000000..1d7a1bd0f41 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/method_update.go @@ -0,0 +1,75 @@ +package rules + +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 + Model *Rule +} + +// Update ... +func (c RulesClient) Update(ctx context.Context, id RuleId, input RuleUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c RulesClient) UpdateThenPoll(ctx context.Context, id RuleId, input RuleUpdateParameters) 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/cdn/2024-02-01/rules/model_cacheconfiguration.go b/resource-manager/cdn/2024-02-01/rules/model_cacheconfiguration.go new file mode 100644 index 00000000000..af68de873ac --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_cacheconfiguration.go @@ -0,0 +1,12 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheConfiguration struct { + CacheBehavior *RuleCacheBehavior `json:"cacheBehavior,omitempty"` + CacheDuration *string `json:"cacheDuration,omitempty"` + IsCompressionEnabled *RuleIsCompressionEnabled `json:"isCompressionEnabled,omitempty"` + QueryParameters *string `json:"queryParameters,omitempty"` + QueryStringCachingBehavior *RuleQueryStringCachingBehavior `json:"queryStringCachingBehavior,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_cacheexpirationactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_cacheexpirationactionparameters.go new file mode 100644 index 00000000000..df3dd7f806b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_cacheexpirationactionparameters.go @@ -0,0 +1,43 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = CacheExpirationActionParameters{} + +type CacheExpirationActionParameters struct { + CacheBehavior CacheBehavior `json:"cacheBehavior"` + CacheDuration *string `json:"cacheDuration,omitempty"` + CacheType CacheType `json:"cacheType"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = CacheExpirationActionParameters{} + +func (s CacheExpirationActionParameters) MarshalJSON() ([]byte, error) { + type wrapper CacheExpirationActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CacheExpirationActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CacheExpirationActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleCacheExpirationActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CacheExpirationActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_cachekeyquerystringactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_cachekeyquerystringactionparameters.go new file mode 100644 index 00000000000..e92fc5dd814 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_cachekeyquerystringactionparameters.go @@ -0,0 +1,42 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = CacheKeyQueryStringActionParameters{} + +type CacheKeyQueryStringActionParameters struct { + QueryParameters *string `json:"queryParameters,omitempty"` + QueryStringBehavior QueryStringBehavior `json:"queryStringBehavior"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = CacheKeyQueryStringActionParameters{} + +func (s CacheKeyQueryStringActionParameters) MarshalJSON() ([]byte, error) { + type wrapper CacheKeyQueryStringActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CacheKeyQueryStringActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CacheKeyQueryStringActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleCacheKeyQueryStringBehaviorActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CacheKeyQueryStringActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_clientportmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_clientportmatchconditionparameters.go new file mode 100644 index 00000000000..eeaf17609e8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_clientportmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = ClientPortMatchConditionParameters{} + +type ClientPortMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator ClientPortOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = ClientPortMatchConditionParameters{} + +func (s ClientPortMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper ClientPortMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ClientPortMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ClientPortMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleClientPortConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ClientPortMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_cookiesmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_cookiesmatchconditionparameters.go new file mode 100644 index 00000000000..97c69dacf04 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_cookiesmatchconditionparameters.go @@ -0,0 +1,45 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = CookiesMatchConditionParameters{} + +type CookiesMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator CookiesOperator `json:"operator"` + Selector *string `json:"selector,omitempty"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = CookiesMatchConditionParameters{} + +func (s CookiesMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper CookiesMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CookiesMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CookiesMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleCookiesConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CookiesMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleaction.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleaction.go new file mode 100644 index 00000000000..069eb3d9234 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleaction.go @@ -0,0 +1,117 @@ +package rules + +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 DeliveryRuleAction interface { +} + +// RawDeliveryRuleActionImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleActionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleActionImplementation(input []byte) (DeliveryRuleAction, 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 DeliveryRuleAction into map[string]interface: %+v", err) + } + + value, ok := temp["name"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "CacheExpiration") { + var out DeliveryRuleCacheExpirationAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleCacheExpirationAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "CacheKeyQueryString") { + var out DeliveryRuleCacheKeyQueryStringAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ModifyRequestHeader") { + var out DeliveryRuleRequestHeaderAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestHeaderAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ModifyResponseHeader") { + var out DeliveryRuleResponseHeaderAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleResponseHeaderAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RouteConfigurationOverride") { + var out DeliveryRuleRouteConfigurationOverrideAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "OriginGroupOverride") { + var out OriginGroupOverrideAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into OriginGroupOverrideAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlRedirect") { + var out UrlRedirectAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRedirectAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlRewrite") { + var out UrlRewriteAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRewriteAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlSigning") { + var out UrlSigningAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlSigningAction: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleActionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleactionparameters.go new file mode 100644 index 00000000000..8b85b8193b3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleactionparameters.go @@ -0,0 +1,109 @@ +package rules + +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 DeliveryRuleActionParameters interface { +} + +// RawDeliveryRuleActionParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleActionParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleActionParametersImplementation(input []byte) (DeliveryRuleActionParameters, 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 DeliveryRuleActionParameters into map[string]interface: %+v", err) + } + + value, ok := temp["typeName"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "DeliveryRuleCacheExpirationActionParameters") { + var out CacheExpirationActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CacheExpirationActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleCacheKeyQueryStringBehaviorActionParameters") { + var out CacheKeyQueryStringActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CacheKeyQueryStringActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleHeaderActionParameters") { + var out HeaderActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HeaderActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleOriginGroupOverrideActionParameters") { + var out OriginGroupOverrideActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into OriginGroupOverrideActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRouteConfigurationOverrideActionParameters") { + var out RouteConfigurationOverrideActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RouteConfigurationOverrideActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlRedirectActionParameters") { + var out UrlRedirectActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRedirectActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlRewriteActionParameters") { + var out UrlRewriteActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlRewriteActionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlSigningActionParameters") { + var out UrlSigningActionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlSigningActionParameters: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleActionParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecacheexpirationaction.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecacheexpirationaction.go new file mode 100644 index 00000000000..141deac6e74 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecacheexpirationaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleCacheExpirationAction{} + +type DeliveryRuleCacheExpirationAction struct { + Parameters CacheExpirationActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleCacheExpirationAction{} + +func (s DeliveryRuleCacheExpirationAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleCacheExpirationAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleCacheExpirationAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleCacheExpirationAction: %+v", err) + } + decoded["name"] = "CacheExpiration" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleCacheExpirationAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecachekeyquerystringaction.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecachekeyquerystringaction.go new file mode 100644 index 00000000000..fbd6289fb0e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecachekeyquerystringaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleCacheKeyQueryStringAction{} + +type DeliveryRuleCacheKeyQueryStringAction struct { + Parameters CacheKeyQueryStringActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleCacheKeyQueryStringAction{} + +func (s DeliveryRuleCacheKeyQueryStringAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleCacheKeyQueryStringAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + decoded["name"] = "CacheKeyQueryString" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleCacheKeyQueryStringAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleclientportcondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleclientportcondition.go new file mode 100644 index 00000000000..4a8b8b065be --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleclientportcondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleClientPortCondition{} + +type DeliveryRuleClientPortCondition struct { + Parameters ClientPortMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleClientPortCondition{} + +func (s DeliveryRuleClientPortCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleClientPortCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleClientPortCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleClientPortCondition: %+v", err) + } + decoded["name"] = "ClientPort" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleClientPortCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecondition.go new file mode 100644 index 00000000000..9fea76221e2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecondition.go @@ -0,0 +1,197 @@ +package rules + +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 DeliveryRuleCondition interface { +} + +// RawDeliveryRuleConditionImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleConditionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleConditionImplementation(input []byte) (DeliveryRuleCondition, 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 DeliveryRuleCondition into map[string]interface: %+v", err) + } + + value, ok := temp["name"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ClientPort") { + var out DeliveryRuleClientPortCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleClientPortCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Cookies") { + var out DeliveryRuleCookiesCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleCookiesCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HttpVersion") { + var out DeliveryRuleHTTPVersionCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleHTTPVersionCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HostName") { + var out DeliveryRuleHostNameCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleHostNameCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IsDevice") { + var out DeliveryRuleIsDeviceCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleIsDeviceCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "PostArgs") { + var out DeliveryRulePostArgsCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRulePostArgsCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "QueryString") { + var out DeliveryRuleQueryStringCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleQueryStringCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RemoteAddress") { + var out DeliveryRuleRemoteAddressCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRemoteAddressCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestBody") { + var out DeliveryRuleRequestBodyCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestBodyCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestHeader") { + var out DeliveryRuleRequestHeaderCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestHeaderCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestMethod") { + var out DeliveryRuleRequestMethodCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestMethodCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestScheme") { + var out DeliveryRuleRequestSchemeCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestSchemeCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RequestUri") { + var out DeliveryRuleRequestUriCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleRequestUriCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ServerPort") { + var out DeliveryRuleServerPortCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleServerPortCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SocketAddr") { + var out DeliveryRuleSocketAddrCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleSocketAddrCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SslProtocol") { + var out DeliveryRuleSslProtocolCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleSslProtocolCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlFileExtension") { + var out DeliveryRuleUrlFileExtensionCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlFileName") { + var out DeliveryRuleUrlFileNameCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleUrlFileNameCondition: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlPath") { + var out DeliveryRuleUrlPathCondition + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DeliveryRuleUrlPathCondition: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleConditionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleconditionparameters.go new file mode 100644 index 00000000000..e857806e532 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleconditionparameters.go @@ -0,0 +1,197 @@ +package rules + +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 DeliveryRuleConditionParameters interface { +} + +// RawDeliveryRuleConditionParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeliveryRuleConditionParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryRuleConditionParametersImplementation(input []byte) (DeliveryRuleConditionParameters, 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 DeliveryRuleConditionParameters into map[string]interface: %+v", err) + } + + value, ok := temp["typeName"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "DeliveryRuleClientPortConditionParameters") { + var out ClientPortMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ClientPortMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleCookiesConditionParameters") { + var out CookiesMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CookiesMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleHttpVersionConditionParameters") { + var out HTTPVersionMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HTTPVersionMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleHostNameConditionParameters") { + var out HostNameMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HostNameMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleIsDeviceConditionParameters") { + var out IsDeviceMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IsDeviceMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRulePostArgsConditionParameters") { + var out PostArgsMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PostArgsMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleQueryStringConditionParameters") { + var out QueryStringMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into QueryStringMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRemoteAddressConditionParameters") { + var out RemoteAddressMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RemoteAddressMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestBodyConditionParameters") { + var out RequestBodyMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestBodyMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestHeaderConditionParameters") { + var out RequestHeaderMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestHeaderMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestMethodConditionParameters") { + var out RequestMethodMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestMethodMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestSchemeConditionParameters") { + var out RequestSchemeMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestSchemeMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleRequestUriConditionParameters") { + var out RequestUriMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RequestUriMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleServerPortConditionParameters") { + var out ServerPortMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ServerPortMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleSocketAddrConditionParameters") { + var out SocketAddrMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SocketAddrMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleSslProtocolConditionParameters") { + var out SslProtocolMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SslProtocolMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlFileExtensionMatchConditionParameters") { + var out UrlFileExtensionMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlFileExtensionMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlFilenameConditionParameters") { + var out UrlFileNameMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlFileNameMatchConditionParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DeliveryRuleUrlPathMatchConditionParameters") { + var out UrlPathMatchConditionParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlPathMatchConditionParameters: %+v", err) + } + return out, nil + } + + out := RawDeliveryRuleConditionParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecookiescondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecookiescondition.go new file mode 100644 index 00000000000..ffc96f85263 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulecookiescondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleCookiesCondition{} + +type DeliveryRuleCookiesCondition struct { + Parameters CookiesMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleCookiesCondition{} + +func (s DeliveryRuleCookiesCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleCookiesCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleCookiesCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleCookiesCondition: %+v", err) + } + decoded["name"] = "Cookies" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleCookiesCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulehostnamecondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulehostnamecondition.go new file mode 100644 index 00000000000..e0ec9df8a92 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulehostnamecondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleHostNameCondition{} + +type DeliveryRuleHostNameCondition struct { + Parameters HostNameMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleHostNameCondition{} + +func (s DeliveryRuleHostNameCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleHostNameCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleHostNameCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleHostNameCondition: %+v", err) + } + decoded["name"] = "HostName" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleHostNameCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulehttpversioncondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulehttpversioncondition.go new file mode 100644 index 00000000000..63b72411613 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulehttpversioncondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleHTTPVersionCondition{} + +type DeliveryRuleHTTPVersionCondition struct { + Parameters HTTPVersionMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleHTTPVersionCondition{} + +func (s DeliveryRuleHTTPVersionCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleHTTPVersionCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleHTTPVersionCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleHTTPVersionCondition: %+v", err) + } + decoded["name"] = "HttpVersion" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleHTTPVersionCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleisdevicecondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleisdevicecondition.go new file mode 100644 index 00000000000..d970808c943 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleisdevicecondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleIsDeviceCondition{} + +type DeliveryRuleIsDeviceCondition struct { + Parameters IsDeviceMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleIsDeviceCondition{} + +func (s DeliveryRuleIsDeviceCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleIsDeviceCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleIsDeviceCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleIsDeviceCondition: %+v", err) + } + decoded["name"] = "IsDevice" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleIsDeviceCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulepostargscondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulepostargscondition.go new file mode 100644 index 00000000000..538f9396ee6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulepostargscondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRulePostArgsCondition{} + +type DeliveryRulePostArgsCondition struct { + Parameters PostArgsMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRulePostArgsCondition{} + +func (s DeliveryRulePostArgsCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRulePostArgsCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRulePostArgsCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRulePostArgsCondition: %+v", err) + } + decoded["name"] = "PostArgs" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRulePostArgsCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulequerystringcondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulequerystringcondition.go new file mode 100644 index 00000000000..1db4b7d9131 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulequerystringcondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleQueryStringCondition{} + +type DeliveryRuleQueryStringCondition struct { + Parameters QueryStringMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleQueryStringCondition{} + +func (s DeliveryRuleQueryStringCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleQueryStringCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleQueryStringCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleQueryStringCondition: %+v", err) + } + decoded["name"] = "QueryString" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleQueryStringCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleremoteaddresscondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleremoteaddresscondition.go new file mode 100644 index 00000000000..074027e1566 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleremoteaddresscondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRemoteAddressCondition{} + +type DeliveryRuleRemoteAddressCondition struct { + Parameters RemoteAddressMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRemoteAddressCondition{} + +func (s DeliveryRuleRemoteAddressCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRemoteAddressCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRemoteAddressCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRemoteAddressCondition: %+v", err) + } + decoded["name"] = "RemoteAddress" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRemoteAddressCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestbodycondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestbodycondition.go new file mode 100644 index 00000000000..6d5dcf5d3b8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestbodycondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestBodyCondition{} + +type DeliveryRuleRequestBodyCondition struct { + Parameters RequestBodyMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestBodyCondition{} + +func (s DeliveryRuleRequestBodyCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestBodyCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestBodyCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestBodyCondition: %+v", err) + } + decoded["name"] = "RequestBody" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestBodyCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestheaderaction.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestheaderaction.go new file mode 100644 index 00000000000..2576bd76043 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestheaderaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleRequestHeaderAction{} + +type DeliveryRuleRequestHeaderAction struct { + Parameters HeaderActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleRequestHeaderAction{} + +func (s DeliveryRuleRequestHeaderAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestHeaderAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestHeaderAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestHeaderAction: %+v", err) + } + decoded["name"] = "ModifyRequestHeader" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestHeaderAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestheadercondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestheadercondition.go new file mode 100644 index 00000000000..ae2fff3572a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestheadercondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestHeaderCondition{} + +type DeliveryRuleRequestHeaderCondition struct { + Parameters RequestHeaderMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestHeaderCondition{} + +func (s DeliveryRuleRequestHeaderCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestHeaderCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestHeaderCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestHeaderCondition: %+v", err) + } + decoded["name"] = "RequestHeader" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestHeaderCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestmethodcondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestmethodcondition.go new file mode 100644 index 00000000000..0087351462f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestmethodcondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestMethodCondition{} + +type DeliveryRuleRequestMethodCondition struct { + Parameters RequestMethodMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestMethodCondition{} + +func (s DeliveryRuleRequestMethodCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestMethodCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestMethodCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestMethodCondition: %+v", err) + } + decoded["name"] = "RequestMethod" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestMethodCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestschemecondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestschemecondition.go new file mode 100644 index 00000000000..a67b391b9f6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequestschemecondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestSchemeCondition{} + +type DeliveryRuleRequestSchemeCondition struct { + Parameters RequestSchemeMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestSchemeCondition{} + +func (s DeliveryRuleRequestSchemeCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestSchemeCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestSchemeCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestSchemeCondition: %+v", err) + } + decoded["name"] = "RequestScheme" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestSchemeCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequesturicondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequesturicondition.go new file mode 100644 index 00000000000..06197136e50 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerequesturicondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleRequestUriCondition{} + +type DeliveryRuleRequestUriCondition struct { + Parameters RequestUriMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleRequestUriCondition{} + +func (s DeliveryRuleRequestUriCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRequestUriCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRequestUriCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRequestUriCondition: %+v", err) + } + decoded["name"] = "RequestUri" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRequestUriCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleresponseheaderaction.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleresponseheaderaction.go new file mode 100644 index 00000000000..284197b1a95 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleresponseheaderaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleResponseHeaderAction{} + +type DeliveryRuleResponseHeaderAction struct { + Parameters HeaderActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleResponseHeaderAction{} + +func (s DeliveryRuleResponseHeaderAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleResponseHeaderAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleResponseHeaderAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleResponseHeaderAction: %+v", err) + } + decoded["name"] = "ModifyResponseHeader" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleResponseHeaderAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerouteconfigurationoverrideaction.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerouteconfigurationoverrideaction.go new file mode 100644 index 00000000000..bb950a9605c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulerouteconfigurationoverrideaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = DeliveryRuleRouteConfigurationOverrideAction{} + +type DeliveryRuleRouteConfigurationOverrideAction struct { + Parameters RouteConfigurationOverrideActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = DeliveryRuleRouteConfigurationOverrideAction{} + +func (s DeliveryRuleRouteConfigurationOverrideAction) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleRouteConfigurationOverrideAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + decoded["name"] = "RouteConfigurationOverride" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleRouteConfigurationOverrideAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleserverportcondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleserverportcondition.go new file mode 100644 index 00000000000..0f31e2d4c23 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleserverportcondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleServerPortCondition{} + +type DeliveryRuleServerPortCondition struct { + Parameters ServerPortMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleServerPortCondition{} + +func (s DeliveryRuleServerPortCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleServerPortCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleServerPortCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleServerPortCondition: %+v", err) + } + decoded["name"] = "ServerPort" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleServerPortCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulesocketaddrcondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulesocketaddrcondition.go new file mode 100644 index 00000000000..f8ae9cb0ab6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulesocketaddrcondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleSocketAddrCondition{} + +type DeliveryRuleSocketAddrCondition struct { + Parameters SocketAddrMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleSocketAddrCondition{} + +func (s DeliveryRuleSocketAddrCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleSocketAddrCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleSocketAddrCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleSocketAddrCondition: %+v", err) + } + decoded["name"] = "SocketAddr" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleSocketAddrCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryrulesslprotocolcondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulesslprotocolcondition.go new file mode 100644 index 00000000000..6219661dc4d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryrulesslprotocolcondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleSslProtocolCondition{} + +type DeliveryRuleSslProtocolCondition struct { + Parameters SslProtocolMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleSslProtocolCondition{} + +func (s DeliveryRuleSslProtocolCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleSslProtocolCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleSslProtocolCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleSslProtocolCondition: %+v", err) + } + decoded["name"] = "SslProtocol" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleSslProtocolCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlfileextensioncondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlfileextensioncondition.go new file mode 100644 index 00000000000..525a34897c8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlfileextensioncondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleUrlFileExtensionCondition{} + +type DeliveryRuleUrlFileExtensionCondition struct { + Parameters UrlFileExtensionMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleUrlFileExtensionCondition{} + +func (s DeliveryRuleUrlFileExtensionCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleUrlFileExtensionCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + decoded["name"] = "UrlFileExtension" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleUrlFileExtensionCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlfilenamecondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlfilenamecondition.go new file mode 100644 index 00000000000..0482968efc7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlfilenamecondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleUrlFileNameCondition{} + +type DeliveryRuleUrlFileNameCondition struct { + Parameters UrlFileNameMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleUrlFileNameCondition{} + +func (s DeliveryRuleUrlFileNameCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleUrlFileNameCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleUrlFileNameCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleUrlFileNameCondition: %+v", err) + } + decoded["name"] = "UrlFileName" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleUrlFileNameCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlpathcondition.go b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlpathcondition.go new file mode 100644 index 00000000000..0c91ed762b0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_deliveryruleurlpathcondition.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleCondition = DeliveryRuleUrlPathCondition{} + +type DeliveryRuleUrlPathCondition struct { + Parameters UrlPathMatchConditionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleCondition +} + +var _ json.Marshaler = DeliveryRuleUrlPathCondition{} + +func (s DeliveryRuleUrlPathCondition) MarshalJSON() ([]byte, error) { + type wrapper DeliveryRuleUrlPathCondition + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DeliveryRuleUrlPathCondition: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DeliveryRuleUrlPathCondition: %+v", err) + } + decoded["name"] = "UrlPath" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DeliveryRuleUrlPathCondition: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_headeractionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_headeractionparameters.go new file mode 100644 index 00000000000..cc4d10192ce --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_headeractionparameters.go @@ -0,0 +1,43 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = HeaderActionParameters{} + +type HeaderActionParameters struct { + HeaderAction HeaderAction `json:"headerAction"` + HeaderName string `json:"headerName"` + Value *string `json:"value,omitempty"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = HeaderActionParameters{} + +func (s HeaderActionParameters) MarshalJSON() ([]byte, error) { + type wrapper HeaderActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HeaderActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HeaderActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleHeaderActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HeaderActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_hostnamematchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_hostnamematchconditionparameters.go new file mode 100644 index 00000000000..038ce9ba9e0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_hostnamematchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = HostNameMatchConditionParameters{} + +type HostNameMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator HostNameOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = HostNameMatchConditionParameters{} + +func (s HostNameMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper HostNameMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HostNameMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HostNameMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleHostNameConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HostNameMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_httpversionmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_httpversionmatchconditionparameters.go new file mode 100644 index 00000000000..657f89bb846 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_httpversionmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = HTTPVersionMatchConditionParameters{} + +type HTTPVersionMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator HTTPVersionOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = HTTPVersionMatchConditionParameters{} + +func (s HTTPVersionMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper HTTPVersionMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HTTPVersionMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HTTPVersionMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleHttpVersionConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HTTPVersionMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_isdevicematchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_isdevicematchconditionparameters.go new file mode 100644 index 00000000000..4aa28833dc1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_isdevicematchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = IsDeviceMatchConditionParameters{} + +type IsDeviceMatchConditionParameters struct { + MatchValues *[]IsDeviceMatchValue `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator IsDeviceOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = IsDeviceMatchConditionParameters{} + +func (s IsDeviceMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper IsDeviceMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IsDeviceMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IsDeviceMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleIsDeviceConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IsDeviceMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_origingroupoverride.go b/resource-manager/cdn/2024-02-01/rules/model_origingroupoverride.go new file mode 100644 index 00000000000..72d2e00784b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_origingroupoverride.go @@ -0,0 +1,9 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OriginGroupOverride struct { + ForwardingProtocol *ForwardingProtocol `json:"forwardingProtocol,omitempty"` + OriginGroup *ResourceReference `json:"originGroup,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_origingroupoverrideaction.go b/resource-manager/cdn/2024-02-01/rules/model_origingroupoverrideaction.go new file mode 100644 index 00000000000..26aee4d1e80 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_origingroupoverrideaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = OriginGroupOverrideAction{} + +type OriginGroupOverrideAction struct { + Parameters OriginGroupOverrideActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = OriginGroupOverrideAction{} + +func (s OriginGroupOverrideAction) MarshalJSON() ([]byte, error) { + type wrapper OriginGroupOverrideAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling OriginGroupOverrideAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling OriginGroupOverrideAction: %+v", err) + } + decoded["name"] = "OriginGroupOverride" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling OriginGroupOverrideAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_origingroupoverrideactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_origingroupoverrideactionparameters.go new file mode 100644 index 00000000000..120a8587075 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_origingroupoverrideactionparameters.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = OriginGroupOverrideActionParameters{} + +type OriginGroupOverrideActionParameters struct { + OriginGroup ResourceReference `json:"originGroup"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = OriginGroupOverrideActionParameters{} + +func (s OriginGroupOverrideActionParameters) MarshalJSON() ([]byte, error) { + type wrapper OriginGroupOverrideActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling OriginGroupOverrideActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling OriginGroupOverrideActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleOriginGroupOverrideActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling OriginGroupOverrideActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_postargsmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_postargsmatchconditionparameters.go new file mode 100644 index 00000000000..3b80bfea9cc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_postargsmatchconditionparameters.go @@ -0,0 +1,45 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = PostArgsMatchConditionParameters{} + +type PostArgsMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator PostArgsOperator `json:"operator"` + Selector *string `json:"selector,omitempty"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = PostArgsMatchConditionParameters{} + +func (s PostArgsMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper PostArgsMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PostArgsMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PostArgsMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRulePostArgsConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PostArgsMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_querystringmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_querystringmatchconditionparameters.go new file mode 100644 index 00000000000..aa62075994f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_querystringmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = QueryStringMatchConditionParameters{} + +type QueryStringMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator QueryStringOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = QueryStringMatchConditionParameters{} + +func (s QueryStringMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper QueryStringMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling QueryStringMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling QueryStringMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleQueryStringConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling QueryStringMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_remoteaddressmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_remoteaddressmatchconditionparameters.go new file mode 100644 index 00000000000..c2b8ffca9c1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_remoteaddressmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RemoteAddressMatchConditionParameters{} + +type RemoteAddressMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RemoteAddressOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RemoteAddressMatchConditionParameters{} + +func (s RemoteAddressMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RemoteAddressMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RemoteAddressMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RemoteAddressMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRemoteAddressConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RemoteAddressMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_requestbodymatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_requestbodymatchconditionparameters.go new file mode 100644 index 00000000000..4acb1cc2132 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_requestbodymatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestBodyMatchConditionParameters{} + +type RequestBodyMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestBodyOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestBodyMatchConditionParameters{} + +func (s RequestBodyMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestBodyMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestBodyMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestBodyMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestBodyConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestBodyMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_requestheadermatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_requestheadermatchconditionparameters.go new file mode 100644 index 00000000000..356bb9ab7c5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_requestheadermatchconditionparameters.go @@ -0,0 +1,45 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestHeaderMatchConditionParameters{} + +type RequestHeaderMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestHeaderOperator `json:"operator"` + Selector *string `json:"selector,omitempty"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestHeaderMatchConditionParameters{} + +func (s RequestHeaderMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestHeaderMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestHeaderMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestHeaderMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestHeaderConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestHeaderMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_requestmethodmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_requestmethodmatchconditionparameters.go new file mode 100644 index 00000000000..f7cd3c9147b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_requestmethodmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestMethodMatchConditionParameters{} + +type RequestMethodMatchConditionParameters struct { + MatchValues *[]RequestMethodMatchValue `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestMethodOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestMethodMatchConditionParameters{} + +func (s RequestMethodMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestMethodMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestMethodMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestMethodMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestMethodConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestMethodMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_requestschemematchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_requestschemematchconditionparameters.go new file mode 100644 index 00000000000..9df5aac2f40 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_requestschemematchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestSchemeMatchConditionParameters{} + +type RequestSchemeMatchConditionParameters struct { + MatchValues *[]RequestSchemeMatchValue `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator Operator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestSchemeMatchConditionParameters{} + +func (s RequestSchemeMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestSchemeMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestSchemeMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestSchemeMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestSchemeConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestSchemeMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_requesturimatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_requesturimatchconditionparameters.go new file mode 100644 index 00000000000..3302c4d9409 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_requesturimatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = RequestUriMatchConditionParameters{} + +type RequestUriMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator RequestUriOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = RequestUriMatchConditionParameters{} + +func (s RequestUriMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper RequestUriMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RequestUriMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RequestUriMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRequestUriConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RequestUriMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_resourcereference.go b/resource-manager/cdn/2024-02-01/rules/model_resourcereference.go new file mode 100644 index 00000000000..841c18a0770 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_resourcereference.go @@ -0,0 +1,8 @@ +package rules + +// 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/cdn/2024-02-01/rules/model_routeconfigurationoverrideactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_routeconfigurationoverrideactionparameters.go new file mode 100644 index 00000000000..f464ac90831 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_routeconfigurationoverrideactionparameters.go @@ -0,0 +1,42 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = RouteConfigurationOverrideActionParameters{} + +type RouteConfigurationOverrideActionParameters struct { + CacheConfiguration *CacheConfiguration `json:"cacheConfiguration,omitempty"` + OriginGroupOverride *OriginGroupOverride `json:"originGroupOverride,omitempty"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = RouteConfigurationOverrideActionParameters{} + +func (s RouteConfigurationOverrideActionParameters) MarshalJSON() ([]byte, error) { + type wrapper RouteConfigurationOverrideActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RouteConfigurationOverrideActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RouteConfigurationOverrideActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleRouteConfigurationOverrideActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RouteConfigurationOverrideActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_rule.go b/resource-manager/cdn/2024-02-01/rules/model_rule.go new file mode 100644 index 00000000000..8b9504ed600 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_rule.go @@ -0,0 +1,16 @@ +package rules + +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 Rule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RuleProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_ruleproperties.go b/resource-manager/cdn/2024-02-01/rules/model_ruleproperties.go new file mode 100644 index 00000000000..aaada8e6bf8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_ruleproperties.go @@ -0,0 +1,75 @@ +package rules + +import ( + "encoding/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 RuleProperties struct { + Actions *[]DeliveryRuleAction `json:"actions,omitempty"` + Conditions *[]DeliveryRuleCondition `json:"conditions,omitempty"` + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + MatchProcessingBehavior *MatchProcessingBehavior `json:"matchProcessingBehavior,omitempty"` + Order *int64 `json:"order,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` + RuleSetName *string `json:"ruleSetName,omitempty"` +} + +var _ json.Unmarshaler = &RuleProperties{} + +func (s *RuleProperties) UnmarshalJSON(bytes []byte) error { + type alias RuleProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RuleProperties: %+v", err) + } + + s.DeploymentStatus = decoded.DeploymentStatus + s.MatchProcessingBehavior = decoded.MatchProcessingBehavior + s.Order = decoded.Order + s.ProvisioningState = decoded.ProvisioningState + s.RuleSetName = decoded.RuleSetName + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RuleProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["actions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Actions into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryRuleAction, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryRuleActionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Actions' for 'RuleProperties': %+v", i, err) + } + output = append(output, impl) + } + s.Actions = &output + } + + if v, ok := temp["conditions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Conditions into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryRuleCondition, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryRuleConditionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Conditions' for 'RuleProperties': %+v", i, err) + } + output = append(output, impl) + } + s.Conditions = &output + } + return nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_ruleupdateparameters.go b/resource-manager/cdn/2024-02-01/rules/model_ruleupdateparameters.go new file mode 100644 index 00000000000..d5bd427fc3d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_ruleupdateparameters.go @@ -0,0 +1,8 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RuleUpdateParameters struct { + Properties *RuleUpdatePropertiesParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_ruleupdatepropertiesparameters.go b/resource-manager/cdn/2024-02-01/rules/model_ruleupdatepropertiesparameters.go new file mode 100644 index 00000000000..91a2757ee94 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_ruleupdatepropertiesparameters.go @@ -0,0 +1,71 @@ +package rules + +import ( + "encoding/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 RuleUpdatePropertiesParameters struct { + Actions *[]DeliveryRuleAction `json:"actions,omitempty"` + Conditions *[]DeliveryRuleCondition `json:"conditions,omitempty"` + MatchProcessingBehavior *MatchProcessingBehavior `json:"matchProcessingBehavior,omitempty"` + Order *int64 `json:"order,omitempty"` + RuleSetName *string `json:"ruleSetName,omitempty"` +} + +var _ json.Unmarshaler = &RuleUpdatePropertiesParameters{} + +func (s *RuleUpdatePropertiesParameters) UnmarshalJSON(bytes []byte) error { + type alias RuleUpdatePropertiesParameters + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RuleUpdatePropertiesParameters: %+v", err) + } + + s.MatchProcessingBehavior = decoded.MatchProcessingBehavior + s.Order = decoded.Order + s.RuleSetName = decoded.RuleSetName + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RuleUpdatePropertiesParameters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["actions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Actions into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryRuleAction, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryRuleActionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Actions' for 'RuleUpdatePropertiesParameters': %+v", i, err) + } + output = append(output, impl) + } + s.Actions = &output + } + + if v, ok := temp["conditions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Conditions into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryRuleCondition, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryRuleConditionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Conditions' for 'RuleUpdatePropertiesParameters': %+v", i, err) + } + output = append(output, impl) + } + s.Conditions = &output + } + return nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_serverportmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_serverportmatchconditionparameters.go new file mode 100644 index 00000000000..d6a39517c52 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_serverportmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = ServerPortMatchConditionParameters{} + +type ServerPortMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator ServerPortOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = ServerPortMatchConditionParameters{} + +func (s ServerPortMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper ServerPortMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ServerPortMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ServerPortMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleServerPortConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ServerPortMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_socketaddrmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_socketaddrmatchconditionparameters.go new file mode 100644 index 00000000000..fdd091305b4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_socketaddrmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = SocketAddrMatchConditionParameters{} + +type SocketAddrMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator SocketAddrOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = SocketAddrMatchConditionParameters{} + +func (s SocketAddrMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper SocketAddrMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SocketAddrMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SocketAddrMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleSocketAddrConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SocketAddrMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_sslprotocolmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_sslprotocolmatchconditionparameters.go new file mode 100644 index 00000000000..b0d7b0d9159 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_sslprotocolmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = SslProtocolMatchConditionParameters{} + +type SslProtocolMatchConditionParameters struct { + MatchValues *[]SslProtocol `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator SslProtocolOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = SslProtocolMatchConditionParameters{} + +func (s SslProtocolMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper SslProtocolMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SslProtocolMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SslProtocolMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleSslProtocolConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SslProtocolMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlfileextensionmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_urlfileextensionmatchconditionparameters.go new file mode 100644 index 00000000000..0fd336867e1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlfileextensionmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = UrlFileExtensionMatchConditionParameters{} + +type UrlFileExtensionMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator UrlFileExtensionOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = UrlFileExtensionMatchConditionParameters{} + +func (s UrlFileExtensionMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlFileExtensionMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlFileExtensionMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlFileExtensionMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlFileExtensionMatchConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlFileExtensionMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlfilenamematchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_urlfilenamematchconditionparameters.go new file mode 100644 index 00000000000..7cf2fe84433 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlfilenamematchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = UrlFileNameMatchConditionParameters{} + +type UrlFileNameMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator UrlFileNameOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = UrlFileNameMatchConditionParameters{} + +func (s UrlFileNameMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlFileNameMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlFileNameMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlFileNameMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlFilenameConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlFileNameMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlpathmatchconditionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_urlpathmatchconditionparameters.go new file mode 100644 index 00000000000..77f807ddc6c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlpathmatchconditionparameters.go @@ -0,0 +1,44 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleConditionParameters = UrlPathMatchConditionParameters{} + +type UrlPathMatchConditionParameters struct { + MatchValues *[]string `json:"matchValues,omitempty"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator UrlPathOperator `json:"operator"` + Transforms *[]Transform `json:"transforms,omitempty"` + + // Fields inherited from DeliveryRuleConditionParameters +} + +var _ json.Marshaler = UrlPathMatchConditionParameters{} + +func (s UrlPathMatchConditionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlPathMatchConditionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlPathMatchConditionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlPathMatchConditionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlPathMatchConditionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlPathMatchConditionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlredirectaction.go b/resource-manager/cdn/2024-02-01/rules/model_urlredirectaction.go new file mode 100644 index 00000000000..1d4cd4ad801 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlredirectaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = UrlRedirectAction{} + +type UrlRedirectAction struct { + Parameters UrlRedirectActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = UrlRedirectAction{} + +func (s UrlRedirectAction) MarshalJSON() ([]byte, error) { + type wrapper UrlRedirectAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRedirectAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRedirectAction: %+v", err) + } + decoded["name"] = "UrlRedirect" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRedirectAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlredirectactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_urlredirectactionparameters.go new file mode 100644 index 00000000000..75e8699fa1d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlredirectactionparameters.go @@ -0,0 +1,46 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = UrlRedirectActionParameters{} + +type UrlRedirectActionParameters struct { + CustomFragment *string `json:"customFragment,omitempty"` + CustomHostname *string `json:"customHostname,omitempty"` + CustomPath *string `json:"customPath,omitempty"` + CustomQueryString *string `json:"customQueryString,omitempty"` + DestinationProtocol *DestinationProtocol `json:"destinationProtocol,omitempty"` + RedirectType RedirectType `json:"redirectType"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = UrlRedirectActionParameters{} + +func (s UrlRedirectActionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlRedirectActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRedirectActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRedirectActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlRedirectActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRedirectActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlrewriteaction.go b/resource-manager/cdn/2024-02-01/rules/model_urlrewriteaction.go new file mode 100644 index 00000000000..e169d2d9a60 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlrewriteaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = UrlRewriteAction{} + +type UrlRewriteAction struct { + Parameters UrlRewriteActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = UrlRewriteAction{} + +func (s UrlRewriteAction) MarshalJSON() ([]byte, error) { + type wrapper UrlRewriteAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRewriteAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRewriteAction: %+v", err) + } + decoded["name"] = "UrlRewrite" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRewriteAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlrewriteactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_urlrewriteactionparameters.go new file mode 100644 index 00000000000..2dc6dff17a8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlrewriteactionparameters.go @@ -0,0 +1,43 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = UrlRewriteActionParameters{} + +type UrlRewriteActionParameters struct { + Destination string `json:"destination"` + PreserveUnmatchedPath *bool `json:"preserveUnmatchedPath,omitempty"` + SourcePattern string `json:"sourcePattern"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = UrlRewriteActionParameters{} + +func (s UrlRewriteActionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlRewriteActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlRewriteActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlRewriteActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlRewriteActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlRewriteActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlsigningaction.go b/resource-manager/cdn/2024-02-01/rules/model_urlsigningaction.go new file mode 100644 index 00000000000..48bcc4d7bb1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlsigningaction.go @@ -0,0 +1,41 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleAction = UrlSigningAction{} + +type UrlSigningAction struct { + Parameters UrlSigningActionParameters `json:"parameters"` + + // Fields inherited from DeliveryRuleAction +} + +var _ json.Marshaler = UrlSigningAction{} + +func (s UrlSigningAction) MarshalJSON() ([]byte, error) { + type wrapper UrlSigningAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlSigningAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlSigningAction: %+v", err) + } + decoded["name"] = "UrlSigning" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlSigningAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlsigningactionparameters.go b/resource-manager/cdn/2024-02-01/rules/model_urlsigningactionparameters.go new file mode 100644 index 00000000000..503fb295ee9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlsigningactionparameters.go @@ -0,0 +1,42 @@ +package rules + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryRuleActionParameters = UrlSigningActionParameters{} + +type UrlSigningActionParameters struct { + Algorithm *Algorithm `json:"algorithm,omitempty"` + ParameterNameOverride *[]UrlSigningParamIdentifier `json:"parameterNameOverride,omitempty"` + + // Fields inherited from DeliveryRuleActionParameters +} + +var _ json.Marshaler = UrlSigningActionParameters{} + +func (s UrlSigningActionParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlSigningActionParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlSigningActionParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlSigningActionParameters: %+v", err) + } + decoded["typeName"] = "DeliveryRuleUrlSigningActionParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlSigningActionParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/rules/model_urlsigningparamidentifier.go b/resource-manager/cdn/2024-02-01/rules/model_urlsigningparamidentifier.go new file mode 100644 index 00000000000..c8c8ae6a812 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/model_urlsigningparamidentifier.go @@ -0,0 +1,9 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UrlSigningParamIdentifier struct { + ParamIndicator ParamIndicator `json:"paramIndicator"` + ParamName string `json:"paramName"` +} diff --git a/resource-manager/cdn/2024-02-01/rules/predicates.go b/resource-manager/cdn/2024-02-01/rules/predicates.go new file mode 100644 index 00000000000..0dd99d7ba7d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/predicates.go @@ -0,0 +1,27 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RuleOperationPredicate) Matches(input Rule) 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/cdn/2024-02-01/rules/version.go b/resource-manager/cdn/2024-02-01/rules/version.go new file mode 100644 index 00000000000..9a828346241 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rules/version.go @@ -0,0 +1,12 @@ +package rules + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/rules/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/README.md b/resource-manager/cdn/2024-02-01/rulesets/README.md new file mode 100644 index 00000000000..4b99e9f4027 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/README.md @@ -0,0 +1,98 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/rulesets` Documentation + +The `rulesets` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/rulesets" +``` + + +### Client Initialization + +```go +client := rulesets.NewRuleSetsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RuleSetsClient.Create` + +```go +ctx := context.TODO() +id := rulesets.NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue") + +read, err := client.Create(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RuleSetsClient.Delete` + +```go +ctx := context.TODO() +id := rulesets.NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RuleSetsClient.Get` + +```go +ctx := context.TODO() +id := rulesets.NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue") + +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: `RuleSetsClient.ListByProfile` + +```go +ctx := context.TODO() +id := rulesets.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RuleSetsClient.ListResourceUsage` + +```go +ctx := context.TODO() +id := rulesets.NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue") + +// alternatively `client.ListResourceUsage(ctx, id)` can be used to do batched pagination +items, err := client.ListResourceUsageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cdn/2024-02-01/rulesets/client.go b/resource-manager/cdn/2024-02-01/rulesets/client.go new file mode 100644 index 00000000000..546536b1801 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/client.go @@ -0,0 +1,26 @@ +package rulesets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RuleSetsClient struct { + Client *resourcemanager.Client +} + +func NewRuleSetsClientWithBaseURI(sdkApi sdkEnv.Api) (*RuleSetsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "rulesets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RuleSetsClient: %+v", err) + } + + return &RuleSetsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/constants.go b/resource-manager/cdn/2024-02-01/rulesets/constants.go new file mode 100644 index 00000000000..4873ab357b0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/constants.go @@ -0,0 +1,145 @@ +package rulesets + +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 AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type UsageUnit string + +const ( + UsageUnitCount UsageUnit = "Count" +) + +func PossibleValuesForUsageUnit() []string { + return []string{ + string(UsageUnitCount), + } +} + +func (s *UsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUsageUnit(input string) (*UsageUnit, error) { + vals := map[string]UsageUnit{ + "count": UsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsageUnit(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/id_profile.go b/resource-manager/cdn/2024-02-01/rulesets/id_profile.go new file mode 100644 index 00000000000..306e5371f67 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/id_profile.go @@ -0,0 +1,130 @@ +package rulesets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/id_profile_test.go b/resource-manager/cdn/2024-02-01/rulesets/id_profile_test.go new file mode 100644 index 00000000000..a0e9a4ca9f1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/id_profile_test.go @@ -0,0 +1,282 @@ +package rulesets + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/rulesets/id_ruleset.go b/resource-manager/cdn/2024-02-01/rulesets/id_ruleset.go new file mode 100644 index 00000000000..cd3998f7525 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/id_ruleset.go @@ -0,0 +1,139 @@ +package rulesets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RuleSetId{}) +} + +var _ resourceids.ResourceId = &RuleSetId{} + +// RuleSetId is a struct representing the Resource ID for a Rule Set +type RuleSetId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + RuleSetName string +} + +// NewRuleSetID returns a new RuleSetId struct +func NewRuleSetID(subscriptionId string, resourceGroupName string, profileName string, ruleSetName string) RuleSetId { + return RuleSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + RuleSetName: ruleSetName, + } +} + +// ParseRuleSetID parses 'input' into a RuleSetId +func ParseRuleSetID(input string) (*RuleSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRuleSetIDInsensitively parses 'input' case-insensitively into a RuleSetId +// note: this method should only be used for API response data and not user input +func ParseRuleSetIDInsensitively(input string) (*RuleSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RuleSetId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.RuleSetName, ok = input.Parsed["ruleSetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleSetName", input) + } + + return nil +} + +// ValidateRuleSetID checks that 'input' can be parsed as a Rule Set ID +func ValidateRuleSetID(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 := ParseRuleSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rule Set ID +func (id RuleSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/ruleSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.RuleSetName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rule Set ID +func (id RuleSetId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticRuleSets", "ruleSets", "ruleSets"), + resourceids.UserSpecifiedSegment("ruleSetName", "ruleSetValue"), + } +} + +// String returns a human-readable description of this Rule Set ID +func (id RuleSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Rule Set Name: %q", id.RuleSetName), + } + return fmt.Sprintf("Rule Set (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/id_ruleset_test.go b/resource-manager/cdn/2024-02-01/rulesets/id_ruleset_test.go new file mode 100644 index 00000000000..21c4c70a82f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/id_ruleset_test.go @@ -0,0 +1,327 @@ +package rulesets + +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 = &RuleSetId{} + +func TestNewRuleSetID(t *testing.T) { + id := NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.RuleSetName != "ruleSetValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleSetName'", id.RuleSetName, "ruleSetValue") + } +} + +func TestFormatRuleSetID(t *testing.T) { + actual := NewRuleSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "ruleSetValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRuleSetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleSetId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue", + Expected: &RuleSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + RuleSetName: "ruleSetValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleSetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.RuleSetName != v.Expected.RuleSetName { + t.Fatalf("Expected %q but got %q for RuleSetName", v.Expected.RuleSetName, actual.RuleSetName) + } + + } +} + +func TestParseRuleSetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleSetId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue", + Expected: &RuleSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + RuleSetName: "ruleSetValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/ruleSets/ruleSetValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE", + Expected: &RuleSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + RuleSetName: "rUlEsEtVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/rUlEsEtS/rUlEsEtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleSetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.RuleSetName != v.Expected.RuleSetName { + t.Fatalf("Expected %q but got %q for RuleSetName", v.Expected.RuleSetName, actual.RuleSetName) + } + + } +} + +func TestSegmentsForRuleSetId(t *testing.T) { + segments := RuleSetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RuleSetId 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/cdn/2024-02-01/rulesets/method_create.go b/resource-manager/cdn/2024-02-01/rulesets/method_create.go new file mode 100644 index 00000000000..4dafa8af647 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/method_create.go @@ -0,0 +1,55 @@ +package rulesets + +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 CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RuleSet +} + +// Create ... +func (c RuleSetsClient) Create(ctx context.Context, id RuleSetId) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RuleSet + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/method_delete.go b/resource-manager/cdn/2024-02-01/rulesets/method_delete.go new file mode 100644 index 00000000000..e0f00268a45 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/method_delete.go @@ -0,0 +1,71 @@ +package rulesets + +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 RuleSetsClient) Delete(ctx context.Context, id RuleSetId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c RuleSetsClient) DeleteThenPoll(ctx context.Context, id RuleSetId) 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/cdn/2024-02-01/rulesets/method_get.go b/resource-manager/cdn/2024-02-01/rulesets/method_get.go new file mode 100644 index 00000000000..f8f2d23fac0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/method_get.go @@ -0,0 +1,54 @@ +package rulesets + +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 *RuleSet +} + +// Get ... +func (c RuleSetsClient) Get(ctx context.Context, id RuleSetId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RuleSet + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/method_listbyprofile.go b/resource-manager/cdn/2024-02-01/rulesets/method_listbyprofile.go new file mode 100644 index 00000000000..3c04ee6d0a7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/method_listbyprofile.go @@ -0,0 +1,105 @@ +package rulesets + +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 ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RuleSet +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []RuleSet +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c RuleSetsClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + Path: fmt.Sprintf("%s/ruleSets", 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 *[]RuleSet `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c RuleSetsClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, RuleSetOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RuleSetsClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate RuleSetOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]RuleSet, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/method_listresourceusage.go b/resource-manager/cdn/2024-02-01/rulesets/method_listresourceusage.go new file mode 100644 index 00000000000..08a467d0bf5 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/method_listresourceusage.go @@ -0,0 +1,105 @@ +package rulesets + +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 ListResourceUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ListResourceUsageCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ListResourceUsageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListResourceUsageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListResourceUsage ... +func (c RuleSetsClient) ListResourceUsage(ctx context.Context, id RuleSetId) (result ListResourceUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListResourceUsageCustomPager{}, + 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 *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourceUsageComplete retrieves all the results into a single object +func (c RuleSetsClient) ListResourceUsageComplete(ctx context.Context, id RuleSetId) (ListResourceUsageCompleteResult, error) { + return c.ListResourceUsageCompleteMatchingPredicate(ctx, id, UsageOperationPredicate{}) +} + +// ListResourceUsageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RuleSetsClient) ListResourceUsageCompleteMatchingPredicate(ctx context.Context, id RuleSetId, predicate UsageOperationPredicate) (result ListResourceUsageCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.ListResourceUsage(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListResourceUsageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/model_ruleset.go b/resource-manager/cdn/2024-02-01/rulesets/model_ruleset.go new file mode 100644 index 00000000000..318adf43729 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/model_ruleset.go @@ -0,0 +1,16 @@ +package rulesets + +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 RuleSet struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RuleSetProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/model_rulesetproperties.go b/resource-manager/cdn/2024-02-01/rulesets/model_rulesetproperties.go new file mode 100644 index 00000000000..55b980e2c52 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/model_rulesetproperties.go @@ -0,0 +1,10 @@ +package rulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RuleSetProperties struct { + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/model_usage.go b/resource-manager/cdn/2024-02-01/rulesets/model_usage.go new file mode 100644 index 00000000000..54f0c36919f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/model_usage.go @@ -0,0 +1,12 @@ +package rulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Usage struct { + CurrentValue int64 `json:"currentValue"` + Id *string `json:"id,omitempty"` + Limit int64 `json:"limit"` + Name UsageName `json:"name"` + Unit UsageUnit `json:"unit"` +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/model_usagename.go b/resource-manager/cdn/2024-02-01/rulesets/model_usagename.go new file mode 100644 index 00000000000..023a3d43d61 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/model_usagename.go @@ -0,0 +1,9 @@ +package rulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/predicates.go b/resource-manager/cdn/2024-02-01/rulesets/predicates.go new file mode 100644 index 00000000000..0d67bcef083 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/predicates.go @@ -0,0 +1,50 @@ +package rulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RuleSetOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RuleSetOperationPredicate) Matches(input RuleSet) 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 UsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.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 && *p.Limit != input.Limit { + return false + } + + return true +} diff --git a/resource-manager/cdn/2024-02-01/rulesets/version.go b/resource-manager/cdn/2024-02-01/rulesets/version.go new file mode 100644 index 00000000000..bb9c1216660 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/rulesets/version.go @@ -0,0 +1,12 @@ +package rulesets + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/rulesets/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/secrets/README.md b/resource-manager/cdn/2024-02-01/secrets/README.md new file mode 100644 index 00000000000..f294de0bf11 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/secrets` Documentation + +The `secrets` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/secrets" +``` + + +### Client Initialization + +```go +client := secrets.NewSecretsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SecretsClient.Create` + +```go +ctx := context.TODO() +id := secrets.NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "secretValue") + +payload := secrets.Secret{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecretsClient.Delete` + +```go +ctx := context.TODO() +id := secrets.NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "secretValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecretsClient.Get` + +```go +ctx := context.TODO() +id := secrets.NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "secretValue") + +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: `SecretsClient.ListByProfile` + +```go +ctx := context.TODO() +id := secrets.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cdn/2024-02-01/secrets/client.go b/resource-manager/cdn/2024-02-01/secrets/client.go new file mode 100644 index 00000000000..c8a49ae1e6b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/client.go @@ -0,0 +1,26 @@ +package secrets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretsClient struct { + Client *resourcemanager.Client +} + +func NewSecretsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecretsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "secrets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecretsClient: %+v", err) + } + + return &SecretsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/constants.go b/resource-manager/cdn/2024-02-01/secrets/constants.go new file mode 100644 index 00000000000..c8027d12eef --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/constants.go @@ -0,0 +1,154 @@ +package secrets + +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 AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type SecretType string + +const ( + SecretTypeAzureFirstPartyManagedCertificate SecretType = "AzureFirstPartyManagedCertificate" + SecretTypeCustomerCertificate SecretType = "CustomerCertificate" + SecretTypeManagedCertificate SecretType = "ManagedCertificate" + SecretTypeUrlSigningKey SecretType = "UrlSigningKey" +) + +func PossibleValuesForSecretType() []string { + return []string{ + string(SecretTypeAzureFirstPartyManagedCertificate), + string(SecretTypeCustomerCertificate), + string(SecretTypeManagedCertificate), + string(SecretTypeUrlSigningKey), + } +} + +func (s *SecretType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretType(input string) (*SecretType, error) { + vals := map[string]SecretType{ + "azurefirstpartymanagedcertificate": SecretTypeAzureFirstPartyManagedCertificate, + "customercertificate": SecretTypeCustomerCertificate, + "managedcertificate": SecretTypeManagedCertificate, + "urlsigningkey": SecretTypeUrlSigningKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretType(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/id_profile.go b/resource-manager/cdn/2024-02-01/secrets/id_profile.go new file mode 100644 index 00000000000..b11f3e26420 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/id_profile.go @@ -0,0 +1,130 @@ +package secrets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/secrets/id_profile_test.go b/resource-manager/cdn/2024-02-01/secrets/id_profile_test.go new file mode 100644 index 00000000000..53bc427e379 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/id_profile_test.go @@ -0,0 +1,282 @@ +package secrets + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/secrets/id_secret.go b/resource-manager/cdn/2024-02-01/secrets/id_secret.go new file mode 100644 index 00000000000..9a9a0c5aed6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/id_secret.go @@ -0,0 +1,139 @@ +package secrets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SecretId{}) +} + +var _ resourceids.ResourceId = &SecretId{} + +// SecretId is a struct representing the Resource ID for a Secret +type SecretId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + SecretName string +} + +// NewSecretID returns a new SecretId struct +func NewSecretID(subscriptionId string, resourceGroupName string, profileName string, secretName string) SecretId { + return SecretId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + SecretName: secretName, + } +} + +// ParseSecretID parses 'input' into a SecretId +func ParseSecretID(input string) (*SecretId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecretId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecretId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSecretIDInsensitively parses 'input' case-insensitively into a SecretId +// note: this method should only be used for API response data and not user input +func ParseSecretIDInsensitively(input string) (*SecretId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecretId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecretId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SecretId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.SecretName, ok = input.Parsed["secretName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "secretName", input) + } + + return nil +} + +// ValidateSecretID checks that 'input' can be parsed as a Secret ID +func ValidateSecretID(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 := ParseSecretID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Secret ID +func (id SecretId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/secrets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.SecretName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Secret ID +func (id SecretId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticSecrets", "secrets", "secrets"), + resourceids.UserSpecifiedSegment("secretName", "secretValue"), + } +} + +// String returns a human-readable description of this Secret ID +func (id SecretId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Secret Name: %q", id.SecretName), + } + return fmt.Sprintf("Secret (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/secrets/id_secret_test.go b/resource-manager/cdn/2024-02-01/secrets/id_secret_test.go new file mode 100644 index 00000000000..df1cfd25479 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/id_secret_test.go @@ -0,0 +1,327 @@ +package secrets + +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 = &SecretId{} + +func TestNewSecretID(t *testing.T) { + id := NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "secretValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.SecretName != "secretValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecretName'", id.SecretName, "secretValue") + } +} + +func TestFormatSecretID(t *testing.T) { + actual := NewSecretID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "secretValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/secrets/secretValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSecretID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecretId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/secrets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/secrets/secretValue", + Expected: &SecretId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + SecretName: "secretValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/secrets/secretValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecretID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.SecretName != v.Expected.SecretName { + t.Fatalf("Expected %q but got %q for SecretName", v.Expected.SecretName, actual.SecretName) + } + + } +} + +func TestParseSecretIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecretId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/secrets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/sEcReTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/secrets/secretValue", + Expected: &SecretId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + SecretName: "secretValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/secrets/secretValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/sEcReTs/sEcReTvAlUe", + Expected: &SecretId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + SecretName: "sEcReTvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/sEcReTs/sEcReTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecretIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.SecretName != v.Expected.SecretName { + t.Fatalf("Expected %q but got %q for SecretName", v.Expected.SecretName, actual.SecretName) + } + + } +} + +func TestSegmentsForSecretId(t *testing.T) { + segments := SecretId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SecretId 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/cdn/2024-02-01/secrets/method_create.go b/resource-manager/cdn/2024-02-01/secrets/method_create.go new file mode 100644 index 00000000000..65aac40ebab --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/method_create.go @@ -0,0 +1,76 @@ +package secrets + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Secret +} + +// Create ... +func (c SecretsClient) Create(ctx context.Context, id SecretId, input Secret) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c SecretsClient) CreateThenPoll(ctx context.Context, id SecretId, input Secret) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/method_delete.go b/resource-manager/cdn/2024-02-01/secrets/method_delete.go new file mode 100644 index 00000000000..7740a7a1b9f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/method_delete.go @@ -0,0 +1,71 @@ +package secrets + +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 SecretsClient) Delete(ctx context.Context, id SecretId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SecretsClient) DeleteThenPoll(ctx context.Context, id SecretId) 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/cdn/2024-02-01/secrets/method_get.go b/resource-manager/cdn/2024-02-01/secrets/method_get.go new file mode 100644 index 00000000000..13c1528927a --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/method_get.go @@ -0,0 +1,54 @@ +package secrets + +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 *Secret +} + +// Get ... +func (c SecretsClient) Get(ctx context.Context, id SecretId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Secret + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/secrets/method_listbyprofile.go b/resource-manager/cdn/2024-02-01/secrets/method_listbyprofile.go new file mode 100644 index 00000000000..425af171780 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/method_listbyprofile.go @@ -0,0 +1,105 @@ +package secrets + +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 ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Secret +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []Secret +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c SecretsClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + Path: fmt.Sprintf("%s/secrets", 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 *[]Secret `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c SecretsClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, SecretOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecretsClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate SecretOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]Secret, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/secrets/model_azurefirstpartymanagedcertificateparameters.go b/resource-manager/cdn/2024-02-01/secrets/model_azurefirstpartymanagedcertificateparameters.go new file mode 100644 index 00000000000..bab1eb8b245 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_azurefirstpartymanagedcertificateparameters.go @@ -0,0 +1,46 @@ +package secrets + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecretParameters = AzureFirstPartyManagedCertificateParameters{} + +type AzureFirstPartyManagedCertificateParameters struct { + CertificateAuthority *string `json:"certificateAuthority,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + SecretSource *ResourceReference `json:"secretSource,omitempty"` + Subject *string `json:"subject,omitempty"` + SubjectAlternativeNames *[]string `json:"subjectAlternativeNames,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + + // Fields inherited from SecretParameters +} + +var _ json.Marshaler = AzureFirstPartyManagedCertificateParameters{} + +func (s AzureFirstPartyManagedCertificateParameters) MarshalJSON() ([]byte, error) { + type wrapper AzureFirstPartyManagedCertificateParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFirstPartyManagedCertificateParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFirstPartyManagedCertificateParameters: %+v", err) + } + decoded["type"] = "AzureFirstPartyManagedCertificate" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFirstPartyManagedCertificateParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/model_customercertificateparameters.go b/resource-manager/cdn/2024-02-01/secrets/model_customercertificateparameters.go new file mode 100644 index 00000000000..ece8e3628ff --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_customercertificateparameters.go @@ -0,0 +1,48 @@ +package secrets + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecretParameters = CustomerCertificateParameters{} + +type CustomerCertificateParameters struct { + CertificateAuthority *string `json:"certificateAuthority,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + SecretSource ResourceReference `json:"secretSource"` + SecretVersion *string `json:"secretVersion,omitempty"` + Subject *string `json:"subject,omitempty"` + SubjectAlternativeNames *[]string `json:"subjectAlternativeNames,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + UseLatestVersion *bool `json:"useLatestVersion,omitempty"` + + // Fields inherited from SecretParameters +} + +var _ json.Marshaler = CustomerCertificateParameters{} + +func (s CustomerCertificateParameters) MarshalJSON() ([]byte, error) { + type wrapper CustomerCertificateParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CustomerCertificateParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CustomerCertificateParameters: %+v", err) + } + decoded["type"] = "CustomerCertificate" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CustomerCertificateParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/model_managedcertificateparameters.go b/resource-manager/cdn/2024-02-01/secrets/model_managedcertificateparameters.go new file mode 100644 index 00000000000..6219de832a8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_managedcertificateparameters.go @@ -0,0 +1,42 @@ +package secrets + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecretParameters = ManagedCertificateParameters{} + +type ManagedCertificateParameters struct { + ExpirationDate *string `json:"expirationDate,omitempty"` + Subject *string `json:"subject,omitempty"` + + // Fields inherited from SecretParameters +} + +var _ json.Marshaler = ManagedCertificateParameters{} + +func (s ManagedCertificateParameters) MarshalJSON() ([]byte, error) { + type wrapper ManagedCertificateParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ManagedCertificateParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ManagedCertificateParameters: %+v", err) + } + decoded["type"] = "ManagedCertificate" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ManagedCertificateParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/model_resourcereference.go b/resource-manager/cdn/2024-02-01/secrets/model_resourcereference.go new file mode 100644 index 00000000000..873436b4dd8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_resourcereference.go @@ -0,0 +1,8 @@ +package secrets + +// 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/cdn/2024-02-01/secrets/model_secret.go b/resource-manager/cdn/2024-02-01/secrets/model_secret.go new file mode 100644 index 00000000000..b6dcf9bbefb --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_secret.go @@ -0,0 +1,16 @@ +package secrets + +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 Secret struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecretProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/secrets/model_secretparameters.go b/resource-manager/cdn/2024-02-01/secrets/model_secretparameters.go new file mode 100644 index 00000000000..17fc88da98b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_secretparameters.go @@ -0,0 +1,77 @@ +package secrets + +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 SecretParameters interface { +} + +// RawSecretParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawSecretParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalSecretParametersImplementation(input []byte) (SecretParameters, 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 SecretParameters into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFirstPartyManagedCertificate") { + var out AzureFirstPartyManagedCertificateParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFirstPartyManagedCertificateParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "CustomerCertificate") { + var out CustomerCertificateParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CustomerCertificateParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ManagedCertificate") { + var out ManagedCertificateParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ManagedCertificateParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "UrlSigningKey") { + var out UrlSigningKeyParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlSigningKeyParameters: %+v", err) + } + return out, nil + } + + out := RawSecretParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/secrets/model_secretproperties.go b/resource-manager/cdn/2024-02-01/secrets/model_secretproperties.go new file mode 100644 index 00000000000..be73ff13313 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_secretproperties.go @@ -0,0 +1,44 @@ +package secrets + +import ( + "encoding/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 SecretProperties struct { + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + Parameters SecretParameters `json:"parameters"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` +} + +var _ json.Unmarshaler = &SecretProperties{} + +func (s *SecretProperties) UnmarshalJSON(bytes []byte) error { + type alias SecretProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SecretProperties: %+v", err) + } + + s.DeploymentStatus = decoded.DeploymentStatus + s.ProfileName = decoded.ProfileName + s.ProvisioningState = decoded.ProvisioningState + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SecretProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["parameters"]; ok { + impl, err := unmarshalSecretParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Parameters' for 'SecretProperties': %+v", err) + } + s.Parameters = impl + } + return nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/model_urlsigningkeyparameters.go b/resource-manager/cdn/2024-02-01/secrets/model_urlsigningkeyparameters.go new file mode 100644 index 00000000000..0e3a8b3a729 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/model_urlsigningkeyparameters.go @@ -0,0 +1,43 @@ +package secrets + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecretParameters = UrlSigningKeyParameters{} + +type UrlSigningKeyParameters struct { + KeyId string `json:"keyId"` + SecretSource ResourceReference `json:"secretSource"` + SecretVersion *string `json:"secretVersion,omitempty"` + + // Fields inherited from SecretParameters +} + +var _ json.Marshaler = UrlSigningKeyParameters{} + +func (s UrlSigningKeyParameters) MarshalJSON() ([]byte, error) { + type wrapper UrlSigningKeyParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlSigningKeyParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlSigningKeyParameters: %+v", err) + } + decoded["type"] = "UrlSigningKey" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlSigningKeyParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/secrets/predicates.go b/resource-manager/cdn/2024-02-01/secrets/predicates.go new file mode 100644 index 00000000000..7bff4879b50 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/predicates.go @@ -0,0 +1,27 @@ +package secrets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SecretOperationPredicate) Matches(input Secret) 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/cdn/2024-02-01/secrets/version.go b/resource-manager/cdn/2024-02-01/secrets/version.go new file mode 100644 index 00000000000..0eb551f3ec9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/secrets/version.go @@ -0,0 +1,12 @@ +package secrets + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/secrets/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/README.md b/resource-manager/cdn/2024-02-01/securitypolicies/README.md new file mode 100644 index 00000000000..ebd6d2272a4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies` Documentation + +The `securitypolicies` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/securitypolicies" +``` + + +### Client Initialization + +```go +client := securitypolicies.NewSecurityPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SecurityPoliciesClient.Create` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "securityPolicyValue") + +payload := securitypolicies.SecurityPolicy{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecurityPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "securityPolicyValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecurityPoliciesClient.Get` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "securityPolicyValue") + +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: `SecurityPoliciesClient.ListByProfile` + +```go +ctx := context.TODO() +id := securitypolicies.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SecurityPoliciesClient.Patch` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "securityPolicyValue") + +payload := securitypolicies.SecurityPolicyUpdateParameters{ + // ... +} + + +if err := client.PatchThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/client.go b/resource-manager/cdn/2024-02-01/securitypolicies/client.go new file mode 100644 index 00000000000..fdfadde5667 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/client.go @@ -0,0 +1,26 @@ +package securitypolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewSecurityPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "securitypolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityPoliciesClient: %+v", err) + } + + return &SecurityPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/constants.go b/resource-manager/cdn/2024-02-01/securitypolicies/constants.go new file mode 100644 index 00000000000..7354c2cb326 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/constants.go @@ -0,0 +1,145 @@ +package securitypolicies + +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 AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type SecurityPolicyType string + +const ( + SecurityPolicyTypeWebApplicationFirewall SecurityPolicyType = "WebApplicationFirewall" +) + +func PossibleValuesForSecurityPolicyType() []string { + return []string{ + string(SecurityPolicyTypeWebApplicationFirewall), + } +} + +func (s *SecurityPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityPolicyType(input string) (*SecurityPolicyType, error) { + vals := map[string]SecurityPolicyType{ + "webapplicationfirewall": SecurityPolicyTypeWebApplicationFirewall, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityPolicyType(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/id_profile.go b/resource-manager/cdn/2024-02-01/securitypolicies/id_profile.go new file mode 100644 index 00000000000..871771ba412 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/id_profile.go @@ -0,0 +1,130 @@ +package securitypolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/id_profile_test.go b/resource-manager/cdn/2024-02-01/securitypolicies/id_profile_test.go new file mode 100644 index 00000000000..1ff9b3c3b84 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/id_profile_test.go @@ -0,0 +1,282 @@ +package securitypolicies + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/securitypolicies/id_securitypolicy.go b/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy.go new file mode 100644 index 00000000000..0288df4f5c4 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy.go @@ -0,0 +1,139 @@ +package securitypolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SecurityPolicyId{}) +} + +var _ resourceids.ResourceId = &SecurityPolicyId{} + +// SecurityPolicyId is a struct representing the Resource ID for a Security Policy +type SecurityPolicyId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + SecurityPolicyName string +} + +// NewSecurityPolicyID returns a new SecurityPolicyId struct +func NewSecurityPolicyID(subscriptionId string, resourceGroupName string, profileName string, securityPolicyName string) SecurityPolicyId { + return SecurityPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + SecurityPolicyName: securityPolicyName, + } +} + +// ParseSecurityPolicyID parses 'input' into a SecurityPolicyId +func ParseSecurityPolicyID(input string) (*SecurityPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSecurityPolicyIDInsensitively parses 'input' case-insensitively into a SecurityPolicyId +// note: this method should only be used for API response data and not user input +func ParseSecurityPolicyIDInsensitively(input string) (*SecurityPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SecurityPolicyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.SecurityPolicyName, ok = input.Parsed["securityPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityPolicyName", input) + } + + return nil +} + +// ValidateSecurityPolicyID checks that 'input' can be parsed as a Security Policy ID +func ValidateSecurityPolicyID(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 := ParseSecurityPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Security Policy ID +func (id SecurityPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/securityPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.SecurityPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Security Policy ID +func (id SecurityPolicyId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + resourceids.StaticSegment("staticSecurityPolicies", "securityPolicies", "securityPolicies"), + resourceids.UserSpecifiedSegment("securityPolicyName", "securityPolicyValue"), + } +} + +// String returns a human-readable description of this Security Policy ID +func (id SecurityPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Security Policy Name: %q", id.SecurityPolicyName), + } + return fmt.Sprintf("Security Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy_test.go b/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy_test.go new file mode 100644 index 00000000000..211c76c7204 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy_test.go @@ -0,0 +1,327 @@ +package securitypolicies + +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 = &SecurityPolicyId{} + +func TestNewSecurityPolicyID(t *testing.T) { + id := NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "securityPolicyValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } + + if id.SecurityPolicyName != "securityPolicyValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityPolicyName'", id.SecurityPolicyName, "securityPolicyValue") + } +} + +func TestFormatSecurityPolicyID(t *testing.T) { + actual := NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue", "securityPolicyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/securityPolicies/securityPolicyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSecurityPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityPolicyId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/securityPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/securityPolicies/securityPolicyValue", + Expected: &SecurityPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + SecurityPolicyName: "securityPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/securityPolicies/securityPolicyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityPolicyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.SecurityPolicyName != v.Expected.SecurityPolicyName { + t.Fatalf("Expected %q but got %q for SecurityPolicyName", v.Expected.SecurityPolicyName, actual.SecurityPolicyName) + } + + } +} + +func TestParseSecurityPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityPolicyId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/securityPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/sEcUrItYpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/securityPolicies/securityPolicyValue", + Expected: &SecurityPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + SecurityPolicyName: "securityPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/securityPolicies/securityPolicyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE/sEcUrItYpOlIcIeS/sEcUrItYpOlIcYvAlUe", + Expected: &SecurityPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + SecurityPolicyName: "sEcUrItYpOlIcYvAlUe", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/sEcUrItYpOlIcIeS/sEcUrItYpOlIcYvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityPolicyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + if actual.SecurityPolicyName != v.Expected.SecurityPolicyName { + t.Fatalf("Expected %q but got %q for SecurityPolicyName", v.Expected.SecurityPolicyName, actual.SecurityPolicyName) + } + + } +} + +func TestSegmentsForSecurityPolicyId(t *testing.T) { + segments := SecurityPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SecurityPolicyId 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/cdn/2024-02-01/securitypolicies/method_create.go b/resource-manager/cdn/2024-02-01/securitypolicies/method_create.go new file mode 100644 index 00000000000..a95ec9d76fd --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/method_create.go @@ -0,0 +1,76 @@ +package securitypolicies + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// Create ... +func (c SecurityPoliciesClient) Create(ctx context.Context, id SecurityPolicyId, input SecurityPolicy) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c SecurityPoliciesClient) CreateThenPoll(ctx context.Context, id SecurityPolicyId, input SecurityPolicy) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/method_delete.go b/resource-manager/cdn/2024-02-01/securitypolicies/method_delete.go new file mode 100644 index 00000000000..9367d103c07 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/method_delete.go @@ -0,0 +1,71 @@ +package securitypolicies + +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 SecurityPoliciesClient) Delete(ctx context.Context, id SecurityPolicyId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SecurityPoliciesClient) DeleteThenPoll(ctx context.Context, id SecurityPolicyId) 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/cdn/2024-02-01/securitypolicies/method_get.go b/resource-manager/cdn/2024-02-01/securitypolicies/method_get.go new file mode 100644 index 00000000000..f88d7753dcc --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/method_get.go @@ -0,0 +1,54 @@ +package securitypolicies + +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 *SecurityPolicy +} + +// Get ... +func (c SecurityPoliciesClient) Get(ctx context.Context, id SecurityPolicyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SecurityPolicy + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/method_listbyprofile.go b/resource-manager/cdn/2024-02-01/securitypolicies/method_listbyprofile.go new file mode 100644 index 00000000000..322dbf96b30 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/method_listbyprofile.go @@ -0,0 +1,105 @@ +package securitypolicies + +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 ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityPolicy +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityPolicy +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c SecurityPoliciesClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + Path: fmt.Sprintf("%s/securityPolicies", 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 *[]SecurityPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c SecurityPoliciesClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, SecurityPolicyOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityPoliciesClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate SecurityPolicyOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]SecurityPolicy, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/method_patch.go b/resource-manager/cdn/2024-02-01/securitypolicies/method_patch.go new file mode 100644 index 00000000000..c0f9a10b203 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/method_patch.go @@ -0,0 +1,75 @@ +package securitypolicies + +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 PatchOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// Patch ... +func (c SecurityPoliciesClient) Patch(ctx context.Context, id SecurityPolicyId, input SecurityPolicyUpdateParameters) (result PatchOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PatchThenPoll performs Patch then polls until it's completed +func (c SecurityPoliciesClient) PatchThenPoll(ctx context.Context, id SecurityPolicyId, input SecurityPolicyUpdateParameters) error { + result, err := c.Patch(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Patch: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Patch: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_activatedresourcereference.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_activatedresourcereference.go new file mode 100644 index 00000000000..98cdc9bedc9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_activatedresourcereference.go @@ -0,0 +1,9 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActivatedResourceReference struct { + Id *string `json:"id,omitempty"` + IsActive *bool `json:"isActive,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_resourcereference.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_resourcereference.go new file mode 100644 index 00000000000..d5146482393 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_resourcereference.go @@ -0,0 +1,8 @@ +package securitypolicies + +// 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/cdn/2024-02-01/securitypolicies/model_securitypolicy.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicy.go new file mode 100644 index 00000000000..798a87168df --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicy.go @@ -0,0 +1,16 @@ +package securitypolicies + +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 SecurityPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyproperties.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyproperties.go new file mode 100644 index 00000000000..65a10e3e059 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyproperties.go @@ -0,0 +1,44 @@ +package securitypolicies + +import ( + "encoding/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 SecurityPolicyProperties struct { + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + Parameters SecurityPolicyPropertiesParameters `json:"parameters"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` +} + +var _ json.Unmarshaler = &SecurityPolicyProperties{} + +func (s *SecurityPolicyProperties) UnmarshalJSON(bytes []byte) error { + type alias SecurityPolicyProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SecurityPolicyProperties: %+v", err) + } + + s.DeploymentStatus = decoded.DeploymentStatus + s.ProfileName = decoded.ProfileName + s.ProvisioningState = decoded.ProvisioningState + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SecurityPolicyProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["parameters"]; ok { + impl, err := unmarshalSecurityPolicyPropertiesParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Parameters' for 'SecurityPolicyProperties': %+v", err) + } + s.Parameters = impl + } + return nil +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicypropertiesparameters.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicypropertiesparameters.go new file mode 100644 index 00000000000..36cc03209b7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicypropertiesparameters.go @@ -0,0 +1,53 @@ +package securitypolicies + +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 SecurityPolicyPropertiesParameters interface { +} + +// RawSecurityPolicyPropertiesParametersImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawSecurityPolicyPropertiesParametersImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalSecurityPolicyPropertiesParametersImplementation(input []byte) (SecurityPolicyPropertiesParameters, 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 SecurityPolicyPropertiesParameters into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "WebApplicationFirewall") { + var out SecurityPolicyWebApplicationFirewallParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + return out, nil + } + + out := RawSecurityPolicyPropertiesParametersImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateparameters.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateparameters.go new file mode 100644 index 00000000000..c9ee5951959 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateparameters.go @@ -0,0 +1,8 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyUpdateParameters struct { + Properties *SecurityPolicyUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateproperties.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateproperties.go new file mode 100644 index 00000000000..4146652bdd2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateproperties.go @@ -0,0 +1,32 @@ +package securitypolicies + +import ( + "encoding/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 SecurityPolicyUpdateProperties struct { + Parameters SecurityPolicyPropertiesParameters `json:"parameters"` +} + +var _ json.Unmarshaler = &SecurityPolicyUpdateProperties{} + +func (s *SecurityPolicyUpdateProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SecurityPolicyUpdateProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["parameters"]; ok { + impl, err := unmarshalSecurityPolicyPropertiesParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Parameters' for 'SecurityPolicyUpdateProperties': %+v", err) + } + s.Parameters = impl + } + return nil +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallassociation.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallassociation.go new file mode 100644 index 00000000000..78cfbe4a259 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallassociation.go @@ -0,0 +1,9 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyWebApplicationFirewallAssociation struct { + Domains *[]ActivatedResourceReference `json:"domains,omitempty"` + PatternsToMatch *[]string `json:"patternsToMatch,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallparameters.go b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallparameters.go new file mode 100644 index 00000000000..47b387095c8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallparameters.go @@ -0,0 +1,42 @@ +package securitypolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecurityPolicyPropertiesParameters = SecurityPolicyWebApplicationFirewallParameters{} + +type SecurityPolicyWebApplicationFirewallParameters struct { + Associations *[]SecurityPolicyWebApplicationFirewallAssociation `json:"associations,omitempty"` + WafPolicy *ResourceReference `json:"wafPolicy,omitempty"` + + // Fields inherited from SecurityPolicyPropertiesParameters +} + +var _ json.Marshaler = SecurityPolicyWebApplicationFirewallParameters{} + +func (s SecurityPolicyWebApplicationFirewallParameters) MarshalJSON() ([]byte, error) { + type wrapper SecurityPolicyWebApplicationFirewallParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + decoded["type"] = "WebApplicationFirewall" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/cdn/2024-02-01/securitypolicies/predicates.go b/resource-manager/cdn/2024-02-01/securitypolicies/predicates.go new file mode 100644 index 00000000000..4b70b7eef24 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/predicates.go @@ -0,0 +1,27 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SecurityPolicyOperationPredicate) Matches(input SecurityPolicy) 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/cdn/2024-02-01/securitypolicies/version.go b/resource-manager/cdn/2024-02-01/securitypolicies/version.go new file mode 100644 index 00000000000..4596f6537be --- /dev/null +++ b/resource-manager/cdn/2024-02-01/securitypolicies/version.go @@ -0,0 +1,12 @@ +package securitypolicies + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/securitypolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/validateprobe/README.md b/resource-manager/cdn/2024-02-01/validateprobe/README.md new file mode 100644 index 00000000000..610491907a0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/validateprobe/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/validateprobe` Documentation + +The `validateprobe` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/validateprobe" +``` + + +### Client Initialization + +```go +client := validateprobe.NewValidateProbeClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ValidateProbeClient.ValidateProbe` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := validateprobe.ValidateProbeInput{ + // ... +} + + +read, err := client.ValidateProbe(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/cdn/2024-02-01/validateprobe/client.go b/resource-manager/cdn/2024-02-01/validateprobe/client.go new file mode 100644 index 00000000000..7af4cfb36cb --- /dev/null +++ b/resource-manager/cdn/2024-02-01/validateprobe/client.go @@ -0,0 +1,26 @@ +package validateprobe + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateProbeClient struct { + Client *resourcemanager.Client +} + +func NewValidateProbeClientWithBaseURI(sdkApi sdkEnv.Api) (*ValidateProbeClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "validateprobe", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ValidateProbeClient: %+v", err) + } + + return &ValidateProbeClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/validateprobe/method_validateprobe.go b/resource-manager/cdn/2024-02-01/validateprobe/method_validateprobe.go new file mode 100644 index 00000000000..21614159cf8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/validateprobe/method_validateprobe.go @@ -0,0 +1,60 @@ +package validateprobe + +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 ValidateProbeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ValidateProbeOutput +} + +// ValidateProbe ... +func (c ValidateProbeClient) ValidateProbe(ctx context.Context, id commonids.SubscriptionId, input ValidateProbeInput) (result ValidateProbeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/validateProbe", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ValidateProbeOutput + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/validateprobe/model_validateprobeinput.go b/resource-manager/cdn/2024-02-01/validateprobe/model_validateprobeinput.go new file mode 100644 index 00000000000..cdc3cc24a15 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/validateprobe/model_validateprobeinput.go @@ -0,0 +1,8 @@ +package validateprobe + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateProbeInput struct { + ProbeURL string `json:"probeURL"` +} diff --git a/resource-manager/cdn/2024-02-01/validateprobe/model_validateprobeoutput.go b/resource-manager/cdn/2024-02-01/validateprobe/model_validateprobeoutput.go new file mode 100644 index 00000000000..a6e30c2b48e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/validateprobe/model_validateprobeoutput.go @@ -0,0 +1,10 @@ +package validateprobe + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateProbeOutput struct { + ErrorCode *string `json:"errorCode,omitempty"` + IsValid *bool `json:"isValid,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/validateprobe/version.go b/resource-manager/cdn/2024-02-01/validateprobe/version.go new file mode 100644 index 00000000000..8010d1cebde --- /dev/null +++ b/resource-manager/cdn/2024-02-01/validateprobe/version.go @@ -0,0 +1,12 @@ +package validateprobe + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/validateprobe/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/README.md b/resource-manager/cdn/2024-02-01/wafloganalytics/README.md new file mode 100644 index 00000000000..5c29255a8b1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/wafloganalytics` Documentation + +The `wafloganalytics` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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/cdn/2024-02-01/wafloganalytics" +``` + + +### Client Initialization + +```go +client := wafloganalytics.NewWafLogAnalyticsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WafLogAnalyticsClient.LogAnalyticsGetWafLogAnalyticsMetrics` + +```go +ctx := context.TODO() +id := wafloganalytics.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.LogAnalyticsGetWafLogAnalyticsMetrics(ctx, id, wafloganalytics.DefaultLogAnalyticsGetWafLogAnalyticsMetricsOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WafLogAnalyticsClient.LogAnalyticsGetWafLogAnalyticsRankings` + +```go +ctx := context.TODO() +id := wafloganalytics.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + +read, err := client.LogAnalyticsGetWafLogAnalyticsRankings(ctx, id, wafloganalytics.DefaultLogAnalyticsGetWafLogAnalyticsRankingsOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/client.go b/resource-manager/cdn/2024-02-01/wafloganalytics/client.go new file mode 100644 index 00000000000..2fb646d94ae --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/client.go @@ -0,0 +1,26 @@ +package wafloganalytics + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafLogAnalyticsClient struct { + Client *resourcemanager.Client +} + +func NewWafLogAnalyticsClientWithBaseURI(sdkApi sdkEnv.Api) (*WafLogAnalyticsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "wafloganalytics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WafLogAnalyticsClient: %+v", err) + } + + return &WafLogAnalyticsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/constants.go b/resource-manager/cdn/2024-02-01/wafloganalytics/constants.go new file mode 100644 index 00000000000..a7b76c70b96 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/constants.go @@ -0,0 +1,136 @@ +package wafloganalytics + +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 WafGranularity string + +const ( + WafGranularityPOneD WafGranularity = "P1D" + WafGranularityPTFiveM WafGranularity = "PT5M" + WafGranularityPTOneH WafGranularity = "PT1H" +) + +func PossibleValuesForWafGranularity() []string { + return []string{ + string(WafGranularityPOneD), + string(WafGranularityPTFiveM), + string(WafGranularityPTOneH), + } +} + +func (s *WafGranularity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWafGranularity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWafGranularity(input string) (*WafGranularity, error) { + vals := map[string]WafGranularity{ + "p1d": WafGranularityPOneD, + "pt5m": WafGranularityPTFiveM, + "pt1h": WafGranularityPTOneH, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WafGranularity(input) + return &out, nil +} + +type WafMetricsGranularity string + +const ( + WafMetricsGranularityPOneD WafMetricsGranularity = "P1D" + WafMetricsGranularityPTFiveM WafMetricsGranularity = "PT5M" + WafMetricsGranularityPTOneH WafMetricsGranularity = "PT1H" +) + +func PossibleValuesForWafMetricsGranularity() []string { + return []string{ + string(WafMetricsGranularityPOneD), + string(WafMetricsGranularityPTFiveM), + string(WafMetricsGranularityPTOneH), + } +} + +func (s *WafMetricsGranularity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWafMetricsGranularity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWafMetricsGranularity(input string) (*WafMetricsGranularity, error) { + vals := map[string]WafMetricsGranularity{ + "p1d": WafMetricsGranularityPOneD, + "pt5m": WafMetricsGranularityPTFiveM, + "pt1h": WafMetricsGranularityPTOneH, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WafMetricsGranularity(input) + return &out, nil +} + +type WafMetricsSeriesUnit string + +const ( + WafMetricsSeriesUnitCount WafMetricsSeriesUnit = "count" +) + +func PossibleValuesForWafMetricsSeriesUnit() []string { + return []string{ + string(WafMetricsSeriesUnitCount), + } +} + +func (s *WafMetricsSeriesUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWafMetricsSeriesUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWafMetricsSeriesUnit(input string) (*WafMetricsSeriesUnit, error) { + vals := map[string]WafMetricsSeriesUnit{ + "count": WafMetricsSeriesUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WafMetricsSeriesUnit(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/id_profile.go b/resource-manager/cdn/2024-02-01/wafloganalytics/id_profile.go new file mode 100644 index 00000000000..216510372b6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/id_profile.go @@ -0,0 +1,130 @@ +package wafloganalytics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(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 := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileValue"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/id_profile_test.go b/resource-manager/cdn/2024-02-01/wafloganalytics/id_profile_test.go new file mode 100644 index 00000000000..556f85b7d11 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/id_profile_test.go @@ -0,0 +1,282 @@ +package wafloganalytics + +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 = &ProfileId{} + +func TestNewProfileID(t *testing.T) { + id := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue") + + 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.ProfileName != "profileValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProfileName'", id.ProfileName, "profileValue") + } +} + +func TestFormatProfileID(t *testing.T) { + actual := NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestParseProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProfileId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProfileName: "profileValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/profiles/profileValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/pRoFiLeS/pRoFiLeVaLuE", + Expected: &ProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProfileName: "pRoFiLeVaLuE", + }, + }, + { + // 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.cDn/pRoFiLeS/pRoFiLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ProfileName != v.Expected.ProfileName { + t.Fatalf("Expected %q but got %q for ProfileName", v.Expected.ProfileName, actual.ProfileName) + } + + } +} + +func TestSegmentsForProfileId(t *testing.T) { + segments := ProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProfileId 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/cdn/2024-02-01/wafloganalytics/method_loganalyticsgetwafloganalyticsmetrics.go b/resource-manager/cdn/2024-02-01/wafloganalytics/method_loganalyticsgetwafloganalyticsmetrics.go new file mode 100644 index 00000000000..7e7a52ec887 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/method_loganalyticsgetwafloganalyticsmetrics.go @@ -0,0 +1,107 @@ +package wafloganalytics + +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 LogAnalyticsGetWafLogAnalyticsMetricsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WafMetricsResponse +} + +type LogAnalyticsGetWafLogAnalyticsMetricsOperationOptions struct { + Actions *[]string + DateTimeBegin *string + DateTimeEnd *string + Granularity *WafGranularity + GroupBy *[]string + Metrics *[]string + RuleTypes *[]string +} + +func DefaultLogAnalyticsGetWafLogAnalyticsMetricsOperationOptions() LogAnalyticsGetWafLogAnalyticsMetricsOperationOptions { + return LogAnalyticsGetWafLogAnalyticsMetricsOperationOptions{} +} + +func (o LogAnalyticsGetWafLogAnalyticsMetricsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o LogAnalyticsGetWafLogAnalyticsMetricsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o LogAnalyticsGetWafLogAnalyticsMetricsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Actions != nil { + out.Append("actions", fmt.Sprintf("%v", *o.Actions)) + } + if o.DateTimeBegin != nil { + out.Append("dateTimeBegin", fmt.Sprintf("%v", *o.DateTimeBegin)) + } + if o.DateTimeEnd != nil { + out.Append("dateTimeEnd", fmt.Sprintf("%v", *o.DateTimeEnd)) + } + if o.Granularity != nil { + out.Append("granularity", fmt.Sprintf("%v", *o.Granularity)) + } + if o.GroupBy != nil { + out.Append("groupBy", fmt.Sprintf("%v", *o.GroupBy)) + } + if o.Metrics != nil { + out.Append("metrics", fmt.Sprintf("%v", *o.Metrics)) + } + if o.RuleTypes != nil { + out.Append("ruleTypes", fmt.Sprintf("%v", *o.RuleTypes)) + } + return &out +} + +// LogAnalyticsGetWafLogAnalyticsMetrics ... +func (c WafLogAnalyticsClient) LogAnalyticsGetWafLogAnalyticsMetrics(ctx context.Context, id ProfileId, options LogAnalyticsGetWafLogAnalyticsMetricsOperationOptions) (result LogAnalyticsGetWafLogAnalyticsMetricsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/getWafLogAnalyticsMetrics", 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 + } + + var model WafMetricsResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/method_loganalyticsgetwafloganalyticsrankings.go b/resource-manager/cdn/2024-02-01/wafloganalytics/method_loganalyticsgetwafloganalyticsrankings.go new file mode 100644 index 00000000000..69bdeebaa78 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/method_loganalyticsgetwafloganalyticsrankings.go @@ -0,0 +1,107 @@ +package wafloganalytics + +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 LogAnalyticsGetWafLogAnalyticsRankingsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WafRankingsResponse +} + +type LogAnalyticsGetWafLogAnalyticsRankingsOperationOptions struct { + Actions *[]string + DateTimeBegin *string + DateTimeEnd *string + MaxRanking *int64 + Metrics *[]string + Rankings *[]string + RuleTypes *[]string +} + +func DefaultLogAnalyticsGetWafLogAnalyticsRankingsOperationOptions() LogAnalyticsGetWafLogAnalyticsRankingsOperationOptions { + return LogAnalyticsGetWafLogAnalyticsRankingsOperationOptions{} +} + +func (o LogAnalyticsGetWafLogAnalyticsRankingsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o LogAnalyticsGetWafLogAnalyticsRankingsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o LogAnalyticsGetWafLogAnalyticsRankingsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Actions != nil { + out.Append("actions", fmt.Sprintf("%v", *o.Actions)) + } + if o.DateTimeBegin != nil { + out.Append("dateTimeBegin", fmt.Sprintf("%v", *o.DateTimeBegin)) + } + if o.DateTimeEnd != nil { + out.Append("dateTimeEnd", fmt.Sprintf("%v", *o.DateTimeEnd)) + } + if o.MaxRanking != nil { + out.Append("maxRanking", fmt.Sprintf("%v", *o.MaxRanking)) + } + if o.Metrics != nil { + out.Append("metrics", fmt.Sprintf("%v", *o.Metrics)) + } + if o.Rankings != nil { + out.Append("rankings", fmt.Sprintf("%v", *o.Rankings)) + } + if o.RuleTypes != nil { + out.Append("ruleTypes", fmt.Sprintf("%v", *o.RuleTypes)) + } + return &out +} + +// LogAnalyticsGetWafLogAnalyticsRankings ... +func (c WafLogAnalyticsClient) LogAnalyticsGetWafLogAnalyticsRankings(ctx context.Context, id ProfileId, options LogAnalyticsGetWafLogAnalyticsRankingsOperationOptions) (result LogAnalyticsGetWafLogAnalyticsRankingsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/getWafLogAnalyticsRankings", 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 + } + + var model WafRankingsResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponse.go b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponse.go new file mode 100644 index 00000000000..290fdaacf39 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponse.go @@ -0,0 +1,41 @@ +package wafloganalytics + +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 WafMetricsResponse struct { + DateTimeBegin *string `json:"dateTimeBegin,omitempty"` + DateTimeEnd *string `json:"dateTimeEnd,omitempty"` + Granularity *WafMetricsGranularity `json:"granularity,omitempty"` + Series *[]WafMetricsResponseSeriesInlined `json:"series,omitempty"` +} + +func (o *WafMetricsResponse) GetDateTimeBeginAsTime() (*time.Time, error) { + if o.DateTimeBegin == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeBegin, "2006-01-02T15:04:05Z07:00") +} + +func (o *WafMetricsResponse) SetDateTimeBeginAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeBegin = &formatted +} + +func (o *WafMetricsResponse) GetDateTimeEndAsTime() (*time.Time, error) { + if o.DateTimeEnd == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeEnd, "2006-01-02T15:04:05Z07:00") +} + +func (o *WafMetricsResponse) SetDateTimeEndAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeEnd = &formatted +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlined.go b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlined.go new file mode 100644 index 00000000000..684ed281daf --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlined.go @@ -0,0 +1,11 @@ +package wafloganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafMetricsResponseSeriesInlined struct { + Data *[]WafMetricsResponseSeriesInlinedDataInlined `json:"data,omitempty"` + Groups *[]WafMetricsResponseSeriesInlinedGroupsInlined `json:"groups,omitempty"` + Metric *string `json:"metric,omitempty"` + Unit *WafMetricsSeriesUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlineddatainlined.go b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlineddatainlined.go new file mode 100644 index 00000000000..d4ed9da14f3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlineddatainlined.go @@ -0,0 +1,27 @@ +package wafloganalytics + +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 WafMetricsResponseSeriesInlinedDataInlined struct { + DateTime *string `json:"dateTime,omitempty"` + Value *float64 `json:"value,omitempty"` +} + +func (o *WafMetricsResponseSeriesInlinedDataInlined) GetDateTimeAsTime() (*time.Time, error) { + if o.DateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *WafMetricsResponseSeriesInlinedDataInlined) SetDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTime = &formatted +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlinedgroupsinlined.go b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlinedgroupsinlined.go new file mode 100644 index 00000000000..df00ac2df23 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafmetricsresponseseriesinlinedgroupsinlined.go @@ -0,0 +1,9 @@ +package wafloganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafMetricsResponseSeriesInlinedGroupsInlined struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponse.go b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponse.go new file mode 100644 index 00000000000..a19dd330615 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponse.go @@ -0,0 +1,41 @@ +package wafloganalytics + +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 WafRankingsResponse struct { + Data *[]WafRankingsResponseDataInlined `json:"data,omitempty"` + DateTimeBegin *string `json:"dateTimeBegin,omitempty"` + DateTimeEnd *string `json:"dateTimeEnd,omitempty"` + Groups *[]string `json:"groups,omitempty"` +} + +func (o *WafRankingsResponse) GetDateTimeBeginAsTime() (*time.Time, error) { + if o.DateTimeBegin == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeBegin, "2006-01-02T15:04:05Z07:00") +} + +func (o *WafRankingsResponse) SetDateTimeBeginAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeBegin = &formatted +} + +func (o *WafRankingsResponse) GetDateTimeEndAsTime() (*time.Time, error) { + if o.DateTimeEnd == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DateTimeEnd, "2006-01-02T15:04:05Z07:00") +} + +func (o *WafRankingsResponse) SetDateTimeEndAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DateTimeEnd = &formatted +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponsedatainlined.go b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponsedatainlined.go new file mode 100644 index 00000000000..920ad82073f --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponsedatainlined.go @@ -0,0 +1,9 @@ +package wafloganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafRankingsResponseDataInlined struct { + GroupValues *[]string `json:"groupValues,omitempty"` + Metrics *[]WafRankingsResponseDataInlinedMetricsInlined `json:"metrics,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponsedatainlinedmetricsinlined.go b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponsedatainlinedmetricsinlined.go new file mode 100644 index 00000000000..995bfd9deee --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/model_wafrankingsresponsedatainlinedmetricsinlined.go @@ -0,0 +1,10 @@ +package wafloganalytics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafRankingsResponseDataInlinedMetricsInlined struct { + Metric *string `json:"metric,omitempty"` + Percentage *float64 `json:"percentage,omitempty"` + Value *int64 `json:"value,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/wafloganalytics/version.go b/resource-manager/cdn/2024-02-01/wafloganalytics/version.go new file mode 100644 index 00000000000..d8d0d7ca444 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/wafloganalytics/version.go @@ -0,0 +1,12 @@ +package wafloganalytics + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/wafloganalytics/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/README.md b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/README.md new file mode 100644 index 00000000000..42c25566fe2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets` Documentation + +The `webapplicationfirewallmanagedrulesets` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets" +``` + + +### Client Initialization + +```go +client := webapplicationfirewallmanagedrulesets.NewWebApplicationFirewallManagedRuleSetsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WebApplicationFirewallManagedRuleSetsClient.ManagedRuleSetsList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ManagedRuleSetsList(ctx, id)` can be used to do batched pagination +items, err := client.ManagedRuleSetsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/client.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/client.go new file mode 100644 index 00000000000..2320599c025 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/client.go @@ -0,0 +1,26 @@ +package webapplicationfirewallmanagedrulesets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebApplicationFirewallManagedRuleSetsClient struct { + Client *resourcemanager.Client +} + +func NewWebApplicationFirewallManagedRuleSetsClientWithBaseURI(sdkApi sdkEnv.Api) (*WebApplicationFirewallManagedRuleSetsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "webapplicationfirewallmanagedrulesets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WebApplicationFirewallManagedRuleSetsClient: %+v", err) + } + + return &WebApplicationFirewallManagedRuleSetsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/constants.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/constants.go new file mode 100644 index 00000000000..62ef54e4413 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/constants.go @@ -0,0 +1,84 @@ +package webapplicationfirewallmanagedrulesets + +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 SkuName string + +const ( + SkuNameCustomVerizon SkuName = "Custom_Verizon" + SkuNamePremiumAzureFrontDoor SkuName = "Premium_AzureFrontDoor" + SkuNamePremiumVerizon SkuName = "Premium_Verizon" + SkuNameStandardAkamai SkuName = "Standard_Akamai" + SkuNameStandardAvgBandWidthChinaCdn SkuName = "Standard_AvgBandWidth_ChinaCdn" + SkuNameStandardAzureFrontDoor SkuName = "Standard_AzureFrontDoor" + SkuNameStandardChinaCdn SkuName = "Standard_ChinaCdn" + SkuNameStandardMicrosoft SkuName = "Standard_Microsoft" + SkuNameStandardNineFiveFiveBandWidthChinaCdn SkuName = "Standard_955BandWidth_ChinaCdn" + SkuNameStandardPlusAvgBandWidthChinaCdn SkuName = "StandardPlus_AvgBandWidth_ChinaCdn" + SkuNameStandardPlusChinaCdn SkuName = "StandardPlus_ChinaCdn" + SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn SkuName = "StandardPlus_955BandWidth_ChinaCdn" + SkuNameStandardVerizon SkuName = "Standard_Verizon" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameCustomVerizon), + string(SkuNamePremiumAzureFrontDoor), + string(SkuNamePremiumVerizon), + string(SkuNameStandardAkamai), + string(SkuNameStandardAvgBandWidthChinaCdn), + string(SkuNameStandardAzureFrontDoor), + string(SkuNameStandardChinaCdn), + string(SkuNameStandardMicrosoft), + string(SkuNameStandardNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardPlusAvgBandWidthChinaCdn), + string(SkuNameStandardPlusChinaCdn), + string(SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardVerizon), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "custom_verizon": SkuNameCustomVerizon, + "premium_azurefrontdoor": SkuNamePremiumAzureFrontDoor, + "premium_verizon": SkuNamePremiumVerizon, + "standard_akamai": SkuNameStandardAkamai, + "standard_avgbandwidth_chinacdn": SkuNameStandardAvgBandWidthChinaCdn, + "standard_azurefrontdoor": SkuNameStandardAzureFrontDoor, + "standard_chinacdn": SkuNameStandardChinaCdn, + "standard_microsoft": SkuNameStandardMicrosoft, + "standard_955bandwidth_chinacdn": SkuNameStandardNineFiveFiveBandWidthChinaCdn, + "standardplus_avgbandwidth_chinacdn": SkuNameStandardPlusAvgBandWidthChinaCdn, + "standardplus_chinacdn": SkuNameStandardPlusChinaCdn, + "standardplus_955bandwidth_chinacdn": SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn, + "standard_verizon": SkuNameStandardVerizon, + } + 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 +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/method_managedrulesetslist.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/method_managedrulesetslist.go new file mode 100644 index 00000000000..ed01a1188d7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/method_managedrulesetslist.go @@ -0,0 +1,106 @@ +package webapplicationfirewallmanagedrulesets + +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 ManagedRuleSetsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedRuleSetDefinition +} + +type ManagedRuleSetsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedRuleSetDefinition +} + +type ManagedRuleSetsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ManagedRuleSetsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ManagedRuleSetsList ... +func (c WebApplicationFirewallManagedRuleSetsClient) ManagedRuleSetsList(ctx context.Context, id commonids.SubscriptionId) (result ManagedRuleSetsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ManagedRuleSetsListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/cdnWebApplicationFirewallManagedRuleSets", 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 *[]ManagedRuleSetDefinition `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ManagedRuleSetsListComplete retrieves all the results into a single object +func (c WebApplicationFirewallManagedRuleSetsClient) ManagedRuleSetsListComplete(ctx context.Context, id commonids.SubscriptionId) (ManagedRuleSetsListCompleteResult, error) { + return c.ManagedRuleSetsListCompleteMatchingPredicate(ctx, id, ManagedRuleSetDefinitionOperationPredicate{}) +} + +// ManagedRuleSetsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WebApplicationFirewallManagedRuleSetsClient) ManagedRuleSetsListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ManagedRuleSetDefinitionOperationPredicate) (result ManagedRuleSetsListCompleteResult, err error) { + items := make([]ManagedRuleSetDefinition, 0) + + resp, err := c.ManagedRuleSetsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ManagedRuleSetsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedruledefinition.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedruledefinition.go new file mode 100644 index 00000000000..d0cd3de3858 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedruledefinition.go @@ -0,0 +1,9 @@ +package webapplicationfirewallmanagedrulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleDefinition struct { + Description *string `json:"description,omitempty"` + RuleId *string `json:"ruleId,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulegroupdefinition.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulegroupdefinition.go new file mode 100644 index 00000000000..f2663854eb1 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulegroupdefinition.go @@ -0,0 +1,10 @@ +package webapplicationfirewallmanagedrulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleGroupDefinition struct { + Description *string `json:"description,omitempty"` + RuleGroupName *string `json:"ruleGroupName,omitempty"` + Rules *[]ManagedRuleDefinition `json:"rules,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulesetdefinition.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulesetdefinition.go new file mode 100644 index 00000000000..8771892ca42 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulesetdefinition.go @@ -0,0 +1,17 @@ +package webapplicationfirewallmanagedrulesets + +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 ManagedRuleSetDefinition struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedRuleSetDefinitionProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulesetdefinitionproperties.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulesetdefinitionproperties.go new file mode 100644 index 00000000000..ea8c773005d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_managedrulesetdefinitionproperties.go @@ -0,0 +1,11 @@ +package webapplicationfirewallmanagedrulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleSetDefinitionProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` + RuleGroups *[]ManagedRuleGroupDefinition `json:"ruleGroups,omitempty"` + RuleSetType *string `json:"ruleSetType,omitempty"` + RuleSetVersion *string `json:"ruleSetVersion,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_sku.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_sku.go new file mode 100644 index 00000000000..d7de1d49a26 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/model_sku.go @@ -0,0 +1,8 @@ +package webapplicationfirewallmanagedrulesets + +// 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 { + Name *SkuName `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/predicates.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/predicates.go new file mode 100644 index 00000000000..f600223e4ee --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/predicates.go @@ -0,0 +1,27 @@ +package webapplicationfirewallmanagedrulesets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleSetDefinitionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedRuleSetDefinitionOperationPredicate) Matches(input ManagedRuleSetDefinition) 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/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/version.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/version.go new file mode 100644 index 00000000000..94ea0bf2410 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallmanagedrulesets/version.go @@ -0,0 +1,12 @@ +package webapplicationfirewallmanagedrulesets + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/webapplicationfirewallmanagedrulesets/%s", defaultApiVersion) +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/README.md b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/README.md new file mode 100644 index 00000000000..4f6b940eb37 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/README.md @@ -0,0 +1,104 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies` Documentation + +The `webapplicationfirewallpolicies` SDK allows for interaction with the Azure Resource Manager Service `cdn` (API Version `2024-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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies" +``` + + +### Client Initialization + +```go +client := webapplicationfirewallpolicies.NewWebApplicationFirewallPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WebApplicationFirewallPoliciesClient.PoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := webapplicationfirewallpolicies.NewCdnWebApplicationFirewallPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "cdnWebApplicationFirewallPolicyValue") + +payload := webapplicationfirewallpolicies.CdnWebApplicationFirewallPolicy{ + // ... +} + + +if err := client.PoliciesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebApplicationFirewallPoliciesClient.PoliciesDelete` + +```go +ctx := context.TODO() +id := webapplicationfirewallpolicies.NewCdnWebApplicationFirewallPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "cdnWebApplicationFirewallPolicyValue") + +read, err := client.PoliciesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebApplicationFirewallPoliciesClient.PoliciesGet` + +```go +ctx := context.TODO() +id := webapplicationfirewallpolicies.NewCdnWebApplicationFirewallPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "cdnWebApplicationFirewallPolicyValue") + +read, err := client.PoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebApplicationFirewallPoliciesClient.PoliciesList` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.PoliciesList(ctx, id)` can be used to do batched pagination +items, err := client.PoliciesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebApplicationFirewallPoliciesClient.PoliciesUpdate` + +```go +ctx := context.TODO() +id := webapplicationfirewallpolicies.NewCdnWebApplicationFirewallPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "cdnWebApplicationFirewallPolicyValue") + +payload := webapplicationfirewallpolicies.CdnWebApplicationFirewallPolicyPatchParameters{ + // ... +} + + +if err := client.PoliciesUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/client.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/client.go new file mode 100644 index 00000000000..ac148c53733 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/client.go @@ -0,0 +1,26 @@ +package webapplicationfirewallpolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebApplicationFirewallPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewWebApplicationFirewallPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*WebApplicationFirewallPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "webapplicationfirewallpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WebApplicationFirewallPoliciesClient: %+v", err) + } + + return &WebApplicationFirewallPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/constants.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/constants.go new file mode 100644 index 00000000000..c5acc5a0a4b --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/constants.go @@ -0,0 +1,628 @@ +package webapplicationfirewallpolicies + +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 ActionType string + +const ( + ActionTypeAllow ActionType = "Allow" + ActionTypeBlock ActionType = "Block" + ActionTypeLog ActionType = "Log" + ActionTypeRedirect ActionType = "Redirect" +) + +func PossibleValuesForActionType() []string { + return []string{ + string(ActionTypeAllow), + string(ActionTypeBlock), + string(ActionTypeLog), + string(ActionTypeRedirect), + } +} + +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionType(input string) (*ActionType, error) { + vals := map[string]ActionType{ + "allow": ActionTypeAllow, + "block": ActionTypeBlock, + "log": ActionTypeLog, + "redirect": ActionTypeRedirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionType(input) + return &out, nil +} + +type CustomRuleEnabledState string + +const ( + CustomRuleEnabledStateDisabled CustomRuleEnabledState = "Disabled" + CustomRuleEnabledStateEnabled CustomRuleEnabledState = "Enabled" +) + +func PossibleValuesForCustomRuleEnabledState() []string { + return []string{ + string(CustomRuleEnabledStateDisabled), + string(CustomRuleEnabledStateEnabled), + } +} + +func (s *CustomRuleEnabledState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCustomRuleEnabledState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCustomRuleEnabledState(input string) (*CustomRuleEnabledState, error) { + vals := map[string]CustomRuleEnabledState{ + "disabled": CustomRuleEnabledStateDisabled, + "enabled": CustomRuleEnabledStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CustomRuleEnabledState(input) + return &out, nil +} + +type DefaultCustomBlockResponseStatusCode string + +const ( + DefaultCustomBlockResponseStatusCodeFourTwoNine DefaultCustomBlockResponseStatusCode = "429" + DefaultCustomBlockResponseStatusCodeFourZeroFive DefaultCustomBlockResponseStatusCode = "405" + DefaultCustomBlockResponseStatusCodeFourZeroSix DefaultCustomBlockResponseStatusCode = "406" + DefaultCustomBlockResponseStatusCodeFourZeroThree DefaultCustomBlockResponseStatusCode = "403" + DefaultCustomBlockResponseStatusCodeTwoHundred DefaultCustomBlockResponseStatusCode = "200" +) + +func PossibleValuesForDefaultCustomBlockResponseStatusCode() []string { + return []string{ + string(DefaultCustomBlockResponseStatusCodeFourTwoNine), + string(DefaultCustomBlockResponseStatusCodeFourZeroFive), + string(DefaultCustomBlockResponseStatusCodeFourZeroSix), + string(DefaultCustomBlockResponseStatusCodeFourZeroThree), + string(DefaultCustomBlockResponseStatusCodeTwoHundred), + } +} + +func (s *DefaultCustomBlockResponseStatusCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDefaultCustomBlockResponseStatusCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDefaultCustomBlockResponseStatusCode(input string) (*DefaultCustomBlockResponseStatusCode, error) { + vals := map[string]DefaultCustomBlockResponseStatusCode{ + "429": DefaultCustomBlockResponseStatusCodeFourTwoNine, + "405": DefaultCustomBlockResponseStatusCodeFourZeroFive, + "406": DefaultCustomBlockResponseStatusCodeFourZeroSix, + "403": DefaultCustomBlockResponseStatusCodeFourZeroThree, + "200": DefaultCustomBlockResponseStatusCodeTwoHundred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DefaultCustomBlockResponseStatusCode(input) + return &out, nil +} + +type ManagedRuleEnabledState string + +const ( + ManagedRuleEnabledStateDisabled ManagedRuleEnabledState = "Disabled" + ManagedRuleEnabledStateEnabled ManagedRuleEnabledState = "Enabled" +) + +func PossibleValuesForManagedRuleEnabledState() []string { + return []string{ + string(ManagedRuleEnabledStateDisabled), + string(ManagedRuleEnabledStateEnabled), + } +} + +func (s *ManagedRuleEnabledState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedRuleEnabledState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedRuleEnabledState(input string) (*ManagedRuleEnabledState, error) { + vals := map[string]ManagedRuleEnabledState{ + "disabled": ManagedRuleEnabledStateDisabled, + "enabled": ManagedRuleEnabledStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedRuleEnabledState(input) + return &out, nil +} + +type Operator string + +const ( + OperatorAny Operator = "Any" + OperatorBeginsWith Operator = "BeginsWith" + OperatorContains Operator = "Contains" + OperatorEndsWith Operator = "EndsWith" + OperatorEqual Operator = "Equal" + OperatorGeoMatch Operator = "GeoMatch" + OperatorGreaterThan Operator = "GreaterThan" + OperatorGreaterThanOrEqual Operator = "GreaterThanOrEqual" + OperatorIPMatch Operator = "IPMatch" + OperatorLessThan Operator = "LessThan" + OperatorLessThanOrEqual Operator = "LessThanOrEqual" + OperatorRegEx Operator = "RegEx" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorAny), + string(OperatorBeginsWith), + string(OperatorContains), + string(OperatorEndsWith), + string(OperatorEqual), + string(OperatorGeoMatch), + string(OperatorGreaterThan), + string(OperatorGreaterThanOrEqual), + string(OperatorIPMatch), + string(OperatorLessThan), + string(OperatorLessThanOrEqual), + string(OperatorRegEx), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "any": OperatorAny, + "beginswith": OperatorBeginsWith, + "contains": OperatorContains, + "endswith": OperatorEndsWith, + "equal": OperatorEqual, + "geomatch": OperatorGeoMatch, + "greaterthan": OperatorGreaterThan, + "greaterthanorequal": OperatorGreaterThanOrEqual, + "ipmatch": OperatorIPMatch, + "lessthan": OperatorLessThan, + "lessthanorequal": OperatorLessThanOrEqual, + "regex": OperatorRegEx, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type PolicyEnabledState string + +const ( + PolicyEnabledStateDisabled PolicyEnabledState = "Disabled" + PolicyEnabledStateEnabled PolicyEnabledState = "Enabled" +) + +func PossibleValuesForPolicyEnabledState() []string { + return []string{ + string(PolicyEnabledStateDisabled), + string(PolicyEnabledStateEnabled), + } +} + +func (s *PolicyEnabledState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyEnabledState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyEnabledState(input string) (*PolicyEnabledState, error) { + vals := map[string]PolicyEnabledState{ + "disabled": PolicyEnabledStateDisabled, + "enabled": PolicyEnabledStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyEnabledState(input) + return &out, nil +} + +type PolicyMode string + +const ( + PolicyModeDetection PolicyMode = "Detection" + PolicyModePrevention PolicyMode = "Prevention" +) + +func PossibleValuesForPolicyMode() []string { + return []string{ + string(PolicyModeDetection), + string(PolicyModePrevention), + } +} + +func (s *PolicyMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyMode(input string) (*PolicyMode, error) { + vals := map[string]PolicyMode{ + "detection": PolicyModeDetection, + "prevention": PolicyModePrevention, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyMode(input) + return &out, nil +} + +type PolicyResourceState string + +const ( + PolicyResourceStateCreating PolicyResourceState = "Creating" + PolicyResourceStateDeleting PolicyResourceState = "Deleting" + PolicyResourceStateDisabled PolicyResourceState = "Disabled" + PolicyResourceStateDisabling PolicyResourceState = "Disabling" + PolicyResourceStateEnabled PolicyResourceState = "Enabled" + PolicyResourceStateEnabling PolicyResourceState = "Enabling" +) + +func PossibleValuesForPolicyResourceState() []string { + return []string{ + string(PolicyResourceStateCreating), + string(PolicyResourceStateDeleting), + string(PolicyResourceStateDisabled), + string(PolicyResourceStateDisabling), + string(PolicyResourceStateEnabled), + string(PolicyResourceStateEnabling), + } +} + +func (s *PolicyResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyResourceState(input string) (*PolicyResourceState, error) { + vals := map[string]PolicyResourceState{ + "creating": PolicyResourceStateCreating, + "deleting": PolicyResourceStateDeleting, + "disabled": PolicyResourceStateDisabled, + "disabling": PolicyResourceStateDisabling, + "enabled": PolicyResourceStateEnabled, + "enabling": PolicyResourceStateEnabling, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyResourceState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCreating), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "creating": ProvisioningStateCreating, + "failed": ProvisioningStateFailed, + "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 SkuName string + +const ( + SkuNameCustomVerizon SkuName = "Custom_Verizon" + SkuNamePremiumAzureFrontDoor SkuName = "Premium_AzureFrontDoor" + SkuNamePremiumVerizon SkuName = "Premium_Verizon" + SkuNameStandardAkamai SkuName = "Standard_Akamai" + SkuNameStandardAvgBandWidthChinaCdn SkuName = "Standard_AvgBandWidth_ChinaCdn" + SkuNameStandardAzureFrontDoor SkuName = "Standard_AzureFrontDoor" + SkuNameStandardChinaCdn SkuName = "Standard_ChinaCdn" + SkuNameStandardMicrosoft SkuName = "Standard_Microsoft" + SkuNameStandardNineFiveFiveBandWidthChinaCdn SkuName = "Standard_955BandWidth_ChinaCdn" + SkuNameStandardPlusAvgBandWidthChinaCdn SkuName = "StandardPlus_AvgBandWidth_ChinaCdn" + SkuNameStandardPlusChinaCdn SkuName = "StandardPlus_ChinaCdn" + SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn SkuName = "StandardPlus_955BandWidth_ChinaCdn" + SkuNameStandardVerizon SkuName = "Standard_Verizon" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameCustomVerizon), + string(SkuNamePremiumAzureFrontDoor), + string(SkuNamePremiumVerizon), + string(SkuNameStandardAkamai), + string(SkuNameStandardAvgBandWidthChinaCdn), + string(SkuNameStandardAzureFrontDoor), + string(SkuNameStandardChinaCdn), + string(SkuNameStandardMicrosoft), + string(SkuNameStandardNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardPlusAvgBandWidthChinaCdn), + string(SkuNameStandardPlusChinaCdn), + string(SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardVerizon), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "custom_verizon": SkuNameCustomVerizon, + "premium_azurefrontdoor": SkuNamePremiumAzureFrontDoor, + "premium_verizon": SkuNamePremiumVerizon, + "standard_akamai": SkuNameStandardAkamai, + "standard_avgbandwidth_chinacdn": SkuNameStandardAvgBandWidthChinaCdn, + "standard_azurefrontdoor": SkuNameStandardAzureFrontDoor, + "standard_chinacdn": SkuNameStandardChinaCdn, + "standard_microsoft": SkuNameStandardMicrosoft, + "standard_955bandwidth_chinacdn": SkuNameStandardNineFiveFiveBandWidthChinaCdn, + "standardplus_avgbandwidth_chinacdn": SkuNameStandardPlusAvgBandWidthChinaCdn, + "standardplus_chinacdn": SkuNameStandardPlusChinaCdn, + "standardplus_955bandwidth_chinacdn": SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn, + "standard_verizon": SkuNameStandardVerizon, + } + 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 TransformType string + +const ( + TransformTypeLowercase TransformType = "Lowercase" + TransformTypeRemoveNulls TransformType = "RemoveNulls" + TransformTypeTrim TransformType = "Trim" + TransformTypeUppercase TransformType = "Uppercase" + TransformTypeUrlDecode TransformType = "UrlDecode" + TransformTypeUrlEncode TransformType = "UrlEncode" +) + +func PossibleValuesForTransformType() []string { + return []string{ + string(TransformTypeLowercase), + string(TransformTypeRemoveNulls), + string(TransformTypeTrim), + string(TransformTypeUppercase), + string(TransformTypeUrlDecode), + string(TransformTypeUrlEncode), + } +} + +func (s *TransformType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTransformType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTransformType(input string) (*TransformType, error) { + vals := map[string]TransformType{ + "lowercase": TransformTypeLowercase, + "removenulls": TransformTypeRemoveNulls, + "trim": TransformTypeTrim, + "uppercase": TransformTypeUppercase, + "urldecode": TransformTypeUrlDecode, + "urlencode": TransformTypeUrlEncode, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TransformType(input) + return &out, nil +} + +type WafMatchVariable string + +const ( + WafMatchVariableCookies WafMatchVariable = "Cookies" + WafMatchVariablePostArgs WafMatchVariable = "PostArgs" + WafMatchVariableQueryString WafMatchVariable = "QueryString" + WafMatchVariableRemoteAddr WafMatchVariable = "RemoteAddr" + WafMatchVariableRequestBody WafMatchVariable = "RequestBody" + WafMatchVariableRequestHeader WafMatchVariable = "RequestHeader" + WafMatchVariableRequestMethod WafMatchVariable = "RequestMethod" + WafMatchVariableRequestUri WafMatchVariable = "RequestUri" + WafMatchVariableSocketAddr WafMatchVariable = "SocketAddr" +) + +func PossibleValuesForWafMatchVariable() []string { + return []string{ + string(WafMatchVariableCookies), + string(WafMatchVariablePostArgs), + string(WafMatchVariableQueryString), + string(WafMatchVariableRemoteAddr), + string(WafMatchVariableRequestBody), + string(WafMatchVariableRequestHeader), + string(WafMatchVariableRequestMethod), + string(WafMatchVariableRequestUri), + string(WafMatchVariableSocketAddr), + } +} + +func (s *WafMatchVariable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWafMatchVariable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWafMatchVariable(input string) (*WafMatchVariable, error) { + vals := map[string]WafMatchVariable{ + "cookies": WafMatchVariableCookies, + "postargs": WafMatchVariablePostArgs, + "querystring": WafMatchVariableQueryString, + "remoteaddr": WafMatchVariableRemoteAddr, + "requestbody": WafMatchVariableRequestBody, + "requestheader": WafMatchVariableRequestHeader, + "requestmethod": WafMatchVariableRequestMethod, + "requesturi": WafMatchVariableRequestUri, + "socketaddr": WafMatchVariableSocketAddr, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WafMatchVariable(input) + return &out, nil +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/id_cdnwebapplicationfirewallpolicy.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/id_cdnwebapplicationfirewallpolicy.go new file mode 100644 index 00000000000..969f1c8fda8 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/id_cdnwebapplicationfirewallpolicy.go @@ -0,0 +1,130 @@ +package webapplicationfirewallpolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CdnWebApplicationFirewallPolicyId{}) +} + +var _ resourceids.ResourceId = &CdnWebApplicationFirewallPolicyId{} + +// CdnWebApplicationFirewallPolicyId is a struct representing the Resource ID for a Cdn Web Application Firewall Policy +type CdnWebApplicationFirewallPolicyId struct { + SubscriptionId string + ResourceGroupName string + CdnWebApplicationFirewallPolicyName string +} + +// NewCdnWebApplicationFirewallPolicyID returns a new CdnWebApplicationFirewallPolicyId struct +func NewCdnWebApplicationFirewallPolicyID(subscriptionId string, resourceGroupName string, cdnWebApplicationFirewallPolicyName string) CdnWebApplicationFirewallPolicyId { + return CdnWebApplicationFirewallPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + CdnWebApplicationFirewallPolicyName: cdnWebApplicationFirewallPolicyName, + } +} + +// ParseCdnWebApplicationFirewallPolicyID parses 'input' into a CdnWebApplicationFirewallPolicyId +func ParseCdnWebApplicationFirewallPolicyID(input string) (*CdnWebApplicationFirewallPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&CdnWebApplicationFirewallPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CdnWebApplicationFirewallPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCdnWebApplicationFirewallPolicyIDInsensitively parses 'input' case-insensitively into a CdnWebApplicationFirewallPolicyId +// note: this method should only be used for API response data and not user input +func ParseCdnWebApplicationFirewallPolicyIDInsensitively(input string) (*CdnWebApplicationFirewallPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&CdnWebApplicationFirewallPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CdnWebApplicationFirewallPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CdnWebApplicationFirewallPolicyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.CdnWebApplicationFirewallPolicyName, ok = input.Parsed["cdnWebApplicationFirewallPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "cdnWebApplicationFirewallPolicyName", input) + } + + return nil +} + +// ValidateCdnWebApplicationFirewallPolicyID checks that 'input' can be parsed as a Cdn Web Application Firewall Policy ID +func ValidateCdnWebApplicationFirewallPolicyID(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 := ParseCdnWebApplicationFirewallPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cdn Web Application Firewall Policy ID +func (id CdnWebApplicationFirewallPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.CdnWebApplicationFirewallPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cdn Web Application Firewall Policy ID +func (id CdnWebApplicationFirewallPolicyId) 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("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticCdnWebApplicationFirewallPolicies", "cdnWebApplicationFirewallPolicies", "cdnWebApplicationFirewallPolicies"), + resourceids.UserSpecifiedSegment("cdnWebApplicationFirewallPolicyName", "cdnWebApplicationFirewallPolicyValue"), + } +} + +// String returns a human-readable description of this Cdn Web Application Firewall Policy ID +func (id CdnWebApplicationFirewallPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cdn Web Application Firewall Policy Name: %q", id.CdnWebApplicationFirewallPolicyName), + } + return fmt.Sprintf("Cdn Web Application Firewall Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/id_cdnwebapplicationfirewallpolicy_test.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/id_cdnwebapplicationfirewallpolicy_test.go new file mode 100644 index 00000000000..7c873caf9c9 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/id_cdnwebapplicationfirewallpolicy_test.go @@ -0,0 +1,282 @@ +package webapplicationfirewallpolicies + +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 = &CdnWebApplicationFirewallPolicyId{} + +func TestNewCdnWebApplicationFirewallPolicyID(t *testing.T) { + id := NewCdnWebApplicationFirewallPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "cdnWebApplicationFirewallPolicyValue") + + 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.CdnWebApplicationFirewallPolicyName != "cdnWebApplicationFirewallPolicyValue" { + t.Fatalf("Expected %q but got %q for Segment 'CdnWebApplicationFirewallPolicyName'", id.CdnWebApplicationFirewallPolicyName, "cdnWebApplicationFirewallPolicyValue") + } +} + +func TestFormatCdnWebApplicationFirewallPolicyID(t *testing.T) { + actual := NewCdnWebApplicationFirewallPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "cdnWebApplicationFirewallPolicyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies/cdnWebApplicationFirewallPolicyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCdnWebApplicationFirewallPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CdnWebApplicationFirewallPolicyId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies/cdnWebApplicationFirewallPolicyValue", + Expected: &CdnWebApplicationFirewallPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CdnWebApplicationFirewallPolicyName: "cdnWebApplicationFirewallPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies/cdnWebApplicationFirewallPolicyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCdnWebApplicationFirewallPolicyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.CdnWebApplicationFirewallPolicyName != v.Expected.CdnWebApplicationFirewallPolicyName { + t.Fatalf("Expected %q but got %q for CdnWebApplicationFirewallPolicyName", v.Expected.CdnWebApplicationFirewallPolicyName, actual.CdnWebApplicationFirewallPolicyName) + } + + } +} + +func TestParseCdnWebApplicationFirewallPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CdnWebApplicationFirewallPolicyId + }{ + { + // 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.CDN", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/cDnWeBaPpLiCaTiOnFiReWaLlPoLiCiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies/cdnWebApplicationFirewallPolicyValue", + Expected: &CdnWebApplicationFirewallPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CdnWebApplicationFirewallPolicyName: "cdnWebApplicationFirewallPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies/cdnWebApplicationFirewallPolicyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cDn/cDnWeBaPpLiCaTiOnFiReWaLlPoLiCiEs/cDnWeBaPpLiCaTiOnFiReWaLlPoLiCyVaLuE", + Expected: &CdnWebApplicationFirewallPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + CdnWebApplicationFirewallPolicyName: "cDnWeBaPpLiCaTiOnFiReWaLlPoLiCyVaLuE", + }, + }, + { + // 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.cDn/cDnWeBaPpLiCaTiOnFiReWaLlPoLiCiEs/cDnWeBaPpLiCaTiOnFiReWaLlPoLiCyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCdnWebApplicationFirewallPolicyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.CdnWebApplicationFirewallPolicyName != v.Expected.CdnWebApplicationFirewallPolicyName { + t.Fatalf("Expected %q but got %q for CdnWebApplicationFirewallPolicyName", v.Expected.CdnWebApplicationFirewallPolicyName, actual.CdnWebApplicationFirewallPolicyName) + } + + } +} + +func TestSegmentsForCdnWebApplicationFirewallPolicyId(t *testing.T) { + segments := CdnWebApplicationFirewallPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CdnWebApplicationFirewallPolicyId 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/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiescreateorupdate.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiescreateorupdate.go new file mode 100644 index 00000000000..38ad5015c89 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiescreateorupdate.go @@ -0,0 +1,76 @@ +package webapplicationfirewallpolicies + +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 PoliciesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CdnWebApplicationFirewallPolicy +} + +// PoliciesCreateOrUpdate ... +func (c WebApplicationFirewallPoliciesClient) PoliciesCreateOrUpdate(ctx context.Context, id CdnWebApplicationFirewallPolicyId, input CdnWebApplicationFirewallPolicy) (result PoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PoliciesCreateOrUpdateThenPoll performs PoliciesCreateOrUpdate then polls until it's completed +func (c WebApplicationFirewallPoliciesClient) PoliciesCreateOrUpdateThenPoll(ctx context.Context, id CdnWebApplicationFirewallPolicyId, input CdnWebApplicationFirewallPolicy) error { + result, err := c.PoliciesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PoliciesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PoliciesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesdelete.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesdelete.go new file mode 100644 index 00000000000..6de9740fac2 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesdelete.go @@ -0,0 +1,47 @@ +package webapplicationfirewallpolicies + +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 PoliciesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// PoliciesDelete ... +func (c WebApplicationFirewallPoliciesClient) PoliciesDelete(ctx context.Context, id CdnWebApplicationFirewallPolicyId) (result PoliciesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesget.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesget.go new file mode 100644 index 00000000000..71f949fadf3 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesget.go @@ -0,0 +1,54 @@ +package webapplicationfirewallpolicies + +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 PoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CdnWebApplicationFirewallPolicy +} + +// PoliciesGet ... +func (c WebApplicationFirewallPoliciesClient) PoliciesGet(ctx context.Context, id CdnWebApplicationFirewallPolicyId) (result PoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CdnWebApplicationFirewallPolicy + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policieslist.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policieslist.go new file mode 100644 index 00000000000..308944ddafe --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policieslist.go @@ -0,0 +1,106 @@ +package webapplicationfirewallpolicies + +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 PoliciesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CdnWebApplicationFirewallPolicy +} + +type PoliciesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CdnWebApplicationFirewallPolicy +} + +type PoliciesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *PoliciesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// PoliciesList ... +func (c WebApplicationFirewallPoliciesClient) PoliciesList(ctx context.Context, id commonids.ResourceGroupId) (result PoliciesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &PoliciesListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/cdnWebApplicationFirewallPolicies", 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 *[]CdnWebApplicationFirewallPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PoliciesListComplete retrieves all the results into a single object +func (c WebApplicationFirewallPoliciesClient) PoliciesListComplete(ctx context.Context, id commonids.ResourceGroupId) (PoliciesListCompleteResult, error) { + return c.PoliciesListCompleteMatchingPredicate(ctx, id, CdnWebApplicationFirewallPolicyOperationPredicate{}) +} + +// PoliciesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WebApplicationFirewallPoliciesClient) PoliciesListCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate CdnWebApplicationFirewallPolicyOperationPredicate) (result PoliciesListCompleteResult, err error) { + items := make([]CdnWebApplicationFirewallPolicy, 0) + + resp, err := c.PoliciesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = PoliciesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesupdate.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesupdate.go new file mode 100644 index 00000000000..1eb13e013e7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/method_policiesupdate.go @@ -0,0 +1,75 @@ +package webapplicationfirewallpolicies + +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 PoliciesUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CdnWebApplicationFirewallPolicy +} + +// PoliciesUpdate ... +func (c WebApplicationFirewallPoliciesClient) PoliciesUpdate(ctx context.Context, id CdnWebApplicationFirewallPolicyId, input CdnWebApplicationFirewallPolicyPatchParameters) (result PoliciesUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PoliciesUpdateThenPoll performs PoliciesUpdate then polls until it's completed +func (c WebApplicationFirewallPoliciesClient) PoliciesUpdateThenPoll(ctx context.Context, id CdnWebApplicationFirewallPolicyId, input CdnWebApplicationFirewallPolicyPatchParameters) error { + result, err := c.PoliciesUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PoliciesUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PoliciesUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnendpoint.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnendpoint.go new file mode 100644 index 00000000000..7c542c2a5f7 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnendpoint.go @@ -0,0 +1,8 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CdnEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicy.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicy.go new file mode 100644 index 00000000000..f156b758d77 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicy.go @@ -0,0 +1,20 @@ +package webapplicationfirewallpolicies + +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 CdnWebApplicationFirewallPolicy struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *CdnWebApplicationFirewallPolicyProperties `json:"properties,omitempty"` + Sku Sku `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicypatchparameters.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicypatchparameters.go new file mode 100644 index 00000000000..54afad300f6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicypatchparameters.go @@ -0,0 +1,8 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CdnWebApplicationFirewallPolicyPatchParameters struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicyproperties.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicyproperties.go new file mode 100644 index 00000000000..76344cc38c0 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_cdnwebapplicationfirewallpolicyproperties.go @@ -0,0 +1,15 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CdnWebApplicationFirewallPolicyProperties struct { + CustomRules *CustomRuleList `json:"customRules,omitempty"` + EndpointLinks *[]CdnEndpoint `json:"endpointLinks,omitempty"` + ExtendedProperties *map[string]string `json:"extendedProperties,omitempty"` + ManagedRules *ManagedRuleSetList `json:"managedRules,omitempty"` + PolicySettings *PolicySettings `json:"policySettings,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RateLimitRules *RateLimitRuleList `json:"rateLimitRules,omitempty"` + ResourceState *PolicyResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_customrule.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_customrule.go new file mode 100644 index 00000000000..12ff090b028 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_customrule.go @@ -0,0 +1,12 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomRule struct { + Action ActionType `json:"action"` + EnabledState *CustomRuleEnabledState `json:"enabledState,omitempty"` + MatchConditions []MatchCondition `json:"matchConditions"` + Name string `json:"name"` + Priority int64 `json:"priority"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_customrulelist.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_customrulelist.go new file mode 100644 index 00000000000..4af1175aedf --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_customrulelist.go @@ -0,0 +1,8 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomRuleList struct { + Rules *[]CustomRule `json:"rules,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedrulegroupoverride.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedrulegroupoverride.go new file mode 100644 index 00000000000..2810e8e0e4d --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedrulegroupoverride.go @@ -0,0 +1,9 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleGroupOverride struct { + RuleGroupName string `json:"ruleGroupName"` + Rules *[]ManagedRuleOverride `json:"rules,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedruleoverride.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedruleoverride.go new file mode 100644 index 00000000000..595df8bc503 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedruleoverride.go @@ -0,0 +1,10 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleOverride struct { + Action *ActionType `json:"action,omitempty"` + EnabledState *ManagedRuleEnabledState `json:"enabledState,omitempty"` + RuleId string `json:"ruleId"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedruleset.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedruleset.go new file mode 100644 index 00000000000..b3a1388f11e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedruleset.go @@ -0,0 +1,11 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleSet struct { + AnomalyScore *int64 `json:"anomalyScore,omitempty"` + RuleGroupOverrides *[]ManagedRuleGroupOverride `json:"ruleGroupOverrides,omitempty"` + RuleSetType string `json:"ruleSetType"` + RuleSetVersion string `json:"ruleSetVersion"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedrulesetlist.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedrulesetlist.go new file mode 100644 index 00000000000..f15de67cc0c --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_managedrulesetlist.go @@ -0,0 +1,8 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedRuleSetList struct { + ManagedRuleSets *[]ManagedRuleSet `json:"managedRuleSets,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_matchcondition.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_matchcondition.go new file mode 100644 index 00000000000..52283db218e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_matchcondition.go @@ -0,0 +1,13 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MatchCondition struct { + MatchValue []string `json:"matchValue"` + MatchVariable WafMatchVariable `json:"matchVariable"` + NegateCondition *bool `json:"negateCondition,omitempty"` + Operator Operator `json:"operator"` + Selector *string `json:"selector,omitempty"` + Transforms *[]TransformType `json:"transforms,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_policysettings.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_policysettings.go new file mode 100644 index 00000000000..dc011a63138 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_policysettings.go @@ -0,0 +1,12 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicySettings struct { + DefaultCustomBlockResponseBody *string `json:"defaultCustomBlockResponseBody,omitempty"` + DefaultCustomBlockResponseStatusCode *DefaultCustomBlockResponseStatusCode `json:"defaultCustomBlockResponseStatusCode,omitempty"` + DefaultRedirectUrl *string `json:"defaultRedirectUrl,omitempty"` + EnabledState *PolicyEnabledState `json:"enabledState,omitempty"` + Mode *PolicyMode `json:"mode,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_ratelimitrule.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_ratelimitrule.go new file mode 100644 index 00000000000..591db9da11e --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_ratelimitrule.go @@ -0,0 +1,14 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RateLimitRule struct { + Action ActionType `json:"action"` + EnabledState *CustomRuleEnabledState `json:"enabledState,omitempty"` + MatchConditions []MatchCondition `json:"matchConditions"` + Name string `json:"name"` + Priority int64 `json:"priority"` + RateLimitDurationInMinutes int64 `json:"rateLimitDurationInMinutes"` + RateLimitThreshold int64 `json:"rateLimitThreshold"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_ratelimitrulelist.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_ratelimitrulelist.go new file mode 100644 index 00000000000..b7180c9f619 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_ratelimitrulelist.go @@ -0,0 +1,8 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RateLimitRuleList struct { + Rules *[]RateLimitRule `json:"rules,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_sku.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_sku.go new file mode 100644 index 00000000000..2a73ceadea6 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/model_sku.go @@ -0,0 +1,8 @@ +package webapplicationfirewallpolicies + +// 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 { + Name *SkuName `json:"name,omitempty"` +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/predicates.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/predicates.go new file mode 100644 index 00000000000..efe55879414 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/predicates.go @@ -0,0 +1,37 @@ +package webapplicationfirewallpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CdnWebApplicationFirewallPolicyOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p CdnWebApplicationFirewallPolicyOperationPredicate) Matches(input CdnWebApplicationFirewallPolicy) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/version.go b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/version.go new file mode 100644 index 00000000000..5d963580553 --- /dev/null +++ b/resource-manager/cdn/2024-02-01/webapplicationfirewallpolicies/version.go @@ -0,0 +1,12 @@ +package webapplicationfirewallpolicies + +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 = "2024-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/webapplicationfirewallpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/client.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/client.go new file mode 100644 index 00000000000..0b5752d334c --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/client.go @@ -0,0 +1,64 @@ +package v2024_04_04_preview + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions" + "github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/pools" + "github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails" + "github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/sku" + "github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + ImageVersions *imageversions.ImageVersionsClient + Pools *pools.PoolsClient + ResourceDetails *resourcedetails.ResourceDetailsClient + Sku *sku.SkuClient + SubscriptionUsages *subscriptionusages.SubscriptionUsagesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + imageVersionsClient, err := imageversions.NewImageVersionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ImageVersions client: %+v", err) + } + configureFunc(imageVersionsClient.Client) + + poolsClient, err := pools.NewPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Pools client: %+v", err) + } + configureFunc(poolsClient.Client) + + resourceDetailsClient, err := resourcedetails.NewResourceDetailsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ResourceDetails client: %+v", err) + } + configureFunc(resourceDetailsClient.Client) + + skuClient, err := sku.NewSkuClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Sku client: %+v", err) + } + configureFunc(skuClient.Client) + + subscriptionUsagesClient, err := subscriptionusages.NewSubscriptionUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SubscriptionUsages client: %+v", err) + } + configureFunc(subscriptionUsagesClient.Client) + + return &Client{ + ImageVersions: imageVersionsClient, + Pools: poolsClient, + ResourceDetails: resourceDetailsClient, + Sku: skuClient, + SubscriptionUsages: subscriptionUsagesClient, + }, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/README.md b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/README.md new file mode 100644 index 00000000000..2989d2b97de --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions` Documentation + +The `imageversions` SDK allows for interaction with the Azure Resource Manager Service `devopsinfrastructure` (API Version `2024-04-04-preview`). + +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/devopsinfrastructure/2024-04-04-preview/imageversions" +``` + + +### Client Initialization + +```go +client := imageversions.NewImageVersionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ImageVersionsClient.ListByImage` + +```go +ctx := context.TODO() +id := imageversions.NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "imageValue") + +// alternatively `client.ListByImage(ctx, id)` can be used to do batched pagination +items, err := client.ListByImageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/client.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/client.go new file mode 100644 index 00000000000..e7f72638c73 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/client.go @@ -0,0 +1,26 @@ +package imageversions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageVersionsClient struct { + Client *resourcemanager.Client +} + +func NewImageVersionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ImageVersionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "imageversions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ImageVersionsClient: %+v", err) + } + + return &ImageVersionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/id_image.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/id_image.go new file mode 100644 index 00000000000..a96c553811b --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/id_image.go @@ -0,0 +1,130 @@ +package imageversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ImageId{}) +} + +var _ resourceids.ResourceId = &ImageId{} + +// ImageId is a struct representing the Resource ID for a Image +type ImageId struct { + SubscriptionId string + ResourceGroupName string + ImageName string +} + +// NewImageID returns a new ImageId struct +func NewImageID(subscriptionId string, resourceGroupName string, imageName string) ImageId { + return ImageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ImageName: imageName, + } +} + +// ParseImageID parses 'input' into a ImageId +func ParseImageID(input string) (*ImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseImageIDInsensitively parses 'input' case-insensitively into a ImageId +// note: this method should only be used for API response data and not user input +func ParseImageIDInsensitively(input string) (*ImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ImageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ImageName, ok = input.Parsed["imageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "imageName", input) + } + + return nil +} + +// ValidateImageID checks that 'input' can be parsed as a Image ID +func ValidateImageID(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 := ParseImageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Image ID +func (id ImageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevOpsInfrastructure/images/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ImageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Image ID +func (id ImageId) 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("staticMicrosoftDevOpsInfrastructure", "Microsoft.DevOpsInfrastructure", "Microsoft.DevOpsInfrastructure"), + resourceids.StaticSegment("staticImages", "images", "images"), + resourceids.UserSpecifiedSegment("imageName", "imageValue"), + } +} + +// String returns a human-readable description of this Image ID +func (id ImageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Image Name: %q", id.ImageName), + } + return fmt.Sprintf("Image (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/id_image_test.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/id_image_test.go new file mode 100644 index 00000000000..6c8982bf863 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/id_image_test.go @@ -0,0 +1,282 @@ +package imageversions + +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 = &ImageId{} + +func TestNewImageID(t *testing.T) { + id := NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "imageValue") + + 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.ImageName != "imageValue" { + t.Fatalf("Expected %q but got %q for Segment 'ImageName'", id.ImageName, "imageValue") + } +} + +func TestFormatImageID(t *testing.T) { + actual := NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "imageValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/images/imageValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseImageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImageId + }{ + { + // 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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/images", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/images/imageValue", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ImageName: "imageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/images/imageValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImageID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + } +} + +func TestParseImageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImageId + }{ + { + // 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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/images", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/iMaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/images/imageValue", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ImageName: "imageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/images/imageValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/iMaGeS/iMaGeVaLuE", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ImageName: "iMaGeVaLuE", + }, + }, + { + // 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.dEvOpSiNfRaStRuCtUrE/iMaGeS/iMaGeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImageIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + } +} + +func TestSegmentsForImageId(t *testing.T) { + segments := ImageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ImageId 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/devopsinfrastructure/2024-04-04-preview/imageversions/method_listbyimage.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/method_listbyimage.go new file mode 100644 index 00000000000..34815b734af --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/method_listbyimage.go @@ -0,0 +1,105 @@ +package imageversions + +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 ListByImageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ImageVersion +} + +type ListByImageCompleteResult struct { + LatestHttpResponse *http.Response + Items []ImageVersion +} + +type ListByImageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByImageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByImage ... +func (c ImageVersionsClient) ListByImage(ctx context.Context, id ImageId) (result ListByImageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByImageCustomPager{}, + Path: fmt.Sprintf("%s/versions", 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 *[]ImageVersion `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByImageComplete retrieves all the results into a single object +func (c ImageVersionsClient) ListByImageComplete(ctx context.Context, id ImageId) (ListByImageCompleteResult, error) { + return c.ListByImageCompleteMatchingPredicate(ctx, id, ImageVersionOperationPredicate{}) +} + +// ListByImageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ImageVersionsClient) ListByImageCompleteMatchingPredicate(ctx context.Context, id ImageId, predicate ImageVersionOperationPredicate) (result ListByImageCompleteResult, err error) { + items := make([]ImageVersion, 0) + + resp, err := c.ListByImage(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByImageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/model_imageversion.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/model_imageversion.go new file mode 100644 index 00000000000..9080d66706e --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/model_imageversion.go @@ -0,0 +1,16 @@ +package imageversions + +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 ImageVersion struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ImageVersionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/model_imageversionproperties.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/model_imageversionproperties.go new file mode 100644 index 00000000000..1f97bd37b50 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/model_imageversionproperties.go @@ -0,0 +1,8 @@ +package imageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageVersionProperties struct { + Version string `json:"version"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/predicates.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/predicates.go new file mode 100644 index 00000000000..4744837f5f3 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/predicates.go @@ -0,0 +1,27 @@ +package imageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageVersionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ImageVersionOperationPredicate) Matches(input ImageVersion) 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/devopsinfrastructure/2024-04-04-preview/imageversions/version.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/version.go new file mode 100644 index 00000000000..ae891ccba80 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/imageversions/version.go @@ -0,0 +1,12 @@ +package imageversions + +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 = "2024-04-04-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/imageversions/%s", defaultApiVersion) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/README.md b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/README.md new file mode 100644 index 00000000000..d2548093da5 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/pools` Documentation + +The `pools` SDK allows for interaction with the Azure Resource Manager Service `devopsinfrastructure` (API Version `2024-04-04-preview`). + +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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/pools" +``` + + +### Client Initialization + +```go +client := pools.NewPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue") + +payload := pools.Pool{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PoolsClient.Delete` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PoolsClient.Get` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue") + +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: `PoolsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.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: `PoolsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.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: `PoolsClient.Update` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue") + +payload := pools.PoolUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/client.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/client.go new file mode 100644 index 00000000000..ea65f5527d9 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/client.go @@ -0,0 +1,26 @@ +package pools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolsClient struct { + Client *resourcemanager.Client +} + +func NewPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*PoolsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "pools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PoolsClient: %+v", err) + } + + return &PoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/constants.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/constants.go new file mode 100644 index 00000000000..e311ee19900 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/constants.go @@ -0,0 +1,380 @@ +package pools + +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 AzureDevOpsPermissionType string + +const ( + AzureDevOpsPermissionTypeCreatorOnly AzureDevOpsPermissionType = "CreatorOnly" + AzureDevOpsPermissionTypeInherit AzureDevOpsPermissionType = "Inherit" + AzureDevOpsPermissionTypeSpecificAccounts AzureDevOpsPermissionType = "SpecificAccounts" +) + +func PossibleValuesForAzureDevOpsPermissionType() []string { + return []string{ + string(AzureDevOpsPermissionTypeCreatorOnly), + string(AzureDevOpsPermissionTypeInherit), + string(AzureDevOpsPermissionTypeSpecificAccounts), + } +} + +func (s *AzureDevOpsPermissionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAzureDevOpsPermissionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAzureDevOpsPermissionType(input string) (*AzureDevOpsPermissionType, error) { + vals := map[string]AzureDevOpsPermissionType{ + "creatoronly": AzureDevOpsPermissionTypeCreatorOnly, + "inherit": AzureDevOpsPermissionTypeInherit, + "specificaccounts": AzureDevOpsPermissionTypeSpecificAccounts, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AzureDevOpsPermissionType(input) + return &out, nil +} + +type CachingType string + +const ( + CachingTypeNone CachingType = "None" + CachingTypeReadOnly CachingType = "ReadOnly" + CachingTypeReadWrite CachingType = "ReadWrite" +) + +func PossibleValuesForCachingType() []string { + return []string{ + string(CachingTypeNone), + string(CachingTypeReadOnly), + string(CachingTypeReadWrite), + } +} + +func (s *CachingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCachingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCachingType(input string) (*CachingType, error) { + vals := map[string]CachingType{ + "none": CachingTypeNone, + "readonly": CachingTypeReadOnly, + "readwrite": CachingTypeReadWrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CachingType(input) + return &out, nil +} + +type LogonType string + +const ( + LogonTypeInteractive LogonType = "Interactive" + LogonTypeService LogonType = "Service" +) + +func PossibleValuesForLogonType() []string { + return []string{ + string(LogonTypeInteractive), + string(LogonTypeService), + } +} + +func (s *LogonType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLogonType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLogonType(input string) (*LogonType, error) { + vals := map[string]LogonType{ + "interactive": LogonTypeInteractive, + "service": LogonTypeService, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LogonType(input) + return &out, nil +} + +type OsDiskStorageAccountType string + +const ( + OsDiskStorageAccountTypePremium OsDiskStorageAccountType = "Premium" + OsDiskStorageAccountTypeStandard OsDiskStorageAccountType = "Standard" + OsDiskStorageAccountTypeStandardSSD OsDiskStorageAccountType = "StandardSSD" +) + +func PossibleValuesForOsDiskStorageAccountType() []string { + return []string{ + string(OsDiskStorageAccountTypePremium), + string(OsDiskStorageAccountTypeStandard), + string(OsDiskStorageAccountTypeStandardSSD), + } +} + +func (s *OsDiskStorageAccountType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOsDiskStorageAccountType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOsDiskStorageAccountType(input string) (*OsDiskStorageAccountType, error) { + vals := map[string]OsDiskStorageAccountType{ + "premium": OsDiskStorageAccountTypePremium, + "standard": OsDiskStorageAccountTypeStandard, + "standardssd": OsDiskStorageAccountTypeStandardSSD, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OsDiskStorageAccountType(input) + return &out, nil +} + +type PredictionPreference string + +const ( + PredictionPreferenceBalanced PredictionPreference = "Balanced" + PredictionPreferenceBestPerformance PredictionPreference = "BestPerformance" + PredictionPreferenceMoreCostEffective PredictionPreference = "MoreCostEffective" + PredictionPreferenceMorePerformance PredictionPreference = "MorePerformance" + PredictionPreferenceMostCostEffective PredictionPreference = "MostCostEffective" +) + +func PossibleValuesForPredictionPreference() []string { + return []string{ + string(PredictionPreferenceBalanced), + string(PredictionPreferenceBestPerformance), + string(PredictionPreferenceMoreCostEffective), + string(PredictionPreferenceMorePerformance), + string(PredictionPreferenceMostCostEffective), + } +} + +func (s *PredictionPreference) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePredictionPreference(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePredictionPreference(input string) (*PredictionPreference, error) { + vals := map[string]PredictionPreference{ + "balanced": PredictionPreferenceBalanced, + "bestperformance": PredictionPreferenceBestPerformance, + "morecosteffective": PredictionPreferenceMoreCostEffective, + "moreperformance": PredictionPreferenceMorePerformance, + "mostcosteffective": PredictionPreferenceMostCostEffective, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PredictionPreference(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "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 +} + +type ResourcePredictionsProfileType string + +const ( + ResourcePredictionsProfileTypeAutomatic ResourcePredictionsProfileType = "Automatic" + ResourcePredictionsProfileTypeManual ResourcePredictionsProfileType = "Manual" +) + +func PossibleValuesForResourcePredictionsProfileType() []string { + return []string{ + string(ResourcePredictionsProfileTypeAutomatic), + string(ResourcePredictionsProfileTypeManual), + } +} + +func (s *ResourcePredictionsProfileType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourcePredictionsProfileType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourcePredictionsProfileType(input string) (*ResourcePredictionsProfileType, error) { + vals := map[string]ResourcePredictionsProfileType{ + "automatic": ResourcePredictionsProfileTypeAutomatic, + "manual": ResourcePredictionsProfileTypeManual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourcePredictionsProfileType(input) + return &out, nil +} + +type StorageAccountType string + +const ( + StorageAccountTypePremiumLRS StorageAccountType = "Premium_LRS" + StorageAccountTypePremiumZRS StorageAccountType = "Premium_ZRS" + StorageAccountTypeStandardLRS StorageAccountType = "Standard_LRS" + StorageAccountTypeStandardSSDLRS StorageAccountType = "StandardSSD_LRS" + StorageAccountTypeStandardSSDZRS StorageAccountType = "StandardSSD_ZRS" +) + +func PossibleValuesForStorageAccountType() []string { + return []string{ + string(StorageAccountTypePremiumLRS), + string(StorageAccountTypePremiumZRS), + string(StorageAccountTypeStandardLRS), + string(StorageAccountTypeStandardSSDLRS), + string(StorageAccountTypeStandardSSDZRS), + } +} + +func (s *StorageAccountType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageAccountType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageAccountType(input string) (*StorageAccountType, error) { + vals := map[string]StorageAccountType{ + "premium_lrs": StorageAccountTypePremiumLRS, + "premium_zrs": StorageAccountTypePremiumZRS, + "standard_lrs": StorageAccountTypeStandardLRS, + "standardssd_lrs": StorageAccountTypeStandardSSDLRS, + "standardssd_zrs": StorageAccountTypeStandardSSDZRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageAccountType(input) + return &out, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/id_pool.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/id_pool.go new file mode 100644 index 00000000000..79fe1d90ace --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/id_pool.go @@ -0,0 +1,130 @@ +package pools + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PoolId{}) +} + +var _ resourceids.ResourceId = &PoolId{} + +// PoolId is a struct representing the Resource ID for a Pool +type PoolId struct { + SubscriptionId string + ResourceGroupName string + PoolName string +} + +// NewPoolID returns a new PoolId struct +func NewPoolID(subscriptionId string, resourceGroupName string, poolName string) PoolId { + return PoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PoolName: poolName, + } +} + +// ParsePoolID parses 'input' into a PoolId +func ParsePoolID(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePoolIDInsensitively parses 'input' case-insensitively into a PoolId +// note: this method should only be used for API response data and not user input +func ParsePoolIDInsensitively(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PoolName, ok = input.Parsed["poolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "poolName", input) + } + + return nil +} + +// ValidatePoolID checks that 'input' can be parsed as a Pool ID +func ValidatePoolID(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 := ParsePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Pool ID +func (id PoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevOpsInfrastructure/pools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Pool ID +func (id PoolId) 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("staticMicrosoftDevOpsInfrastructure", "Microsoft.DevOpsInfrastructure", "Microsoft.DevOpsInfrastructure"), + resourceids.StaticSegment("staticPools", "pools", "pools"), + resourceids.UserSpecifiedSegment("poolName", "poolValue"), + } +} + +// String returns a human-readable description of this Pool ID +func (id PoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Pool Name: %q", id.PoolName), + } + return fmt.Sprintf("Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/id_pool_test.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/id_pool_test.go new file mode 100644 index 00000000000..5451da8b724 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/id_pool_test.go @@ -0,0 +1,282 @@ +package pools + +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 = &PoolId{} + +func TestNewPoolID(t *testing.T) { + id := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue") + + 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.PoolName != "poolValue" { + t.Fatalf("Expected %q but got %q for Segment 'PoolName'", id.PoolName, "poolValue") + } +} + +func TestFormatPoolID(t *testing.T) { + actual := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestParsePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/pOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/pOoLs/pOoLvAlUe", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PoolName: "pOoLvAlUe", + }, + }, + { + // 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.dEvOpSiNfRaStRuCtUrE/pOoLs/pOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestSegmentsForPoolId(t *testing.T) { + segments := PoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PoolId 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/devopsinfrastructure/2024-04-04-preview/pools/method_createorupdate.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_createorupdate.go new file mode 100644 index 00000000000..6017e9f5eab --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_createorupdate.go @@ -0,0 +1,75 @@ +package pools + +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 + Model *Pool +} + +// CreateOrUpdate ... +func (c PoolsClient) CreateOrUpdate(ctx context.Context, id PoolId, input Pool) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id PoolId, input Pool) 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/devopsinfrastructure/2024-04-04-preview/pools/method_delete.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_delete.go new file mode 100644 index 00000000000..deed72618de --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_delete.go @@ -0,0 +1,70 @@ +package pools + +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 PoolsClient) Delete(ctx context.Context, id PoolId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + 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 PoolsClient) DeleteThenPoll(ctx context.Context, id PoolId) 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/devopsinfrastructure/2024-04-04-preview/pools/method_get.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_get.go new file mode 100644 index 00000000000..f74c4fdbca9 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_get.go @@ -0,0 +1,54 @@ +package pools + +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 *Pool +} + +// Get ... +func (c PoolsClient) Get(ctx context.Context, id PoolId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Pool + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_listbyresourcegroup.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_listbyresourcegroup.go new file mode 100644 index 00000000000..3f040edc555 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package pools + +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 *[]Pool +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Pool +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c PoolsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DevOpsInfrastructure/pools", 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 *[]Pool `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c PoolsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, PoolOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PoolsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate PoolOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Pool, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_listbysubscription.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_listbysubscription.go new file mode 100644 index 00000000000..131eac5670e --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_listbysubscription.go @@ -0,0 +1,106 @@ +package pools + +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 *[]Pool +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Pool +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c PoolsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DevOpsInfrastructure/pools", 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 *[]Pool `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c PoolsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, PoolOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PoolsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate PoolOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Pool, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_update.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_update.go new file mode 100644 index 00000000000..3bec7d745bc --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/method_update.go @@ -0,0 +1,75 @@ +package pools + +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 + Model *Pool +} + +// Update ... +func (c PoolsClient) Update(ctx context.Context, id PoolId, input PoolUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c PoolsClient) UpdateThenPoll(ctx context.Context, id PoolId, input PoolUpdate) 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/devopsinfrastructure/2024-04-04-preview/pools/model_agentprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_agentprofile.go new file mode 100644 index 00000000000..0f69b46da32 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_agentprofile.go @@ -0,0 +1,61 @@ +package pools + +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 AgentProfile interface { +} + +// RawAgentProfileImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAgentProfileImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAgentProfileImplementation(input []byte) (AgentProfile, 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 AgentProfile into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Stateful") { + var out Stateful + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into Stateful: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Stateless") { + var out StatelessAgentProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StatelessAgentProfile: %+v", err) + } + return out, nil + } + + out := RawAgentProfileImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_automaticresourcepredictionsprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_automaticresourcepredictionsprofile.go new file mode 100644 index 00000000000..afee0e985bb --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_automaticresourcepredictionsprofile.go @@ -0,0 +1,41 @@ +package pools + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ResourcePredictionsProfile = AutomaticResourcePredictionsProfile{} + +type AutomaticResourcePredictionsProfile struct { + PredictionPreference *PredictionPreference `json:"predictionPreference,omitempty"` + + // Fields inherited from ResourcePredictionsProfile +} + +var _ json.Marshaler = AutomaticResourcePredictionsProfile{} + +func (s AutomaticResourcePredictionsProfile) MarshalJSON() ([]byte, error) { + type wrapper AutomaticResourcePredictionsProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AutomaticResourcePredictionsProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AutomaticResourcePredictionsProfile: %+v", err) + } + decoded["kind"] = "Automatic" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AutomaticResourcePredictionsProfile: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_azuredevopsorganizationprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_azuredevopsorganizationprofile.go new file mode 100644 index 00000000000..fef7c909b89 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_azuredevopsorganizationprofile.go @@ -0,0 +1,42 @@ +package pools + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ OrganizationProfile = AzureDevOpsOrganizationProfile{} + +type AzureDevOpsOrganizationProfile struct { + Organizations []Organization `json:"organizations"` + PermissionProfile *AzureDevOpsPermissionProfile `json:"permissionProfile,omitempty"` + + // Fields inherited from OrganizationProfile +} + +var _ json.Marshaler = AzureDevOpsOrganizationProfile{} + +func (s AzureDevOpsOrganizationProfile) MarshalJSON() ([]byte, error) { + type wrapper AzureDevOpsOrganizationProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureDevOpsOrganizationProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureDevOpsOrganizationProfile: %+v", err) + } + decoded["kind"] = "AzureDevOps" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureDevOpsOrganizationProfile: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_azuredevopspermissionprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_azuredevopspermissionprofile.go new file mode 100644 index 00000000000..8f6cb8a42d8 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_azuredevopspermissionprofile.go @@ -0,0 +1,10 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsPermissionProfile struct { + Groups *[]string `json:"groups,omitempty"` + Kind AzureDevOpsPermissionType `json:"kind"` + Users *[]string `json:"users,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_datadisk.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_datadisk.go new file mode 100644 index 00000000000..d7e570a9c31 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_datadisk.go @@ -0,0 +1,11 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataDisk struct { + Caching *CachingType `json:"caching,omitempty"` + DiskSizeGiB *int64 `json:"diskSizeGiB,omitempty"` + DriveLetter *string `json:"driveLetter,omitempty"` + StorageAccountType *StorageAccountType `json:"storageAccountType,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_devopsazuresku.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_devopsazuresku.go new file mode 100644 index 00000000000..0fff7500dd0 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_devopsazuresku.go @@ -0,0 +1,8 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevOpsAzureSku struct { + Name string `json:"name"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_fabricprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_fabricprofile.go new file mode 100644 index 00000000000..c7fba82cc7a --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_fabricprofile.go @@ -0,0 +1,53 @@ +package pools + +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 FabricProfile interface { +} + +// RawFabricProfileImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawFabricProfileImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalFabricProfileImplementation(input []byte) (FabricProfile, 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 FabricProfile into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Vmss") { + var out VMSSFabricProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into VMSSFabricProfile: %+v", err) + } + return out, nil + } + + out := RawFabricProfileImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_githuborganization.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_githuborganization.go new file mode 100644 index 00000000000..ebeb8c98da5 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_githuborganization.go @@ -0,0 +1,9 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHubOrganization struct { + Repositories *[]string `json:"repositories,omitempty"` + Url string `json:"url"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_githuborganizationprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_githuborganizationprofile.go new file mode 100644 index 00000000000..cd2aefb6342 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_githuborganizationprofile.go @@ -0,0 +1,41 @@ +package pools + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ OrganizationProfile = GitHubOrganizationProfile{} + +type GitHubOrganizationProfile struct { + Organizations []GitHubOrganization `json:"organizations"` + + // Fields inherited from OrganizationProfile +} + +var _ json.Marshaler = GitHubOrganizationProfile{} + +func (s GitHubOrganizationProfile) MarshalJSON() ([]byte, error) { + type wrapper GitHubOrganizationProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling GitHubOrganizationProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling GitHubOrganizationProfile: %+v", err) + } + decoded["kind"] = "GitHub" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling GitHubOrganizationProfile: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_manualresourcepredictionsprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_manualresourcepredictionsprofile.go new file mode 100644 index 00000000000..2b72c7e64aa --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_manualresourcepredictionsprofile.go @@ -0,0 +1,40 @@ +package pools + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ResourcePredictionsProfile = ManualResourcePredictionsProfile{} + +type ManualResourcePredictionsProfile struct { + + // Fields inherited from ResourcePredictionsProfile +} + +var _ json.Marshaler = ManualResourcePredictionsProfile{} + +func (s ManualResourcePredictionsProfile) MarshalJSON() ([]byte, error) { + type wrapper ManualResourcePredictionsProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ManualResourcePredictionsProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ManualResourcePredictionsProfile: %+v", err) + } + decoded["kind"] = "Manual" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ManualResourcePredictionsProfile: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_networkprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_networkprofile.go new file mode 100644 index 00000000000..8ecd0977e60 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_networkprofile.go @@ -0,0 +1,8 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkProfile struct { + SubnetId string `json:"subnetId"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_organization.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_organization.go new file mode 100644 index 00000000000..9f2517e48f7 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_organization.go @@ -0,0 +1,10 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Organization struct { + Parallelism *int64 `json:"parallelism,omitempty"` + Projects *[]string `json:"projects,omitempty"` + Url string `json:"url"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_organizationprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_organizationprofile.go new file mode 100644 index 00000000000..57c54a0ec16 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_organizationprofile.go @@ -0,0 +1,61 @@ +package pools + +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 OrganizationProfile interface { +} + +// RawOrganizationProfileImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawOrganizationProfileImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalOrganizationProfileImplementation(input []byte) (OrganizationProfile, 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 OrganizationProfile into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureDevOps") { + var out AzureDevOpsOrganizationProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureDevOpsOrganizationProfile: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "GitHub") { + var out GitHubOrganizationProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into GitHubOrganizationProfile: %+v", err) + } + return out, nil + } + + out := RawOrganizationProfileImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_osprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_osprofile.go new file mode 100644 index 00000000000..6e9f8503ad0 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_osprofile.go @@ -0,0 +1,9 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OsProfile struct { + LogonType *LogonType `json:"logonType,omitempty"` + SecretsManagementSettings *SecretsManagementSettings `json:"secretsManagementSettings,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_pool.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_pool.go new file mode 100644 index 00000000000..bc8e20ffc98 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_pool.go @@ -0,0 +1,20 @@ +package pools + +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 Pool struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *PoolProperties `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/devopsinfrastructure/2024-04-04-preview/pools/model_poolimage.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolimage.go new file mode 100644 index 00000000000..3a80c669b43 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolimage.go @@ -0,0 +1,11 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolImage struct { + Aliases *[]string `json:"aliases,omitempty"` + Buffer *string `json:"buffer,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + WellKnownImageName *string `json:"wellKnownImageName,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolproperties.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolproperties.go new file mode 100644 index 00000000000..1fedb6da0d1 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolproperties.go @@ -0,0 +1,62 @@ +package pools + +import ( + "encoding/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 PoolProperties struct { + AgentProfile AgentProfile `json:"agentProfile"` + DevCenterProjectResourceId string `json:"devCenterProjectResourceId"` + FabricProfile FabricProfile `json:"fabricProfile"` + MaximumConcurrency int64 `json:"maximumConcurrency"` + OrganizationProfile OrganizationProfile `json:"organizationProfile"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} + +var _ json.Unmarshaler = &PoolProperties{} + +func (s *PoolProperties) UnmarshalJSON(bytes []byte) error { + type alias PoolProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into PoolProperties: %+v", err) + } + + s.DevCenterProjectResourceId = decoded.DevCenterProjectResourceId + s.MaximumConcurrency = decoded.MaximumConcurrency + s.ProvisioningState = decoded.ProvisioningState + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PoolProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["agentProfile"]; ok { + impl, err := unmarshalAgentProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'AgentProfile' for 'PoolProperties': %+v", err) + } + s.AgentProfile = impl + } + + if v, ok := temp["fabricProfile"]; ok { + impl, err := unmarshalFabricProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'FabricProfile' for 'PoolProperties': %+v", err) + } + s.FabricProfile = impl + } + + if v, ok := temp["organizationProfile"]; ok { + impl, err := unmarshalOrganizationProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'OrganizationProfile' for 'PoolProperties': %+v", err) + } + s.OrganizationProfile = impl + } + return nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolupdate.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolupdate.go new file mode 100644 index 00000000000..596e730feb1 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolupdate.go @@ -0,0 +1,14 @@ +package pools + +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 PoolUpdate struct { + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *PoolUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolupdateproperties.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolupdateproperties.go new file mode 100644 index 00000000000..1e066025a55 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_poolupdateproperties.go @@ -0,0 +1,62 @@ +package pools + +import ( + "encoding/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 PoolUpdateProperties struct { + AgentProfile AgentProfile `json:"agentProfile"` + DevCenterProjectResourceId *string `json:"devCenterProjectResourceId,omitempty"` + FabricProfile FabricProfile `json:"fabricProfile"` + MaximumConcurrency *int64 `json:"maximumConcurrency,omitempty"` + OrganizationProfile OrganizationProfile `json:"organizationProfile"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} + +var _ json.Unmarshaler = &PoolUpdateProperties{} + +func (s *PoolUpdateProperties) UnmarshalJSON(bytes []byte) error { + type alias PoolUpdateProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into PoolUpdateProperties: %+v", err) + } + + s.DevCenterProjectResourceId = decoded.DevCenterProjectResourceId + s.MaximumConcurrency = decoded.MaximumConcurrency + s.ProvisioningState = decoded.ProvisioningState + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PoolUpdateProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["agentProfile"]; ok { + impl, err := unmarshalAgentProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'AgentProfile' for 'PoolUpdateProperties': %+v", err) + } + s.AgentProfile = impl + } + + if v, ok := temp["fabricProfile"]; ok { + impl, err := unmarshalFabricProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'FabricProfile' for 'PoolUpdateProperties': %+v", err) + } + s.FabricProfile = impl + } + + if v, ok := temp["organizationProfile"]; ok { + impl, err := unmarshalOrganizationProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'OrganizationProfile' for 'PoolUpdateProperties': %+v", err) + } + s.OrganizationProfile = impl + } + return nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_resourcepredictionsprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_resourcepredictionsprofile.go new file mode 100644 index 00000000000..4eaf318b281 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_resourcepredictionsprofile.go @@ -0,0 +1,61 @@ +package pools + +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 ResourcePredictionsProfile interface { +} + +// RawResourcePredictionsProfileImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawResourcePredictionsProfileImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalResourcePredictionsProfileImplementation(input []byte) (ResourcePredictionsProfile, 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 ResourcePredictionsProfile into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Automatic") { + var out AutomaticResourcePredictionsProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AutomaticResourcePredictionsProfile: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Manual") { + var out ManualResourcePredictionsProfile + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ManualResourcePredictionsProfile: %+v", err) + } + return out, nil + } + + out := RawResourcePredictionsProfileImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_secretsmanagementsettings.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_secretsmanagementsettings.go new file mode 100644 index 00000000000..27d0fef3d0f --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_secretsmanagementsettings.go @@ -0,0 +1,10 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretsManagementSettings struct { + CertificateStoreLocation *string `json:"certificateStoreLocation,omitempty"` + KeyExportable bool `json:"keyExportable"` + ObservedCertificates []string `json:"observedCertificates"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_stateful.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_stateful.go new file mode 100644 index 00000000000..bb89cb9cf63 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_stateful.go @@ -0,0 +1,72 @@ +package pools + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AgentProfile = Stateful{} + +type Stateful struct { + GracePeriodTimeSpan *string `json:"gracePeriodTimeSpan,omitempty"` + MaxAgentLifetime *string `json:"maxAgentLifetime,omitempty"` + + // Fields inherited from AgentProfile + ResourcePredictions *interface{} `json:"resourcePredictions,omitempty"` + ResourcePredictionsProfile ResourcePredictionsProfile `json:"resourcePredictionsProfile"` +} + +var _ json.Marshaler = Stateful{} + +func (s Stateful) MarshalJSON() ([]byte, error) { + type wrapper Stateful + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling Stateful: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling Stateful: %+v", err) + } + decoded["kind"] = "Stateful" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling Stateful: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &Stateful{} + +func (s *Stateful) UnmarshalJSON(bytes []byte) error { + type alias Stateful + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into Stateful: %+v", err) + } + + s.GracePeriodTimeSpan = decoded.GracePeriodTimeSpan + s.MaxAgentLifetime = decoded.MaxAgentLifetime + s.ResourcePredictions = decoded.ResourcePredictions + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling Stateful into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourcePredictionsProfile"]; ok { + impl, err := unmarshalResourcePredictionsProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourcePredictionsProfile' for 'Stateful': %+v", err) + } + s.ResourcePredictionsProfile = impl + } + return nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_statelessagentprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_statelessagentprofile.go new file mode 100644 index 00000000000..7a94f2bb4a5 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_statelessagentprofile.go @@ -0,0 +1,68 @@ +package pools + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AgentProfile = StatelessAgentProfile{} + +type StatelessAgentProfile struct { + + // Fields inherited from AgentProfile + ResourcePredictions *interface{} `json:"resourcePredictions,omitempty"` + ResourcePredictionsProfile ResourcePredictionsProfile `json:"resourcePredictionsProfile"` +} + +var _ json.Marshaler = StatelessAgentProfile{} + +func (s StatelessAgentProfile) MarshalJSON() ([]byte, error) { + type wrapper StatelessAgentProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StatelessAgentProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StatelessAgentProfile: %+v", err) + } + decoded["kind"] = "Stateless" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StatelessAgentProfile: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &StatelessAgentProfile{} + +func (s *StatelessAgentProfile) UnmarshalJSON(bytes []byte) error { + type alias StatelessAgentProfile + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into StatelessAgentProfile: %+v", err) + } + + s.ResourcePredictions = decoded.ResourcePredictions + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling StatelessAgentProfile into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourcePredictionsProfile"]; ok { + impl, err := unmarshalResourcePredictionsProfileImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourcePredictionsProfile' for 'StatelessAgentProfile': %+v", err) + } + s.ResourcePredictionsProfile = impl + } + return nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_storageprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_storageprofile.go new file mode 100644 index 00000000000..327c32aec0f --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_storageprofile.go @@ -0,0 +1,9 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageProfile struct { + DataDisks *[]DataDisk `json:"dataDisks,omitempty"` + OsDiskStorageAccountType *OsDiskStorageAccountType `json:"osDiskStorageAccountType,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_vmssfabricprofile.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_vmssfabricprofile.go new file mode 100644 index 00000000000..948cbd6d1a1 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/model_vmssfabricprofile.go @@ -0,0 +1,45 @@ +package pools + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ FabricProfile = VMSSFabricProfile{} + +type VMSSFabricProfile struct { + Images []PoolImage `json:"images"` + NetworkProfile *NetworkProfile `json:"networkProfile,omitempty"` + OsProfile *OsProfile `json:"osProfile,omitempty"` + Sku DevOpsAzureSku `json:"sku"` + StorageProfile *StorageProfile `json:"storageProfile,omitempty"` + + // Fields inherited from FabricProfile +} + +var _ json.Marshaler = VMSSFabricProfile{} + +func (s VMSSFabricProfile) MarshalJSON() ([]byte, error) { + type wrapper VMSSFabricProfile + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling VMSSFabricProfile: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling VMSSFabricProfile: %+v", err) + } + decoded["kind"] = "Vmss" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling VMSSFabricProfile: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/predicates.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/predicates.go new file mode 100644 index 00000000000..3db83e0643e --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/predicates.go @@ -0,0 +1,32 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PoolOperationPredicate) Matches(input Pool) 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/devopsinfrastructure/2024-04-04-preview/pools/version.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/version.go new file mode 100644 index 00000000000..44cbf091cbe --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/pools/version.go @@ -0,0 +1,12 @@ +package pools + +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 = "2024-04-04-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/pools/%s", defaultApiVersion) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/README.md b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/README.md new file mode 100644 index 00000000000..d47da38756a --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails` Documentation + +The `resourcedetails` SDK allows for interaction with the Azure Resource Manager Service `devopsinfrastructure` (API Version `2024-04-04-preview`). + +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/devopsinfrastructure/2024-04-04-preview/resourcedetails" +``` + + +### Client Initialization + +```go +client := resourcedetails.NewResourceDetailsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourceDetailsClient.ListByPool` + +```go +ctx := context.TODO() +id := resourcedetails.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue") + +// alternatively `client.ListByPool(ctx, id)` can be used to do batched pagination +items, err := client.ListByPoolComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/client.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/client.go new file mode 100644 index 00000000000..535a124f8ff --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/client.go @@ -0,0 +1,26 @@ +package resourcedetails + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceDetailsClient struct { + Client *resourcemanager.Client +} + +func NewResourceDetailsClientWithBaseURI(sdkApi sdkEnv.Api) (*ResourceDetailsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "resourcedetails", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ResourceDetailsClient: %+v", err) + } + + return &ResourceDetailsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/constants.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/constants.go new file mode 100644 index 00000000000..e2a8101d4b1 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/constants.go @@ -0,0 +1,78 @@ +package resourcedetails + +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 ResourceStatus string + +const ( + ResourceStatusAllocated ResourceStatus = "Allocated" + ResourceStatusLeased ResourceStatus = "Leased" + ResourceStatusNotReady ResourceStatus = "NotReady" + ResourceStatusPendingReimage ResourceStatus = "PendingReimage" + ResourceStatusPendingReturn ResourceStatus = "PendingReturn" + ResourceStatusProvisioning ResourceStatus = "Provisioning" + ResourceStatusReady ResourceStatus = "Ready" + ResourceStatusReimaging ResourceStatus = "Reimaging" + ResourceStatusReturned ResourceStatus = "Returned" + ResourceStatusStarting ResourceStatus = "Starting" + ResourceStatusUpdating ResourceStatus = "Updating" +) + +func PossibleValuesForResourceStatus() []string { + return []string{ + string(ResourceStatusAllocated), + string(ResourceStatusLeased), + string(ResourceStatusNotReady), + string(ResourceStatusPendingReimage), + string(ResourceStatusPendingReturn), + string(ResourceStatusProvisioning), + string(ResourceStatusReady), + string(ResourceStatusReimaging), + string(ResourceStatusReturned), + string(ResourceStatusStarting), + string(ResourceStatusUpdating), + } +} + +func (s *ResourceStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceStatus(input string) (*ResourceStatus, error) { + vals := map[string]ResourceStatus{ + "allocated": ResourceStatusAllocated, + "leased": ResourceStatusLeased, + "notready": ResourceStatusNotReady, + "pendingreimage": ResourceStatusPendingReimage, + "pendingreturn": ResourceStatusPendingReturn, + "provisioning": ResourceStatusProvisioning, + "ready": ResourceStatusReady, + "reimaging": ResourceStatusReimaging, + "returned": ResourceStatusReturned, + "starting": ResourceStatusStarting, + "updating": ResourceStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceStatus(input) + return &out, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/id_pool.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/id_pool.go new file mode 100644 index 00000000000..f9f7bf396e0 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/id_pool.go @@ -0,0 +1,130 @@ +package resourcedetails + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PoolId{}) +} + +var _ resourceids.ResourceId = &PoolId{} + +// PoolId is a struct representing the Resource ID for a Pool +type PoolId struct { + SubscriptionId string + ResourceGroupName string + PoolName string +} + +// NewPoolID returns a new PoolId struct +func NewPoolID(subscriptionId string, resourceGroupName string, poolName string) PoolId { + return PoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PoolName: poolName, + } +} + +// ParsePoolID parses 'input' into a PoolId +func ParsePoolID(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePoolIDInsensitively parses 'input' case-insensitively into a PoolId +// note: this method should only be used for API response data and not user input +func ParsePoolIDInsensitively(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PoolName, ok = input.Parsed["poolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "poolName", input) + } + + return nil +} + +// ValidatePoolID checks that 'input' can be parsed as a Pool ID +func ValidatePoolID(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 := ParsePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Pool ID +func (id PoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevOpsInfrastructure/pools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Pool ID +func (id PoolId) 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("staticMicrosoftDevOpsInfrastructure", "Microsoft.DevOpsInfrastructure", "Microsoft.DevOpsInfrastructure"), + resourceids.StaticSegment("staticPools", "pools", "pools"), + resourceids.UserSpecifiedSegment("poolName", "poolValue"), + } +} + +// String returns a human-readable description of this Pool ID +func (id PoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Pool Name: %q", id.PoolName), + } + return fmt.Sprintf("Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/id_pool_test.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/id_pool_test.go new file mode 100644 index 00000000000..eca5af1603b --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/id_pool_test.go @@ -0,0 +1,282 @@ +package resourcedetails + +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 = &PoolId{} + +func TestNewPoolID(t *testing.T) { + id := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue") + + 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.PoolName != "poolValue" { + t.Fatalf("Expected %q but got %q for Segment 'PoolName'", id.PoolName, "poolValue") + } +} + +func TestFormatPoolID(t *testing.T) { + actual := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "poolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestParsePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/pOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevOpsInfrastructure/pools/poolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/pOoLs/pOoLvAlUe", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PoolName: "pOoLvAlUe", + }, + }, + { + // 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.dEvOpSiNfRaStRuCtUrE/pOoLs/pOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestSegmentsForPoolId(t *testing.T) { + segments := PoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PoolId 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/devopsinfrastructure/2024-04-04-preview/resourcedetails/method_listbypool.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/method_listbypool.go new file mode 100644 index 00000000000..6330001e75f --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/method_listbypool.go @@ -0,0 +1,105 @@ +package resourcedetails + +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 ListByPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceDetailsObject +} + +type ListByPoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceDetailsObject +} + +type ListByPoolCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByPoolCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByPool ... +func (c ResourceDetailsClient) ListByPool(ctx context.Context, id PoolId) (result ListByPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByPoolCustomPager{}, + Path: fmt.Sprintf("%s/resources", 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 *[]ResourceDetailsObject `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByPoolComplete retrieves all the results into a single object +func (c ResourceDetailsClient) ListByPoolComplete(ctx context.Context, id PoolId) (ListByPoolCompleteResult, error) { + return c.ListByPoolCompleteMatchingPredicate(ctx, id, ResourceDetailsObjectOperationPredicate{}) +} + +// ListByPoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceDetailsClient) ListByPoolCompleteMatchingPredicate(ctx context.Context, id PoolId, predicate ResourceDetailsObjectOperationPredicate) (result ListByPoolCompleteResult, err error) { + items := make([]ResourceDetailsObject, 0) + + resp, err := c.ListByPool(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByPoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/model_resourcedetailsobject.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/model_resourcedetailsobject.go new file mode 100644 index 00000000000..4427ce65ddc --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/model_resourcedetailsobject.go @@ -0,0 +1,16 @@ +package resourcedetails + +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 ResourceDetailsObject struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceDetailsObjectProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/model_resourcedetailsobjectproperties.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/model_resourcedetailsobjectproperties.go new file mode 100644 index 00000000000..2656eb02a73 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/model_resourcedetailsobjectproperties.go @@ -0,0 +1,10 @@ +package resourcedetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceDetailsObjectProperties struct { + Image string `json:"image"` + ImageVersion string `json:"imageVersion"` + Status ResourceStatus `json:"status"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/predicates.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/predicates.go new file mode 100644 index 00000000000..cf92e73a78d --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/predicates.go @@ -0,0 +1,27 @@ +package resourcedetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceDetailsObjectOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceDetailsObjectOperationPredicate) Matches(input ResourceDetailsObject) 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/devopsinfrastructure/2024-04-04-preview/resourcedetails/version.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/version.go new file mode 100644 index 00000000000..d7483497790 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/resourcedetails/version.go @@ -0,0 +1,12 @@ +package resourcedetails + +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 = "2024-04-04-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/resourcedetails/%s", defaultApiVersion) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/README.md b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/README.md new file mode 100644 index 00000000000..4508dae3c3d --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/sku` Documentation + +The `sku` SDK allows for interaction with the Azure Resource Manager Service `devopsinfrastructure` (API Version `2024-04-04-preview`). + +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/devopsinfrastructure/2024-04-04-preview/sku" +``` + + +### Client Initialization + +```go +client := sku.NewSkuClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SkuClient.ListByLocation` + +```go +ctx := context.TODO() +id := sku.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.ListByLocation(ctx, id)` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/client.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/client.go new file mode 100644 index 00000000000..0d80f978801 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/client.go @@ -0,0 +1,26 @@ +package sku + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuClient struct { + Client *resourcemanager.Client +} + +func NewSkuClientWithBaseURI(sdkApi sdkEnv.Api) (*SkuClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sku", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SkuClient: %+v", err) + } + + return &SkuClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/constants.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/constants.go new file mode 100644 index 00000000000..5bc093139f5 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/constants.go @@ -0,0 +1,92 @@ +package sku + +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 ResourceSkuRestrictionsReasonCode string + +const ( + ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription ResourceSkuRestrictionsReasonCode = "NotAvailableForSubscription" + ResourceSkuRestrictionsReasonCodeQuotaId ResourceSkuRestrictionsReasonCode = "QuotaId" +) + +func PossibleValuesForResourceSkuRestrictionsReasonCode() []string { + return []string{ + string(ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription), + string(ResourceSkuRestrictionsReasonCodeQuotaId), + } +} + +func (s *ResourceSkuRestrictionsReasonCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceSkuRestrictionsReasonCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceSkuRestrictionsReasonCode(input string) (*ResourceSkuRestrictionsReasonCode, error) { + vals := map[string]ResourceSkuRestrictionsReasonCode{ + "notavailableforsubscription": ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription, + "quotaid": ResourceSkuRestrictionsReasonCodeQuotaId, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceSkuRestrictionsReasonCode(input) + return &out, nil +} + +type ResourceSkuRestrictionsType string + +const ( + ResourceSkuRestrictionsTypeLocation ResourceSkuRestrictionsType = "Location" + ResourceSkuRestrictionsTypeZone ResourceSkuRestrictionsType = "Zone" +) + +func PossibleValuesForResourceSkuRestrictionsType() []string { + return []string{ + string(ResourceSkuRestrictionsTypeLocation), + string(ResourceSkuRestrictionsTypeZone), + } +} + +func (s *ResourceSkuRestrictionsType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceSkuRestrictionsType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceSkuRestrictionsType(input string) (*ResourceSkuRestrictionsType, error) { + vals := map[string]ResourceSkuRestrictionsType{ + "location": ResourceSkuRestrictionsTypeLocation, + "zone": ResourceSkuRestrictionsTypeZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceSkuRestrictionsType(input) + return &out, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/id_location.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/id_location.go new file mode 100644 index 00000000000..6e7b9afb295 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/id_location.go @@ -0,0 +1,121 @@ +package sku + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.DevOpsInfrastructure/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("staticMicrosoftDevOpsInfrastructure", "Microsoft.DevOpsInfrastructure", "Microsoft.DevOpsInfrastructure"), + 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/devopsinfrastructure/2024-04-04-preview/sku/id_location_test.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/id_location_test.go new file mode 100644 index 00000000000..7e8201d994f --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/id_location_test.go @@ -0,0 +1,237 @@ +package sku + +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.DevOpsInfrastructure/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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/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.DevOpsInfrastructure/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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/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.DevOpsInfrastructure/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/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.dEvOpSiNfRaStRuCtUrE/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/devopsinfrastructure/2024-04-04-preview/sku/method_listbylocation.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/method_listbylocation.go new file mode 100644 index 00000000000..734beee7e1e --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/method_listbylocation.go @@ -0,0 +1,105 @@ +package sku + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceSku +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceSku +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c SkuClient) ListByLocation(ctx context.Context, id LocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByLocationCustomPager{}, + 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.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ResourceSku `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c SkuClient) ListByLocationComplete(ctx context.Context, id LocationId) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, ResourceSkuOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SkuClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate ResourceSkuOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]ResourceSku, 0) + + resp, err := c.ListByLocation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourcesku.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourcesku.go new file mode 100644 index 00000000000..76971520808 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourcesku.go @@ -0,0 +1,16 @@ +package sku + +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 ResourceSku struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceSkuProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskucapabilities.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskucapabilities.go new file mode 100644 index 00000000000..30b04f49dba --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskucapabilities.go @@ -0,0 +1,9 @@ +package sku + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuCapabilities struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskulocationinfo.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskulocationinfo.go new file mode 100644 index 00000000000..dd758ed458c --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskulocationinfo.go @@ -0,0 +1,14 @@ +package sku + +import ( + "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 ResourceSkuLocationInfo struct { + Location string `json:"location"` + ZoneDetails []ResourceSkuZoneDetails `json:"zoneDetails"` + Zones zones.Schema `json:"zones"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskuproperties.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskuproperties.go new file mode 100644 index 00000000000..c53adbca99e --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskuproperties.go @@ -0,0 +1,15 @@ +package sku + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuProperties struct { + Capabilities []ResourceSkuCapabilities `json:"capabilities"` + Family string `json:"family"` + LocationInfo []ResourceSkuLocationInfo `json:"locationInfo"` + Locations []string `json:"locations"` + ResourceType string `json:"resourceType"` + Restrictions []ResourceSkuRestrictions `json:"restrictions"` + Size string `json:"size"` + Tier string `json:"tier"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskurestrictioninfo.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskurestrictioninfo.go new file mode 100644 index 00000000000..de21b17c69a --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskurestrictioninfo.go @@ -0,0 +1,13 @@ +package sku + +import ( + "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 ResourceSkuRestrictionInfo struct { + Locations *[]string `json:"locations,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskurestrictions.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskurestrictions.go new file mode 100644 index 00000000000..0362a669791 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskurestrictions.go @@ -0,0 +1,11 @@ +package sku + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuRestrictions struct { + ReasonCode *ResourceSkuRestrictionsReasonCode `json:"reasonCode,omitempty"` + RestrictionInfo ResourceSkuRestrictionInfo `json:"restrictionInfo"` + Type *ResourceSkuRestrictionsType `json:"type,omitempty"` + Values []string `json:"values"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskuzonedetails.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskuzonedetails.go new file mode 100644 index 00000000000..11e98a5c961 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/model_resourceskuzonedetails.go @@ -0,0 +1,9 @@ +package sku + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuZoneDetails struct { + Capabilities []ResourceSkuCapabilities `json:"capabilities"` + Name []string `json:"name"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/predicates.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/predicates.go new file mode 100644 index 00000000000..a92bcf28a13 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/predicates.go @@ -0,0 +1,27 @@ +package sku + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceSkuOperationPredicate) Matches(input ResourceSku) 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/devopsinfrastructure/2024-04-04-preview/sku/version.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/version.go new file mode 100644 index 00000000000..a6a6404ee60 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/sku/version.go @@ -0,0 +1,12 @@ +package sku + +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 = "2024-04-04-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sku/%s", defaultApiVersion) +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/README.md b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/README.md new file mode 100644 index 00000000000..ce6000fa975 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages` Documentation + +The `subscriptionusages` SDK allows for interaction with the Azure Resource Manager Service `devopsinfrastructure` (API Version `2024-04-04-preview`). + +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/devopsinfrastructure/2024-04-04-preview/subscriptionusages" +``` + + +### Client Initialization + +```go +client := subscriptionusages.NewSubscriptionUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SubscriptionUsagesClient.Usages` + +```go +ctx := context.TODO() +id := subscriptionusages.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.Usages(ctx, id)` can be used to do batched pagination +items, err := client.UsagesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/client.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/client.go new file mode 100644 index 00000000000..6bd351c6169 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/client.go @@ -0,0 +1,26 @@ +package subscriptionusages + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionUsagesClient struct { + Client *resourcemanager.Client +} + +func NewSubscriptionUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionUsagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "subscriptionusages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionUsagesClient: %+v", err) + } + + return &SubscriptionUsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/id_location.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/id_location.go new file mode 100644 index 00000000000..98d2f8e06cc --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/id_location.go @@ -0,0 +1,121 @@ +package subscriptionusages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.DevOpsInfrastructure/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("staticMicrosoftDevOpsInfrastructure", "Microsoft.DevOpsInfrastructure", "Microsoft.DevOpsInfrastructure"), + 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/devopsinfrastructure/2024-04-04-preview/subscriptionusages/id_location_test.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/id_location_test.go new file mode 100644 index 00000000000..55457addc50 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/id_location_test.go @@ -0,0 +1,237 @@ +package subscriptionusages + +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.DevOpsInfrastructure/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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/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.DevOpsInfrastructure/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.DevOpsInfrastructure", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevOpsInfrastructure/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.DevOpsInfrastructure/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvOpSiNfRaStRuCtUrE/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.dEvOpSiNfRaStRuCtUrE/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/devopsinfrastructure/2024-04-04-preview/subscriptionusages/method_usages.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/method_usages.go new file mode 100644 index 00000000000..7e702bf4cc9 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/method_usages.go @@ -0,0 +1,105 @@ +package subscriptionusages + +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 UsagesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Quota +} + +type UsagesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Quota +} + +type UsagesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *UsagesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// Usages ... +func (c SubscriptionUsagesClient) Usages(ctx context.Context, id LocationId) (result UsagesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &UsagesCustomPager{}, + 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 *[]Quota `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// UsagesComplete retrieves all the results into a single object +func (c SubscriptionUsagesClient) UsagesComplete(ctx context.Context, id LocationId) (UsagesCompleteResult, error) { + return c.UsagesCompleteMatchingPredicate(ctx, id, QuotaOperationPredicate{}) +} + +// UsagesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SubscriptionUsagesClient) UsagesCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate QuotaOperationPredicate) (result UsagesCompleteResult, err error) { + items := make([]Quota, 0) + + resp, err := c.Usages(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = UsagesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/model_quota.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/model_quota.go new file mode 100644 index 00000000000..e0574a3af69 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/model_quota.go @@ -0,0 +1,12 @@ +package subscriptionusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Quota struct { + CurrentValue int64 `json:"currentValue"` + Id string `json:"id"` + Limit int64 `json:"limit"` + Name *QuotaName `json:"name,omitempty"` + Unit string `json:"unit"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/model_quotaname.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/model_quotaname.go new file mode 100644 index 00000000000..f19eeab6cdc --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/model_quotaname.go @@ -0,0 +1,9 @@ +package subscriptionusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/predicates.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/predicates.go new file mode 100644 index 00000000000..6f1a4a19081 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/predicates.go @@ -0,0 +1,32 @@ +package subscriptionusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 + Unit *string +} + +func (p QuotaOperationPredicate) Matches(input Quota) bool { + + if p.CurrentValue != nil && *p.CurrentValue != input.CurrentValue { + return false + } + + if p.Id != nil && *p.Id != input.Id { + return false + } + + if p.Limit != nil && *p.Limit != input.Limit { + return false + } + + if p.Unit != nil && *p.Unit != input.Unit { + return false + } + + return true +} diff --git a/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/version.go b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/version.go new file mode 100644 index 00000000000..c94e4292c30 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-04-04-preview/subscriptionusages/version.go @@ -0,0 +1,12 @@ +package subscriptionusages + +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 = "2024-04-04-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/subscriptionusages/%s", defaultApiVersion) +} diff --git a/resource-manager/fabric/2023-11-01/client.go b/resource-manager/fabric/2023-11-01/client.go new file mode 100644 index 00000000000..a8702ce914c --- /dev/null +++ b/resource-manager/fabric/2023-11-01/client.go @@ -0,0 +1,28 @@ +package v2023_11_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/fabric/2023-11-01/fabriccapacities" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + FabricCapacities *fabriccapacities.FabricCapacitiesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + fabricCapacitiesClient, err := fabriccapacities.NewFabricCapacitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FabricCapacities client: %+v", err) + } + configureFunc(fabricCapacitiesClient.Client) + + return &Client{ + FabricCapacities: fabricCapacitiesClient, + }, nil +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/README.md b/resource-manager/fabric/2023-11-01/fabriccapacities/README.md new file mode 100644 index 00000000000..369108116d1 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/README.md @@ -0,0 +1,196 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/fabric/2023-11-01/fabriccapacities` Documentation + +The `fabriccapacities` SDK allows for interaction with the Azure Resource Manager Service `fabric` (API Version `2023-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/fabric/2023-11-01/fabriccapacities" +``` + + +### Client Initialization + +```go +client := fabriccapacities.NewFabricCapacitiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FabricCapacitiesClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := fabriccapacities.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := fabriccapacities.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `FabricCapacitiesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := fabriccapacities.NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + +payload := fabriccapacities.FabricCapacity{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `FabricCapacitiesClient.Delete` + +```go +ctx := context.TODO() +id := fabriccapacities.NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FabricCapacitiesClient.Get` + +```go +ctx := context.TODO() +id := fabriccapacities.NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + +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: `FabricCapacitiesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.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: `FabricCapacitiesClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.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: `FabricCapacitiesClient.ListSkus` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListSkus(ctx, id)` can be used to do batched pagination +items, err := client.ListSkusComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `FabricCapacitiesClient.ListSkusForCapacity` + +```go +ctx := context.TODO() +id := fabriccapacities.NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + +// alternatively `client.ListSkusForCapacity(ctx, id)` can be used to do batched pagination +items, err := client.ListSkusForCapacityComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `FabricCapacitiesClient.Resume` + +```go +ctx := context.TODO() +id := fabriccapacities.NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + +if err := client.ResumeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FabricCapacitiesClient.Suspend` + +```go +ctx := context.TODO() +id := fabriccapacities.NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + +if err := client.SuspendThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FabricCapacitiesClient.Update` + +```go +ctx := context.TODO() +id := fabriccapacities.NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + +payload := fabriccapacities.FabricCapacityUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/client.go b/resource-manager/fabric/2023-11-01/fabriccapacities/client.go new file mode 100644 index 00000000000..e3727d97abd --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/client.go @@ -0,0 +1,26 @@ +package fabriccapacities + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FabricCapacitiesClient struct { + Client *resourcemanager.Client +} + +func NewFabricCapacitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*FabricCapacitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "fabriccapacities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FabricCapacitiesClient: %+v", err) + } + + return &FabricCapacitiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/constants.go b/resource-manager/fabric/2023-11-01/fabriccapacities/constants.go new file mode 100644 index 00000000000..969350a0252 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/constants.go @@ -0,0 +1,213 @@ +package fabriccapacities + +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 CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "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 +} + +type ResourceState string + +const ( + ResourceStateActive ResourceState = "Active" + ResourceStateDeleting ResourceState = "Deleting" + ResourceStateFailed ResourceState = "Failed" + ResourceStatePaused ResourceState = "Paused" + ResourceStatePausing ResourceState = "Pausing" + ResourceStatePreparing ResourceState = "Preparing" + ResourceStateProvisioning ResourceState = "Provisioning" + ResourceStateResuming ResourceState = "Resuming" + ResourceStateScaling ResourceState = "Scaling" + ResourceStateSuspended ResourceState = "Suspended" + ResourceStateSuspending ResourceState = "Suspending" + ResourceStateUpdating ResourceState = "Updating" +) + +func PossibleValuesForResourceState() []string { + return []string{ + string(ResourceStateActive), + string(ResourceStateDeleting), + string(ResourceStateFailed), + string(ResourceStatePaused), + string(ResourceStatePausing), + string(ResourceStatePreparing), + string(ResourceStateProvisioning), + string(ResourceStateResuming), + string(ResourceStateScaling), + string(ResourceStateSuspended), + string(ResourceStateSuspending), + string(ResourceStateUpdating), + } +} + +func (s *ResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceState(input string) (*ResourceState, error) { + vals := map[string]ResourceState{ + "active": ResourceStateActive, + "deleting": ResourceStateDeleting, + "failed": ResourceStateFailed, + "paused": ResourceStatePaused, + "pausing": ResourceStatePausing, + "preparing": ResourceStatePreparing, + "provisioning": ResourceStateProvisioning, + "resuming": ResourceStateResuming, + "scaling": ResourceStateScaling, + "suspended": ResourceStateSuspended, + "suspending": ResourceStateSuspending, + "updating": ResourceStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceState(input) + return &out, nil +} + +type RpSkuTier string + +const ( + RpSkuTierFabric RpSkuTier = "Fabric" +) + +func PossibleValuesForRpSkuTier() []string { + return []string{ + string(RpSkuTierFabric), + } +} + +func (s *RpSkuTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRpSkuTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRpSkuTier(input string) (*RpSkuTier, error) { + vals := map[string]RpSkuTier{ + "fabric": RpSkuTierFabric, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RpSkuTier(input) + return &out, nil +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/id_capacity.go b/resource-manager/fabric/2023-11-01/fabriccapacities/id_capacity.go new file mode 100644 index 00000000000..70eea29dede --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/id_capacity.go @@ -0,0 +1,130 @@ +package fabriccapacities + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CapacityId{}) +} + +var _ resourceids.ResourceId = &CapacityId{} + +// CapacityId is a struct representing the Resource ID for a Capacity +type CapacityId struct { + SubscriptionId string + ResourceGroupName string + CapacityName string +} + +// NewCapacityID returns a new CapacityId struct +func NewCapacityID(subscriptionId string, resourceGroupName string, capacityName string) CapacityId { + return CapacityId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + CapacityName: capacityName, + } +} + +// ParseCapacityID parses 'input' into a CapacityId +func ParseCapacityID(input string) (*CapacityId, error) { + parser := resourceids.NewParserFromResourceIdType(&CapacityId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CapacityId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCapacityIDInsensitively parses 'input' case-insensitively into a CapacityId +// note: this method should only be used for API response data and not user input +func ParseCapacityIDInsensitively(input string) (*CapacityId, error) { + parser := resourceids.NewParserFromResourceIdType(&CapacityId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CapacityId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CapacityId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.CapacityName, ok = input.Parsed["capacityName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "capacityName", input) + } + + return nil +} + +// ValidateCapacityID checks that 'input' can be parsed as a Capacity ID +func ValidateCapacityID(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 := ParseCapacityID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Capacity ID +func (id CapacityId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Fabric/capacities/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.CapacityName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Capacity ID +func (id CapacityId) 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("staticMicrosoftFabric", "Microsoft.Fabric", "Microsoft.Fabric"), + resourceids.StaticSegment("staticCapacities", "capacities", "capacities"), + resourceids.UserSpecifiedSegment("capacityName", "capacityValue"), + } +} + +// String returns a human-readable description of this Capacity ID +func (id CapacityId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Capacity Name: %q", id.CapacityName), + } + return fmt.Sprintf("Capacity (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/id_capacity_test.go b/resource-manager/fabric/2023-11-01/fabriccapacities/id_capacity_test.go new file mode 100644 index 00000000000..73859d9afd8 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/id_capacity_test.go @@ -0,0 +1,282 @@ +package fabriccapacities + +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 = &CapacityId{} + +func TestNewCapacityID(t *testing.T) { + id := NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue") + + 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.CapacityName != "capacityValue" { + t.Fatalf("Expected %q but got %q for Segment 'CapacityName'", id.CapacityName, "capacityValue") + } +} + +func TestFormatCapacityID(t *testing.T) { + actual := NewCapacityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "capacityValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Fabric/capacities/capacityValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCapacityID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CapacityId + }{ + { + // 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.Fabric", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Fabric/capacities", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Fabric/capacities/capacityValue", + Expected: &CapacityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CapacityName: "capacityValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Fabric/capacities/capacityValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCapacityID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.CapacityName != v.Expected.CapacityName { + t.Fatalf("Expected %q but got %q for CapacityName", v.Expected.CapacityName, actual.CapacityName) + } + + } +} + +func TestParseCapacityIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CapacityId + }{ + { + // 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.Fabric", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.fAbRiC", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Fabric/capacities", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.fAbRiC/cApAcItIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Fabric/capacities/capacityValue", + Expected: &CapacityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CapacityName: "capacityValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Fabric/capacities/capacityValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.fAbRiC/cApAcItIeS/cApAcItYvAlUe", + Expected: &CapacityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + CapacityName: "cApAcItYvAlUe", + }, + }, + { + // 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.fAbRiC/cApAcItIeS/cApAcItYvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCapacityIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.CapacityName != v.Expected.CapacityName { + t.Fatalf("Expected %q but got %q for CapacityName", v.Expected.CapacityName, actual.CapacityName) + } + + } +} + +func TestSegmentsForCapacityId(t *testing.T) { + segments := CapacityId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CapacityId 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/fabric/2023-11-01/fabriccapacities/id_location.go b/resource-manager/fabric/2023-11-01/fabriccapacities/id_location.go new file mode 100644 index 00000000000..daa1763de4c --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/id_location.go @@ -0,0 +1,121 @@ +package fabriccapacities + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Fabric/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("staticMicrosoftFabric", "Microsoft.Fabric", "Microsoft.Fabric"), + 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/fabric/2023-11-01/fabriccapacities/id_location_test.go b/resource-manager/fabric/2023-11-01/fabriccapacities/id_location_test.go new file mode 100644 index 00000000000..990920e5a62 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/id_location_test.go @@ -0,0 +1,237 @@ +package fabriccapacities + +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.Fabric/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.Fabric", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Fabric/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Fabric/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.Fabric/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.Fabric", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.fAbRiC", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Fabric/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.fAbRiC/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Fabric/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.Fabric/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.fAbRiC/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.fAbRiC/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/fabric/2023-11-01/fabriccapacities/method_checknameavailability.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_checknameavailability.go new file mode 100644 index 00000000000..29e0f31aedd --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_checknameavailability.go @@ -0,0 +1,59 @@ +package fabriccapacities + +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 *CheckNameAvailabilityResponse +} + +// CheckNameAvailability ... +func (c FabricCapacitiesClient) CheckNameAvailability(ctx context.Context, id LocationId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_createorupdate.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_createorupdate.go new file mode 100644 index 00000000000..c28db3e5b87 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_createorupdate.go @@ -0,0 +1,75 @@ +package fabriccapacities + +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 + Model *FabricCapacity +} + +// CreateOrUpdate ... +func (c FabricCapacitiesClient) CreateOrUpdate(ctx context.Context, id CapacityId, input FabricCapacity) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c FabricCapacitiesClient) CreateOrUpdateThenPoll(ctx context.Context, id CapacityId, input FabricCapacity) 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/fabric/2023-11-01/fabriccapacities/method_delete.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_delete.go new file mode 100644 index 00000000000..e87cfd96906 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_delete.go @@ -0,0 +1,70 @@ +package fabriccapacities + +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 FabricCapacitiesClient) Delete(ctx context.Context, id CapacityId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + 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 FabricCapacitiesClient) DeleteThenPoll(ctx context.Context, id CapacityId) 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/fabric/2023-11-01/fabriccapacities/method_get.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_get.go new file mode 100644 index 00000000000..1ee83df5e66 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_get.go @@ -0,0 +1,54 @@ +package fabriccapacities + +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 *FabricCapacity +} + +// Get ... +func (c FabricCapacitiesClient) Get(ctx context.Context, id CapacityId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model FabricCapacity + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_listbyresourcegroup.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listbyresourcegroup.go new file mode 100644 index 00000000000..3f49ade6b32 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package fabriccapacities + +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 *[]FabricCapacity +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []FabricCapacity +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c FabricCapacitiesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Fabric/capacities", 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 *[]FabricCapacity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c FabricCapacitiesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, FabricCapacityOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FabricCapacitiesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate FabricCapacityOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]FabricCapacity, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_listbysubscription.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listbysubscription.go new file mode 100644 index 00000000000..74c2bbe6cc6 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listbysubscription.go @@ -0,0 +1,106 @@ +package fabriccapacities + +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 *[]FabricCapacity +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []FabricCapacity +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c FabricCapacitiesClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Fabric/capacities", 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 *[]FabricCapacity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c FabricCapacitiesClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, FabricCapacityOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FabricCapacitiesClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate FabricCapacityOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]FabricCapacity, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_listskus.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listskus.go new file mode 100644 index 00000000000..7604d561cb9 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listskus.go @@ -0,0 +1,106 @@ +package fabriccapacities + +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 ListSkusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RpSkuDetailsForNewResource +} + +type ListSkusCompleteResult struct { + LatestHttpResponse *http.Response + Items []RpSkuDetailsForNewResource +} + +type ListSkusCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListSkusCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListSkus ... +func (c FabricCapacitiesClient) ListSkus(ctx context.Context, id commonids.SubscriptionId) (result ListSkusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListSkusCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Fabric/skus", 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 *[]RpSkuDetailsForNewResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListSkusComplete retrieves all the results into a single object +func (c FabricCapacitiesClient) ListSkusComplete(ctx context.Context, id commonids.SubscriptionId) (ListSkusCompleteResult, error) { + return c.ListSkusCompleteMatchingPredicate(ctx, id, RpSkuDetailsForNewResourceOperationPredicate{}) +} + +// ListSkusCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FabricCapacitiesClient) ListSkusCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate RpSkuDetailsForNewResourceOperationPredicate) (result ListSkusCompleteResult, err error) { + items := make([]RpSkuDetailsForNewResource, 0) + + resp, err := c.ListSkus(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListSkusCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_listskusforcapacity.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listskusforcapacity.go new file mode 100644 index 00000000000..a896be4a69a --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_listskusforcapacity.go @@ -0,0 +1,105 @@ +package fabriccapacities + +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 ListSkusForCapacityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RpSkuDetailsForExistingResource +} + +type ListSkusForCapacityCompleteResult struct { + LatestHttpResponse *http.Response + Items []RpSkuDetailsForExistingResource +} + +type ListSkusForCapacityCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListSkusForCapacityCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListSkusForCapacity ... +func (c FabricCapacitiesClient) ListSkusForCapacity(ctx context.Context, id CapacityId) (result ListSkusForCapacityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListSkusForCapacityCustomPager{}, + 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.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RpSkuDetailsForExistingResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListSkusForCapacityComplete retrieves all the results into a single object +func (c FabricCapacitiesClient) ListSkusForCapacityComplete(ctx context.Context, id CapacityId) (ListSkusForCapacityCompleteResult, error) { + return c.ListSkusForCapacityCompleteMatchingPredicate(ctx, id, RpSkuDetailsForExistingResourceOperationPredicate{}) +} + +// ListSkusForCapacityCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FabricCapacitiesClient) ListSkusForCapacityCompleteMatchingPredicate(ctx context.Context, id CapacityId, predicate RpSkuDetailsForExistingResourceOperationPredicate) (result ListSkusForCapacityCompleteResult, err error) { + items := make([]RpSkuDetailsForExistingResource, 0) + + resp, err := c.ListSkusForCapacity(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListSkusForCapacityCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_resume.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_resume.go new file mode 100644 index 00000000000..96a20c6e161 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_resume.go @@ -0,0 +1,70 @@ +package fabriccapacities + +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 ResumeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Resume ... +func (c FabricCapacitiesClient) Resume(ctx context.Context, id CapacityId) (result ResumeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/resume", 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 +} + +// ResumeThenPoll performs Resume then polls until it's completed +func (c FabricCapacitiesClient) ResumeThenPoll(ctx context.Context, id CapacityId) error { + result, err := c.Resume(ctx, id) + if err != nil { + return fmt.Errorf("performing Resume: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Resume: %+v", err) + } + + return nil +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_suspend.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_suspend.go new file mode 100644 index 00000000000..004e29bcb93 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_suspend.go @@ -0,0 +1,70 @@ +package fabriccapacities + +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 SuspendOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Suspend ... +func (c FabricCapacitiesClient) Suspend(ctx context.Context, id CapacityId) (result SuspendOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/suspend", 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 +} + +// SuspendThenPoll performs Suspend then polls until it's completed +func (c FabricCapacitiesClient) SuspendThenPoll(ctx context.Context, id CapacityId) error { + result, err := c.Suspend(ctx, id) + if err != nil { + return fmt.Errorf("performing Suspend: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Suspend: %+v", err) + } + + return nil +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/method_update.go b/resource-manager/fabric/2023-11-01/fabriccapacities/method_update.go new file mode 100644 index 00000000000..4552b51b208 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/method_update.go @@ -0,0 +1,75 @@ +package fabriccapacities + +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 + Model *FabricCapacity +} + +// Update ... +func (c FabricCapacitiesClient) Update(ctx context.Context, id CapacityId, input FabricCapacityUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c FabricCapacitiesClient) UpdateThenPoll(ctx context.Context, id CapacityId, input FabricCapacityUpdate) 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/fabric/2023-11-01/fabriccapacities/model_capacityadministration.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_capacityadministration.go new file mode 100644 index 00000000000..5bd94737366 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_capacityadministration.go @@ -0,0 +1,8 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CapacityAdministration struct { + Members []string `json:"members"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_checknameavailabilityrequest.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..e5a333c98e9 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_checknameavailabilityresponse.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..69c97a20815 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_checknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacity.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacity.go new file mode 100644 index 00000000000..6a3cd2e291b --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacity.go @@ -0,0 +1,19 @@ +package fabriccapacities + +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 FabricCapacity struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties FabricCapacityProperties `json:"properties"` + Sku RpSku `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityproperties.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityproperties.go new file mode 100644 index 00000000000..86a50170003 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityproperties.go @@ -0,0 +1,10 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FabricCapacityProperties struct { + Administration CapacityAdministration `json:"administration"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + State *ResourceState `json:"state,omitempty"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityupdate.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityupdate.go new file mode 100644 index 00000000000..3ea754687f1 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityupdate.go @@ -0,0 +1,10 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FabricCapacityUpdate struct { + Properties *FabricCapacityUpdateProperties `json:"properties,omitempty"` + Sku *RpSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityupdateproperties.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityupdateproperties.go new file mode 100644 index 00000000000..7fe2afa5643 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_fabriccapacityupdateproperties.go @@ -0,0 +1,8 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FabricCapacityUpdateProperties struct { + Administration *CapacityAdministration `json:"administration,omitempty"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpsku.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpsku.go new file mode 100644 index 00000000000..9ac6bf5672c --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpsku.go @@ -0,0 +1,9 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RpSku struct { + Name string `json:"name"` + Tier RpSkuTier `json:"tier"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpskudetailsforexistingresource.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpskudetailsforexistingresource.go new file mode 100644 index 00000000000..130356492df --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpskudetailsforexistingresource.go @@ -0,0 +1,9 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RpSkuDetailsForExistingResource struct { + ResourceType string `json:"resourceType"` + Sku RpSku `json:"sku"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpskudetailsfornewresource.go b/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpskudetailsfornewresource.go new file mode 100644 index 00000000000..147da331443 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/model_rpskudetailsfornewresource.go @@ -0,0 +1,10 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RpSkuDetailsForNewResource struct { + Locations []string `json:"locations"` + Name string `json:"name"` + ResourceType string `json:"resourceType"` +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/predicates.go b/resource-manager/fabric/2023-11-01/fabriccapacities/predicates.go new file mode 100644 index 00000000000..7f552100e83 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/predicates.go @@ -0,0 +1,63 @@ +package fabriccapacities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FabricCapacityOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p FabricCapacityOperationPredicate) Matches(input FabricCapacity) 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 RpSkuDetailsForExistingResourceOperationPredicate struct { + ResourceType *string +} + +func (p RpSkuDetailsForExistingResourceOperationPredicate) Matches(input RpSkuDetailsForExistingResource) bool { + + if p.ResourceType != nil && *p.ResourceType != input.ResourceType { + return false + } + + return true +} + +type RpSkuDetailsForNewResourceOperationPredicate struct { + Name *string + ResourceType *string +} + +func (p RpSkuDetailsForNewResourceOperationPredicate) Matches(input RpSkuDetailsForNewResource) bool { + + if p.Name != nil && *p.Name != input.Name { + return false + } + + if p.ResourceType != nil && *p.ResourceType != input.ResourceType { + return false + } + + return true +} diff --git a/resource-manager/fabric/2023-11-01/fabriccapacities/version.go b/resource-manager/fabric/2023-11-01/fabriccapacities/version.go new file mode 100644 index 00000000000..5e2349a8004 --- /dev/null +++ b/resource-manager/fabric/2023-11-01/fabriccapacities/version.go @@ -0,0 +1,12 @@ +package fabriccapacities + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/fabriccapacities/%s", defaultApiVersion) +} diff --git a/resource-manager/mongocluster/2024-07-01/client.go b/resource-manager/mongocluster/2024-07-01/client.go new file mode 100644 index 00000000000..14139e4cc22 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/client.go @@ -0,0 +1,64 @@ +package v2024_07_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/firewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/mongoclusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/privatelinks" + "github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/replicas" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + FirewallRules *firewallrules.FirewallRulesClient + MongoClusters *mongoclusters.MongoClustersClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinks *privatelinks.PrivateLinksClient + Replicas *replicas.ReplicasClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + firewallRulesClient, err := firewallrules.NewFirewallRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FirewallRules client: %+v", err) + } + configureFunc(firewallRulesClient.Client) + + mongoClustersClient, err := mongoclusters.NewMongoClustersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MongoClusters client: %+v", err) + } + configureFunc(mongoClustersClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinksClient, err := privatelinks.NewPrivateLinksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinks client: %+v", err) + } + configureFunc(privateLinksClient.Client) + + replicasClient, err := replicas.NewReplicasClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Replicas client: %+v", err) + } + configureFunc(replicasClient.Client) + + return &Client{ + FirewallRules: firewallRulesClient, + MongoClusters: mongoClustersClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinks: privateLinksClient, + Replicas: replicasClient, + }, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/README.md b/resource-manager/mongocluster/2024-07-01/firewallrules/README.md new file mode 100644 index 00000000000..c99e08473b1 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/firewallrules` Documentation + +The `firewallrules` SDK allows for interaction with the Azure Resource Manager Service `mongocluster` (API Version `2024-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/mongocluster/2024-07-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", "mongoClusterValue", "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", "mongoClusterValue", "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", "mongoClusterValue", "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.ListByMongoCluster` + +```go +ctx := context.TODO() +id := firewallrules.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +// alternatively `client.ListByMongoCluster(ctx, id)` can be used to do batched pagination +items, err := client.ListByMongoClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/client.go b/resource-manager/mongocluster/2024-07-01/firewallrules/client.go new file mode 100644 index 00000000000..ca183214bd2 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/client.go @@ -0,0 +1,26 @@ +package firewallrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRulesClient struct { + Client *resourcemanager.Client +} + +func NewFirewallRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*FirewallRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "firewallrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FirewallRulesClient: %+v", err) + } + + return &FirewallRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/constants.go b/resource-manager/mongocluster/2024-07-01/firewallrules/constants.go new file mode 100644 index 00000000000..4d73490ad59 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/constants.go @@ -0,0 +1,63 @@ +package firewallrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDropping ProvisioningState = "Dropping" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDropping), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "dropping": ProvisioningStateDropping, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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/mongocluster/2024-07-01/firewallrules/id_firewallrule.go b/resource-manager/mongocluster/2024-07-01/firewallrules/id_firewallrule.go new file mode 100644 index 00000000000..010b5ee4fc9 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/id_firewallrule.go @@ -0,0 +1,139 @@ +package firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&FirewallRuleId{}) +} + +var _ resourceids.ResourceId = &FirewallRuleId{} + +// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule +type FirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + MongoClusterName string + FirewallRuleName string +} + +// NewFirewallRuleID returns a new FirewallRuleId struct +func NewFirewallRuleID(subscriptionId string, resourceGroupName string, mongoClusterName string, firewallRuleName string) FirewallRuleId { + return FirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MongoClusterName: mongoClusterName, + 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) + } + + id := FirewallRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + 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) + } + + id := FirewallRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FirewallRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MongoClusterName, ok = input.Parsed["mongoClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "mongoClusterName", input) + } + + if id.FirewallRuleName, ok = input.Parsed["firewallRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "firewallRuleName", input) + } + + return 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.DocumentDB/mongoClusters/%s/firewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MongoClusterName, 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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + resourceids.StaticSegment("staticMongoClusters", "mongoClusters", "mongoClusters"), + resourceids.UserSpecifiedSegment("mongoClusterName", "mongoClusterValue"), + 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("Mongo Cluster Name: %q", id.MongoClusterName), + fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), + } + return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/id_firewallrule_test.go b/resource-manager/mongocluster/2024-07-01/firewallrules/id_firewallrule_test.go new file mode 100644 index 00000000000..0fed627110b --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/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", "mongoClusterValue", "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.MongoClusterName != "mongoClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'MongoClusterName'", id.MongoClusterName, "mongoClusterValue") + } + + 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", "mongoClusterValue", "firewallRuleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/firewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/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.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/firewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MongoClusterName: "mOnGoClUsTeRvAlUe", + 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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/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.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + 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/mongocluster/2024-07-01/firewallrules/id_mongocluster.go b/resource-manager/mongocluster/2024-07-01/firewallrules/id_mongocluster.go new file mode 100644 index 00000000000..adf52e66cce --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/id_mongocluster.go @@ -0,0 +1,130 @@ +package firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MongoClusterId{}) +} + +var _ resourceids.ResourceId = &MongoClusterId{} + +// MongoClusterId is a struct representing the Resource ID for a Mongo Cluster +type MongoClusterId struct { + SubscriptionId string + ResourceGroupName string + MongoClusterName string +} + +// NewMongoClusterID returns a new MongoClusterId struct +func NewMongoClusterID(subscriptionId string, resourceGroupName string, mongoClusterName string) MongoClusterId { + return MongoClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MongoClusterName: mongoClusterName, + } +} + +// ParseMongoClusterID parses 'input' into a MongoClusterId +func ParseMongoClusterID(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMongoClusterIDInsensitively parses 'input' case-insensitively into a MongoClusterId +// note: this method should only be used for API response data and not user input +func ParseMongoClusterIDInsensitively(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MongoClusterId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MongoClusterName, ok = input.Parsed["mongoClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "mongoClusterName", input) + } + + return nil +} + +// ValidateMongoClusterID checks that 'input' can be parsed as a Mongo Cluster ID +func ValidateMongoClusterID(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 := ParseMongoClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Mongo Cluster ID +func (id MongoClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DocumentDB/mongoClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MongoClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Mongo Cluster ID +func (id MongoClusterId) 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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + resourceids.StaticSegment("staticMongoClusters", "mongoClusters", "mongoClusters"), + resourceids.UserSpecifiedSegment("mongoClusterName", "mongoClusterValue"), + } +} + +// String returns a human-readable description of this Mongo Cluster ID +func (id MongoClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Mongo Cluster Name: %q", id.MongoClusterName), + } + return fmt.Sprintf("Mongo Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/id_mongocluster_test.go b/resource-manager/mongocluster/2024-07-01/firewallrules/id_mongocluster_test.go new file mode 100644 index 00000000000..df275e41feb --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/id_mongocluster_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 = &MongoClusterId{} + +func TestNewMongoClusterID(t *testing.T) { + id := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + + 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.MongoClusterName != "mongoClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'MongoClusterName'", id.MongoClusterName, "mongoClusterValue") + } +} + +func TestFormatMongoClusterID(t *testing.T) { + actual := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMongoClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestParseMongoClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MongoClusterName: "mOnGoClUsTeRvAlUe", + }, + }, + { + // 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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestSegmentsForMongoClusterId(t *testing.T) { + segments := MongoClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MongoClusterId 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/mongocluster/2024-07-01/firewallrules/method_createorupdate.go b/resource-manager/mongocluster/2024-07-01/firewallrules/method_createorupdate.go new file mode 100644 index 00000000000..8a5fca1cd9f --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/method_createorupdate.go @@ -0,0 +1,76 @@ +package firewallrules + +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 + Model *FirewallRule +} + +// CreateOrUpdate ... +func (c FirewallRulesClient) CreateOrUpdate(ctx context.Context, id FirewallRuleId, input FirewallRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c 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(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/method_delete.go b/resource-manager/mongocluster/2024-07-01/firewallrules/method_delete.go new file mode 100644 index 00000000000..4eaea8443be --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/method_delete.go @@ -0,0 +1,70 @@ +package firewallrules + +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 FirewallRulesClient) Delete(ctx context.Context, id FirewallRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + 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 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(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/method_get.go b/resource-manager/mongocluster/2024-07-01/firewallrules/method_get.go new file mode 100644 index 00000000000..37bca7c40d8 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/method_get.go @@ -0,0 +1,54 @@ +package firewallrules + +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 *FirewallRule +} + +// Get ... +func (c FirewallRulesClient) Get(ctx context.Context, id FirewallRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model FirewallRule + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/method_listbymongocluster.go b/resource-manager/mongocluster/2024-07-01/firewallrules/method_listbymongocluster.go new file mode 100644 index 00000000000..b26faa50f98 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/method_listbymongocluster.go @@ -0,0 +1,105 @@ +package firewallrules + +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 ListByMongoClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]FirewallRule +} + +type ListByMongoClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []FirewallRule +} + +type ListByMongoClusterCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByMongoClusterCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByMongoCluster ... +func (c FirewallRulesClient) ListByMongoCluster(ctx context.Context, id MongoClusterId) (result ListByMongoClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByMongoClusterCustomPager{}, + Path: fmt.Sprintf("%s/firewallRules", 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 *[]FirewallRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByMongoClusterComplete retrieves all the results into a single object +func (c FirewallRulesClient) ListByMongoClusterComplete(ctx context.Context, id MongoClusterId) (ListByMongoClusterCompleteResult, error) { + return c.ListByMongoClusterCompleteMatchingPredicate(ctx, id, FirewallRuleOperationPredicate{}) +} + +// ListByMongoClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FirewallRulesClient) ListByMongoClusterCompleteMatchingPredicate(ctx context.Context, id MongoClusterId, predicate FirewallRuleOperationPredicate) (result ListByMongoClusterCompleteResult, err error) { + items := make([]FirewallRule, 0) + + resp, err := c.ListByMongoCluster(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByMongoClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/model_firewallrule.go b/resource-manager/mongocluster/2024-07-01/firewallrules/model_firewallrule.go new file mode 100644 index 00000000000..cf1f4b4439d --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/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,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/firewallrules/model_firewallruleproperties.go b/resource-manager/mongocluster/2024-07-01/firewallrules/model_firewallruleproperties.go new file mode 100644 index 00000000000..ae5a1daae96 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/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/mongocluster/2024-07-01/firewallrules/predicates.go b/resource-manager/mongocluster/2024-07-01/firewallrules/predicates.go new file mode 100644 index 00000000000..fb7011b1d3b --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/firewallrules/predicates.go @@ -0,0 +1,27 @@ +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 FirewallRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p FirewallRuleOperationPredicate) Matches(input FirewallRule) 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/mongocluster/2024-07-01/firewallrules/version.go b/resource-manager/mongocluster/2024-07-01/firewallrules/version.go new file mode 100644 index 00000000000..fe03e17f872 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/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 = "2024-07-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/firewallrules/%s", defaultApiVersion) +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/README.md b/resource-manager/mongocluster/2024-07-01/mongoclusters/README.md new file mode 100644 index 00000000000..3718b640ef0 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/README.md @@ -0,0 +1,171 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/mongoclusters` Documentation + +The `mongoclusters` SDK allows for interaction with the Azure Resource Manager Service `mongocluster` (API Version `2024-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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/mongoclusters" +``` + + +### Client Initialization + +```go +client := mongoclusters.NewMongoClustersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MongoClustersClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := mongoclusters.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := mongoclusters.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MongoClustersClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := mongoclusters.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +payload := mongoclusters.MongoCluster{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `MongoClustersClient.Delete` + +```go +ctx := context.TODO() +id := mongoclusters.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MongoClustersClient.Get` + +```go +ctx := context.TODO() +id := mongoclusters.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +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: `MongoClustersClient.List` + +```go +ctx := context.TODO() +id := commonids.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: `MongoClustersClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.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: `MongoClustersClient.ListConnectionStrings` + +```go +ctx := context.TODO() +id := mongoclusters.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +read, err := client.ListConnectionStrings(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MongoClustersClient.Promote` + +```go +ctx := context.TODO() +id := mongoclusters.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +payload := mongoclusters.PromoteReplicaRequest{ + // ... +} + + +if err := client.PromoteThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `MongoClustersClient.Update` + +```go +ctx := context.TODO() +id := mongoclusters.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +payload := mongoclusters.MongoClusterUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/client.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/client.go new file mode 100644 index 00000000000..11f8511f21e --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/client.go @@ -0,0 +1,26 @@ +package mongoclusters + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClustersClient struct { + Client *resourcemanager.Client +} + +func NewMongoClustersClientWithBaseURI(sdkApi sdkEnv.Api) (*MongoClustersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "mongoclusters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MongoClustersClient: %+v", err) + } + + return &MongoClustersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/constants.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/constants.go new file mode 100644 index 00000000000..4835148e9a5 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/constants.go @@ -0,0 +1,594 @@ +package mongoclusters + +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 CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} + +type CreateMode string + +const ( + CreateModeDefault CreateMode = "Default" + CreateModeGeoReplica CreateMode = "GeoReplica" + CreateModePointInTimeRestore CreateMode = "PointInTimeRestore" + CreateModeReplica CreateMode = "Replica" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeDefault), + string(CreateModeGeoReplica), + string(CreateModePointInTimeRestore), + string(CreateModeReplica), + } +} + +func (s *CreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "default": CreateModeDefault, + "georeplica": CreateModeGeoReplica, + "pointintimerestore": CreateModePointInTimeRestore, + "replica": CreateModeReplica, + } + 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 HighAvailabilityMode string + +const ( + HighAvailabilityModeDisabled HighAvailabilityMode = "Disabled" + HighAvailabilityModeSameZone HighAvailabilityMode = "SameZone" + HighAvailabilityModeZoneRedundantPreferred HighAvailabilityMode = "ZoneRedundantPreferred" +) + +func PossibleValuesForHighAvailabilityMode() []string { + return []string{ + string(HighAvailabilityModeDisabled), + string(HighAvailabilityModeSameZone), + string(HighAvailabilityModeZoneRedundantPreferred), + } +} + +func (s *HighAvailabilityMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHighAvailabilityMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHighAvailabilityMode(input string) (*HighAvailabilityMode, error) { + vals := map[string]HighAvailabilityMode{ + "disabled": HighAvailabilityModeDisabled, + "samezone": HighAvailabilityModeSameZone, + "zoneredundantpreferred": HighAvailabilityModeZoneRedundantPreferred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HighAvailabilityMode(input) + return &out, nil +} + +type MongoClusterStatus string + +const ( + MongoClusterStatusDropping MongoClusterStatus = "Dropping" + MongoClusterStatusProvisioning MongoClusterStatus = "Provisioning" + MongoClusterStatusReady MongoClusterStatus = "Ready" + MongoClusterStatusStarting MongoClusterStatus = "Starting" + MongoClusterStatusStopped MongoClusterStatus = "Stopped" + MongoClusterStatusStopping MongoClusterStatus = "Stopping" + MongoClusterStatusUpdating MongoClusterStatus = "Updating" +) + +func PossibleValuesForMongoClusterStatus() []string { + return []string{ + string(MongoClusterStatusDropping), + string(MongoClusterStatusProvisioning), + string(MongoClusterStatusReady), + string(MongoClusterStatusStarting), + string(MongoClusterStatusStopped), + string(MongoClusterStatusStopping), + string(MongoClusterStatusUpdating), + } +} + +func (s *MongoClusterStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMongoClusterStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMongoClusterStatus(input string) (*MongoClusterStatus, error) { + vals := map[string]MongoClusterStatus{ + "dropping": MongoClusterStatusDropping, + "provisioning": MongoClusterStatusProvisioning, + "ready": MongoClusterStatusReady, + "starting": MongoClusterStatusStarting, + "stopped": MongoClusterStatusStopped, + "stopping": MongoClusterStatusStopping, + "updating": MongoClusterStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MongoClusterStatus(input) + return &out, nil +} + +type PreviewFeature string + +const ( + PreviewFeatureGeoReplicas PreviewFeature = "GeoReplicas" +) + +func PossibleValuesForPreviewFeature() []string { + return []string{ + string(PreviewFeatureGeoReplicas), + } +} + +func (s *PreviewFeature) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePreviewFeature(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePreviewFeature(input string) (*PreviewFeature, error) { + vals := map[string]PreviewFeature{ + "georeplicas": PreviewFeatureGeoReplicas, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PreviewFeature(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 (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 PromoteMode string + +const ( + PromoteModeSwitchover PromoteMode = "Switchover" +) + +func PossibleValuesForPromoteMode() []string { + return []string{ + string(PromoteModeSwitchover), + } +} + +func (s *PromoteMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePromoteMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePromoteMode(input string) (*PromoteMode, error) { + vals := map[string]PromoteMode{ + "switchover": PromoteModeSwitchover, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PromoteMode(input) + return &out, nil +} + +type PromoteOption string + +const ( + PromoteOptionForced PromoteOption = "Forced" +) + +func PossibleValuesForPromoteOption() []string { + return []string{ + string(PromoteOptionForced), + } +} + +func (s *PromoteOption) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePromoteOption(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePromoteOption(input string) (*PromoteOption, error) { + vals := map[string]PromoteOption{ + "forced": PromoteOptionForced, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PromoteOption(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDropping ProvisioningState = "Dropping" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDropping), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "dropping": ProvisioningStateDropping, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 ReplicationRole string + +const ( + ReplicationRoleAsyncReplica ReplicationRole = "AsyncReplica" + ReplicationRoleGeoAsyncReplica ReplicationRole = "GeoAsyncReplica" + ReplicationRolePrimary ReplicationRole = "Primary" +) + +func PossibleValuesForReplicationRole() []string { + return []string{ + string(ReplicationRoleAsyncReplica), + string(ReplicationRoleGeoAsyncReplica), + string(ReplicationRolePrimary), + } +} + +func (s *ReplicationRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationRole(input string) (*ReplicationRole, error) { + vals := map[string]ReplicationRole{ + "asyncreplica": ReplicationRoleAsyncReplica, + "geoasyncreplica": ReplicationRoleGeoAsyncReplica, + "primary": ReplicationRolePrimary, + } + 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 ReplicationState string + +const ( + ReplicationStateActive ReplicationState = "Active" + ReplicationStateBroken ReplicationState = "Broken" + ReplicationStateCatchup ReplicationState = "Catchup" + ReplicationStateProvisioning ReplicationState = "Provisioning" + ReplicationStateReconfiguring ReplicationState = "Reconfiguring" + ReplicationStateUpdating ReplicationState = "Updating" +) + +func PossibleValuesForReplicationState() []string { + return []string{ + string(ReplicationStateActive), + string(ReplicationStateBroken), + string(ReplicationStateCatchup), + string(ReplicationStateProvisioning), + string(ReplicationStateReconfiguring), + string(ReplicationStateUpdating), + } +} + +func (s *ReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationState(input string) (*ReplicationState, error) { + vals := map[string]ReplicationState{ + "active": ReplicationStateActive, + "broken": ReplicationStateBroken, + "catchup": ReplicationStateCatchup, + "provisioning": ReplicationStateProvisioning, + "reconfiguring": ReplicationStateReconfiguring, + "updating": ReplicationStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationState(input) + return &out, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/id_location.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_location.go new file mode 100644 index 00000000000..af6ff58de36 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_location.go @@ -0,0 +1,121 @@ +package mongoclusters + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.DocumentDB/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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + 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/mongocluster/2024-07-01/mongoclusters/id_location_test.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_location_test.go new file mode 100644 index 00000000000..900611d9d82 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_location_test.go @@ -0,0 +1,237 @@ +package mongoclusters + +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.DocumentDB/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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DocumentDB/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DocumentDB/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.DocumentDB/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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DocumentDB/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DocumentDB/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.DocumentDB/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/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.dOcUmEnTdB/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/mongocluster/2024-07-01/mongoclusters/id_mongocluster.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_mongocluster.go new file mode 100644 index 00000000000..42ddb3e1fb9 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_mongocluster.go @@ -0,0 +1,130 @@ +package mongoclusters + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MongoClusterId{}) +} + +var _ resourceids.ResourceId = &MongoClusterId{} + +// MongoClusterId is a struct representing the Resource ID for a Mongo Cluster +type MongoClusterId struct { + SubscriptionId string + ResourceGroupName string + MongoClusterName string +} + +// NewMongoClusterID returns a new MongoClusterId struct +func NewMongoClusterID(subscriptionId string, resourceGroupName string, mongoClusterName string) MongoClusterId { + return MongoClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MongoClusterName: mongoClusterName, + } +} + +// ParseMongoClusterID parses 'input' into a MongoClusterId +func ParseMongoClusterID(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMongoClusterIDInsensitively parses 'input' case-insensitively into a MongoClusterId +// note: this method should only be used for API response data and not user input +func ParseMongoClusterIDInsensitively(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MongoClusterId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MongoClusterName, ok = input.Parsed["mongoClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "mongoClusterName", input) + } + + return nil +} + +// ValidateMongoClusterID checks that 'input' can be parsed as a Mongo Cluster ID +func ValidateMongoClusterID(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 := ParseMongoClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Mongo Cluster ID +func (id MongoClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DocumentDB/mongoClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MongoClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Mongo Cluster ID +func (id MongoClusterId) 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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + resourceids.StaticSegment("staticMongoClusters", "mongoClusters", "mongoClusters"), + resourceids.UserSpecifiedSegment("mongoClusterName", "mongoClusterValue"), + } +} + +// String returns a human-readable description of this Mongo Cluster ID +func (id MongoClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Mongo Cluster Name: %q", id.MongoClusterName), + } + return fmt.Sprintf("Mongo Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/id_mongocluster_test.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_mongocluster_test.go new file mode 100644 index 00000000000..c0a0ff675d9 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/id_mongocluster_test.go @@ -0,0 +1,282 @@ +package mongoclusters + +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 = &MongoClusterId{} + +func TestNewMongoClusterID(t *testing.T) { + id := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + + 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.MongoClusterName != "mongoClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'MongoClusterName'", id.MongoClusterName, "mongoClusterValue") + } +} + +func TestFormatMongoClusterID(t *testing.T) { + actual := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMongoClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestParseMongoClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MongoClusterName: "mOnGoClUsTeRvAlUe", + }, + }, + { + // 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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestSegmentsForMongoClusterId(t *testing.T) { + segments := MongoClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MongoClusterId 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/mongocluster/2024-07-01/mongoclusters/method_checknameavailability.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_checknameavailability.go new file mode 100644 index 00000000000..5d85dc625dd --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_checknameavailability.go @@ -0,0 +1,59 @@ +package mongoclusters + +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 *CheckNameAvailabilityResponse +} + +// CheckNameAvailability ... +func (c MongoClustersClient) CheckNameAvailability(ctx context.Context, id LocationId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkMongoClusterNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/method_createorupdate.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_createorupdate.go new file mode 100644 index 00000000000..d31c486a5a7 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_createorupdate.go @@ -0,0 +1,75 @@ +package mongoclusters + +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 + Model *MongoCluster +} + +// CreateOrUpdate ... +func (c MongoClustersClient) CreateOrUpdate(ctx context.Context, id MongoClusterId, input MongoCluster) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c MongoClustersClient) CreateOrUpdateThenPoll(ctx context.Context, id MongoClusterId, input MongoCluster) 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/mongocluster/2024-07-01/mongoclusters/method_delete.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_delete.go new file mode 100644 index 00000000000..f2ab5c143c4 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_delete.go @@ -0,0 +1,70 @@ +package mongoclusters + +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 MongoClustersClient) Delete(ctx context.Context, id MongoClusterId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + 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 MongoClustersClient) DeleteThenPoll(ctx context.Context, id MongoClusterId) 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/mongocluster/2024-07-01/mongoclusters/method_get.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_get.go new file mode 100644 index 00000000000..545c1943581 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_get.go @@ -0,0 +1,54 @@ +package mongoclusters + +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 *MongoCluster +} + +// Get ... +func (c MongoClustersClient) Get(ctx context.Context, id MongoClusterId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MongoCluster + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/method_list.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_list.go new file mode 100644 index 00000000000..957796bf605 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_list.go @@ -0,0 +1,106 @@ +package mongoclusters + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MongoCluster +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MongoCluster +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c MongoClustersClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DocumentDB/mongoClusters", 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 *[]MongoCluster `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MongoClustersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, MongoClusterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MongoClustersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate MongoClusterOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MongoCluster, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/method_listbyresourcegroup.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_listbyresourcegroup.go new file mode 100644 index 00000000000..87c9b782210 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package mongoclusters + +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 *[]MongoCluster +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []MongoCluster +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c MongoClustersClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DocumentDB/mongoClusters", 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 *[]MongoCluster `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c MongoClustersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, MongoClusterOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MongoClustersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate MongoClusterOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]MongoCluster, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/method_listconnectionstrings.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_listconnectionstrings.go new file mode 100644 index 00000000000..d8478c536b4 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_listconnectionstrings.go @@ -0,0 +1,55 @@ +package mongoclusters + +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 ListConnectionStringsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ListConnectionStringsResult +} + +// ListConnectionStrings ... +func (c MongoClustersClient) ListConnectionStrings(ctx context.Context, id MongoClusterId) (result ListConnectionStringsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listConnectionStrings", 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 + } + + var model ListConnectionStringsResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/method_promote.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_promote.go new file mode 100644 index 00000000000..e1305fefd77 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_promote.go @@ -0,0 +1,73 @@ +package mongoclusters + +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 PromoteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Promote ... +func (c MongoClustersClient) Promote(ctx context.Context, id MongoClusterId, input PromoteReplicaRequest) (result PromoteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/promote", 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 +} + +// PromoteThenPoll performs Promote then polls until it's completed +func (c MongoClustersClient) PromoteThenPoll(ctx context.Context, id MongoClusterId, input PromoteReplicaRequest) error { + result, err := c.Promote(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Promote: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Promote: %+v", err) + } + + return nil +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/method_update.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_update.go new file mode 100644 index 00000000000..b0971a43763 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/method_update.go @@ -0,0 +1,75 @@ +package mongoclusters + +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 + Model *MongoCluster +} + +// Update ... +func (c MongoClustersClient) Update(ctx context.Context, id MongoClusterId, input MongoClusterUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c MongoClustersClient) UpdateThenPoll(ctx context.Context, id MongoClusterId, input MongoClusterUpdate) 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/mongocluster/2024-07-01/mongoclusters/model_administratorproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_administratorproperties.go new file mode 100644 index 00000000000..0d5e695ec05 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_administratorproperties.go @@ -0,0 +1,9 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdministratorProperties struct { + Password *string `json:"password,omitempty"` + UserName *string `json:"userName,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_backupproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_backupproperties.go new file mode 100644 index 00000000000..1a78556df72 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_backupproperties.go @@ -0,0 +1,8 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupProperties struct { + EarliestRestoreTime *string `json:"earliestRestoreTime,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_checknameavailabilityrequest.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..b834e55f5ff --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_checknameavailabilityresponse.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..51db08775d6 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_checknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_computeproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_computeproperties.go new file mode 100644 index 00000000000..750d420bf66 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_computeproperties.go @@ -0,0 +1,8 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ComputeProperties struct { + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_connectionstring.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_connectionstring.go new file mode 100644 index 00000000000..75c56104190 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_connectionstring.go @@ -0,0 +1,10 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionString struct { + ConnectionString *string `json:"connectionString,omitempty"` + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_highavailabilityproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_highavailabilityproperties.go new file mode 100644 index 00000000000..7aa466fd370 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_highavailabilityproperties.go @@ -0,0 +1,8 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HighAvailabilityProperties struct { + TargetMode *HighAvailabilityMode `json:"targetMode,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_listconnectionstringsresult.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_listconnectionstringsresult.go new file mode 100644 index 00000000000..bab5c322924 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_listconnectionstringsresult.go @@ -0,0 +1,8 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListConnectionStringsResult struct { + ConnectionStrings *[]ConnectionString `json:"connectionStrings,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongocluster.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongocluster.go new file mode 100644 index 00000000000..7f6d9cb3fd5 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongocluster.go @@ -0,0 +1,18 @@ +package mongoclusters + +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 MongoCluster struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *MongoClusterProperties `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/mongocluster/2024-07-01/mongoclusters/model_mongoclusterproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterproperties.go new file mode 100644 index 00000000000..6474ffeeb4f --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterproperties.go @@ -0,0 +1,25 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClusterProperties struct { + Administrator *AdministratorProperties `json:"administrator,omitempty"` + Backup *BackupProperties `json:"backup,omitempty"` + ClusterStatus *MongoClusterStatus `json:"clusterStatus,omitempty"` + Compute *ComputeProperties `json:"compute,omitempty"` + ConnectionString *string `json:"connectionString,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + HighAvailability *HighAvailabilityProperties `json:"highAvailability,omitempty"` + InfrastructureVersion *string `json:"infrastructureVersion,omitempty"` + PreviewFeatures *[]PreviewFeature `json:"previewFeatures,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + Replica *ReplicationProperties `json:"replica,omitempty"` + ReplicaParameters *MongoClusterReplicaParameters `json:"replicaParameters,omitempty"` + RestoreParameters *MongoClusterRestoreParameters `json:"restoreParameters,omitempty"` + ServerVersion *string `json:"serverVersion,omitempty"` + Sharding *ShardingProperties `json:"sharding,omitempty"` + Storage *StorageProperties `json:"storage,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterreplicaparameters.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterreplicaparameters.go new file mode 100644 index 00000000000..d76486d9568 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterreplicaparameters.go @@ -0,0 +1,9 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClusterReplicaParameters struct { + SourceLocation string `json:"sourceLocation"` + SourceResourceId string `json:"sourceResourceId"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterrestoreparameters.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterrestoreparameters.go new file mode 100644 index 00000000000..0cc10482f00 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterrestoreparameters.go @@ -0,0 +1,27 @@ +package mongoclusters + +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 MongoClusterRestoreParameters struct { + PointInTimeUTC *string `json:"pointInTimeUTC,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +func (o *MongoClusterRestoreParameters) GetPointInTimeUTCAsTime() (*time.Time, error) { + if o.PointInTimeUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PointInTimeUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *MongoClusterRestoreParameters) SetPointInTimeUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PointInTimeUTC = &formatted +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterupdate.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterupdate.go new file mode 100644 index 00000000000..e452dd9823d --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterupdate.go @@ -0,0 +1,9 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClusterUpdate struct { + Properties *MongoClusterUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterupdateproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterupdateproperties.go new file mode 100644 index 00000000000..ee47924c366 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_mongoclusterupdateproperties.go @@ -0,0 +1,16 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClusterUpdateProperties struct { + Administrator *AdministratorProperties `json:"administrator,omitempty"` + Backup *BackupProperties `json:"backup,omitempty"` + Compute *ComputeProperties `json:"compute,omitempty"` + HighAvailability *HighAvailabilityProperties `json:"highAvailability,omitempty"` + PreviewFeatures *[]PreviewFeature `json:"previewFeatures,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + ServerVersion *string `json:"serverVersion,omitempty"` + Sharding *ShardingProperties `json:"sharding,omitempty"` + Storage *StorageProperties `json:"storage,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privateendpoint.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privateendpoint.go new file mode 100644 index 00000000000..2250ebfa9ec --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privateendpoint.go @@ -0,0 +1,8 @@ +package mongoclusters + +// 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/mongocluster/2024-07-01/mongoclusters/model_privateendpointconnection.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privateendpointconnection.go new file mode 100644 index 00000000000..5dafd446486 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package mongoclusters + +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/mongocluster/2024-07-01/mongoclusters/model_privateendpointconnectionproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..d428048d9a8 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package mongoclusters + +// 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/mongocluster/2024-07-01/mongoclusters/model_privatelinkserviceconnectionstate.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..c38b16c9a31 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package mongoclusters + +// 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/mongocluster/2024-07-01/mongoclusters/model_promotereplicarequest.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_promotereplicarequest.go new file mode 100644 index 00000000000..fc3cc927450 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_promotereplicarequest.go @@ -0,0 +1,9 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PromoteReplicaRequest struct { + Mode *PromoteMode `json:"mode,omitempty"` + PromoteOption PromoteOption `json:"promoteOption"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_replicationproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_replicationproperties.go new file mode 100644 index 00000000000..09303ead8cf --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_replicationproperties.go @@ -0,0 +1,10 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProperties struct { + ReplicationState *ReplicationState `json:"replicationState,omitempty"` + Role *ReplicationRole `json:"role,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_shardingproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_shardingproperties.go new file mode 100644 index 00000000000..b3769061679 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_shardingproperties.go @@ -0,0 +1,8 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShardingProperties struct { + ShardCount *int64 `json:"shardCount,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/model_storageproperties.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_storageproperties.go new file mode 100644 index 00000000000..94d834c45f1 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/model_storageproperties.go @@ -0,0 +1,8 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageProperties struct { + SizeGb *int64 `json:"sizeGb,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/mongoclusters/predicates.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/predicates.go new file mode 100644 index 00000000000..2961ccc5ae0 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/predicates.go @@ -0,0 +1,32 @@ +package mongoclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClusterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p MongoClusterOperationPredicate) Matches(input MongoCluster) 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/mongocluster/2024-07-01/mongoclusters/version.go b/resource-manager/mongocluster/2024-07-01/mongoclusters/version.go new file mode 100644 index 00000000000..30c90ff560c --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/mongoclusters/version.go @@ -0,0 +1,12 @@ +package mongoclusters + +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 = "2024-07-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/mongoclusters/%s", defaultApiVersion) +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/README.md b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..41e6098e6cf --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `mongocluster` (API Version `2024-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/mongocluster/2024-07-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Create` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue", "privateEndpointConnectionValue") + +payload := privateendpointconnections.PrivateEndpointConnectionResource{ + // ... +} + + +if err := client.CreateThenPoll(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", "mongoClusterValue", "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", "mongoClusterValue", "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.ListByMongoCluster` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +// alternatively `client.ListByMongoCluster(ctx, id)` can be used to do batched pagination +items, err := client.ListByMongoClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/client.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..3bf7a6afe1f --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/constants.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..c5850609650 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/constants.go @@ -0,0 +1,101 @@ +package privateendpointconnections + +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 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 (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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/mongocluster/2024-07-01/privateendpointconnections/id_mongocluster.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_mongocluster.go new file mode 100644 index 00000000000..19c2845c398 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_mongocluster.go @@ -0,0 +1,130 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MongoClusterId{}) +} + +var _ resourceids.ResourceId = &MongoClusterId{} + +// MongoClusterId is a struct representing the Resource ID for a Mongo Cluster +type MongoClusterId struct { + SubscriptionId string + ResourceGroupName string + MongoClusterName string +} + +// NewMongoClusterID returns a new MongoClusterId struct +func NewMongoClusterID(subscriptionId string, resourceGroupName string, mongoClusterName string) MongoClusterId { + return MongoClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MongoClusterName: mongoClusterName, + } +} + +// ParseMongoClusterID parses 'input' into a MongoClusterId +func ParseMongoClusterID(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMongoClusterIDInsensitively parses 'input' case-insensitively into a MongoClusterId +// note: this method should only be used for API response data and not user input +func ParseMongoClusterIDInsensitively(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MongoClusterId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MongoClusterName, ok = input.Parsed["mongoClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "mongoClusterName", input) + } + + return nil +} + +// ValidateMongoClusterID checks that 'input' can be parsed as a Mongo Cluster ID +func ValidateMongoClusterID(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 := ParseMongoClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Mongo Cluster ID +func (id MongoClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DocumentDB/mongoClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MongoClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Mongo Cluster ID +func (id MongoClusterId) 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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + resourceids.StaticSegment("staticMongoClusters", "mongoClusters", "mongoClusters"), + resourceids.UserSpecifiedSegment("mongoClusterName", "mongoClusterValue"), + } +} + +// String returns a human-readable description of this Mongo Cluster ID +func (id MongoClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Mongo Cluster Name: %q", id.MongoClusterName), + } + return fmt.Sprintf("Mongo Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_mongocluster_test.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_mongocluster_test.go new file mode 100644 index 00000000000..491f04a407b --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_mongocluster_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 = &MongoClusterId{} + +func TestNewMongoClusterID(t *testing.T) { + id := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + + 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.MongoClusterName != "mongoClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'MongoClusterName'", id.MongoClusterName, "mongoClusterValue") + } +} + +func TestFormatMongoClusterID(t *testing.T) { + actual := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMongoClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestParseMongoClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MongoClusterName: "mOnGoClUsTeRvAlUe", + }, + }, + { + // 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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestSegmentsForMongoClusterId(t *testing.T) { + segments := MongoClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MongoClusterId 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/mongocluster/2024-07-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..99d467b8031 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + MongoClusterName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, mongoClusterName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MongoClusterName: mongoClusterName, + 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) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + 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) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MongoClusterName, ok = input.Parsed["mongoClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "mongoClusterName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return 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.DocumentDB/mongoClusters/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MongoClusterName, 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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + resourceids.StaticSegment("staticMongoClusters", "mongoClusters", "mongoClusters"), + resourceids.UserSpecifiedSegment("mongoClusterName", "mongoClusterValue"), + 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("Mongo Cluster Name: %q", id.MongoClusterName), + 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/mongocluster/2024-07-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..79291df2593 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/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", "mongoClusterValue", "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.MongoClusterName != "mongoClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'MongoClusterName'", id.MongoClusterName, "mongoClusterValue") + } + + 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", "mongoClusterValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/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.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MongoClusterName: "mOnGoClUsTeRvAlUe", + 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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/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.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + 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/mongocluster/2024-07-01/privateendpointconnections/method_create.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_create.go new file mode 100644 index 00000000000..dbeff3c05bd --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_create.go @@ -0,0 +1,76 @@ +package privateendpointconnections + +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 CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnectionResource +} + +// Create ... +func (c PrivateEndpointConnectionsClient) Create(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnectionResource) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c PrivateEndpointConnectionsClient) CreateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnectionResource) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_delete.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..c80136ed33a --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_delete.go @@ -0,0 +1,70 @@ +package privateendpointconnections + +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 PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + 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 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(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_get.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..eb7555da990 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_get.go @@ -0,0 +1,54 @@ +package privateendpointconnections + +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 *PrivateEndpointConnectionResource +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnectionResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_listbymongocluster.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_listbymongocluster.go new file mode 100644 index 00000000000..417493c0ff1 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/method_listbymongocluster.go @@ -0,0 +1,105 @@ +package privateendpointconnections + +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 ListByMongoClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnectionResource +} + +type ListByMongoClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnectionResource +} + +type ListByMongoClusterCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByMongoClusterCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByMongoCluster ... +func (c PrivateEndpointConnectionsClient) ListByMongoCluster(ctx context.Context, id MongoClusterId) (result ListByMongoClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByMongoClusterCustomPager{}, + 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 *[]PrivateEndpointConnectionResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByMongoClusterComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) ListByMongoClusterComplete(ctx context.Context, id MongoClusterId) (ListByMongoClusterCompleteResult, error) { + return c.ListByMongoClusterCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionResourceOperationPredicate{}) +} + +// ListByMongoClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) ListByMongoClusterCompleteMatchingPredicate(ctx context.Context, id MongoClusterId, predicate PrivateEndpointConnectionResourceOperationPredicate) (result ListByMongoClusterCompleteResult, err error) { + items := make([]PrivateEndpointConnectionResource, 0) + + resp, err := c.ListByMongoCluster(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByMongoClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +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 PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..fb540c904b6 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/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/mongocluster/2024-07-01/privateendpointconnections/model_privateendpointconnectionresource.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privateendpointconnectionresource.go new file mode 100644 index 00000000000..d067baf3075 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privateendpointconnectionresource.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 PrivateEndpointConnectionResource 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/mongocluster/2024-07-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ec3f7a9f24c --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +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 PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/privateendpointconnections/predicates.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..0e0476a3195 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/predicates.go @@ -0,0 +1,27 @@ +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 PrivateEndpointConnectionResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionResourceOperationPredicate) Matches(input PrivateEndpointConnectionResource) 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/mongocluster/2024-07-01/privateendpointconnections/version.go b/resource-manager/mongocluster/2024-07-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..602fe619710 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/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 = "2024-07-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/mongocluster/2024-07-01/privatelinks/README.md b/resource-manager/mongocluster/2024-07-01/privatelinks/README.md new file mode 100644 index 00000000000..f3ffca95815 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/privatelinks` Documentation + +The `privatelinks` SDK allows for interaction with the Azure Resource Manager Service `mongocluster` (API Version `2024-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/mongocluster/2024-07-01/privatelinks" +``` + + +### Client Initialization + +```go +client := privatelinks.NewPrivateLinksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinksClient.ListByMongoCluster` + +```go +ctx := context.TODO() +id := privatelinks.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +// alternatively `client.ListByMongoCluster(ctx, id)` can be used to do batched pagination +items, err := client.ListByMongoClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/mongocluster/2024-07-01/privatelinks/client.go b/resource-manager/mongocluster/2024-07-01/privatelinks/client.go new file mode 100644 index 00000000000..8cd3cddf2c2 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/client.go @@ -0,0 +1,26 @@ +package privatelinks + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinksClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinksClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatelinks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinksClient: %+v", err) + } + + return &PrivateLinksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/privatelinks/id_mongocluster.go b/resource-manager/mongocluster/2024-07-01/privatelinks/id_mongocluster.go new file mode 100644 index 00000000000..2673665ec60 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/id_mongocluster.go @@ -0,0 +1,130 @@ +package privatelinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MongoClusterId{}) +} + +var _ resourceids.ResourceId = &MongoClusterId{} + +// MongoClusterId is a struct representing the Resource ID for a Mongo Cluster +type MongoClusterId struct { + SubscriptionId string + ResourceGroupName string + MongoClusterName string +} + +// NewMongoClusterID returns a new MongoClusterId struct +func NewMongoClusterID(subscriptionId string, resourceGroupName string, mongoClusterName string) MongoClusterId { + return MongoClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MongoClusterName: mongoClusterName, + } +} + +// ParseMongoClusterID parses 'input' into a MongoClusterId +func ParseMongoClusterID(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMongoClusterIDInsensitively parses 'input' case-insensitively into a MongoClusterId +// note: this method should only be used for API response data and not user input +func ParseMongoClusterIDInsensitively(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MongoClusterId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MongoClusterName, ok = input.Parsed["mongoClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "mongoClusterName", input) + } + + return nil +} + +// ValidateMongoClusterID checks that 'input' can be parsed as a Mongo Cluster ID +func ValidateMongoClusterID(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 := ParseMongoClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Mongo Cluster ID +func (id MongoClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DocumentDB/mongoClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MongoClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Mongo Cluster ID +func (id MongoClusterId) 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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + resourceids.StaticSegment("staticMongoClusters", "mongoClusters", "mongoClusters"), + resourceids.UserSpecifiedSegment("mongoClusterName", "mongoClusterValue"), + } +} + +// String returns a human-readable description of this Mongo Cluster ID +func (id MongoClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Mongo Cluster Name: %q", id.MongoClusterName), + } + return fmt.Sprintf("Mongo Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/mongocluster/2024-07-01/privatelinks/id_mongocluster_test.go b/resource-manager/mongocluster/2024-07-01/privatelinks/id_mongocluster_test.go new file mode 100644 index 00000000000..f664f3b6e7d --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/id_mongocluster_test.go @@ -0,0 +1,282 @@ +package privatelinks + +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 = &MongoClusterId{} + +func TestNewMongoClusterID(t *testing.T) { + id := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + + 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.MongoClusterName != "mongoClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'MongoClusterName'", id.MongoClusterName, "mongoClusterValue") + } +} + +func TestFormatMongoClusterID(t *testing.T) { + actual := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMongoClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestParseMongoClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MongoClusterName: "mOnGoClUsTeRvAlUe", + }, + }, + { + // 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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestSegmentsForMongoClusterId(t *testing.T) { + segments := MongoClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MongoClusterId 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/mongocluster/2024-07-01/privatelinks/method_listbymongocluster.go b/resource-manager/mongocluster/2024-07-01/privatelinks/method_listbymongocluster.go new file mode 100644 index 00000000000..6c3ac734463 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/method_listbymongocluster.go @@ -0,0 +1,105 @@ +package privatelinks + +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 ListByMongoClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListByMongoClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +type ListByMongoClusterCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByMongoClusterCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByMongoCluster ... +func (c PrivateLinksClient) ListByMongoCluster(ctx context.Context, id MongoClusterId) (result ListByMongoClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByMongoClusterCustomPager{}, + 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:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByMongoClusterComplete retrieves all the results into a single object +func (c PrivateLinksClient) ListByMongoClusterComplete(ctx context.Context, id MongoClusterId) (ListByMongoClusterCompleteResult, error) { + return c.ListByMongoClusterCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ListByMongoClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinksClient) ListByMongoClusterCompleteMatchingPredicate(ctx context.Context, id MongoClusterId, predicate PrivateLinkResourceOperationPredicate) (result ListByMongoClusterCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.ListByMongoCluster(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByMongoClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/mongocluster/2024-07-01/privatelinks/model_privatelinkresource.go b/resource-manager/mongocluster/2024-07-01/privatelinks/model_privatelinkresource.go new file mode 100644 index 00000000000..63ce94df72b --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/model_privatelinkresource.go @@ -0,0 +1,16 @@ +package privatelinks + +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/mongocluster/2024-07-01/privatelinks/model_privatelinkresourceproperties.go b/resource-manager/mongocluster/2024-07-01/privatelinks/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..7b583949a37 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/privatelinks/predicates.go b/resource-manager/mongocluster/2024-07-01/privatelinks/predicates.go new file mode 100644 index 00000000000..40fd722295c --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/predicates.go @@ -0,0 +1,27 @@ +package privatelinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/mongocluster/2024-07-01/privatelinks/version.go b/resource-manager/mongocluster/2024-07-01/privatelinks/version.go new file mode 100644 index 00000000000..28fd9c2aa5a --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/privatelinks/version.go @@ -0,0 +1,12 @@ +package privatelinks + +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 = "2024-07-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinks/%s", defaultApiVersion) +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/README.md b/resource-manager/mongocluster/2024-07-01/replicas/README.md new file mode 100644 index 00000000000..18d95c0e8ad --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/mongocluster/2024-07-01/replicas` Documentation + +The `replicas` SDK allows for interaction with the Azure Resource Manager Service `mongocluster` (API Version `2024-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/mongocluster/2024-07-01/replicas" +``` + + +### Client Initialization + +```go +client := replicas.NewReplicasClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicasClient.ListByParent` + +```go +ctx := context.TODO() +id := replicas.NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + +// alternatively `client.ListByParent(ctx, id)` can be used to do batched pagination +items, err := client.ListByParentComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/mongocluster/2024-07-01/replicas/client.go b/resource-manager/mongocluster/2024-07-01/replicas/client.go new file mode 100644 index 00000000000..d971742c1bd --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/client.go @@ -0,0 +1,26 @@ +package replicas + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicasClient struct { + Client *resourcemanager.Client +} + +func NewReplicasClientWithBaseURI(sdkApi sdkEnv.Api) (*ReplicasClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "replicas", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ReplicasClient: %+v", err) + } + + return &ReplicasClient{ + Client: client, + }, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/constants.go b/resource-manager/mongocluster/2024-07-01/replicas/constants.go new file mode 100644 index 00000000000..b73bfd9ea40 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/constants.go @@ -0,0 +1,477 @@ +package replicas + +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 CreateMode string + +const ( + CreateModeDefault CreateMode = "Default" + CreateModeGeoReplica CreateMode = "GeoReplica" + CreateModePointInTimeRestore CreateMode = "PointInTimeRestore" + CreateModeReplica CreateMode = "Replica" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeDefault), + string(CreateModeGeoReplica), + string(CreateModePointInTimeRestore), + string(CreateModeReplica), + } +} + +func (s *CreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "default": CreateModeDefault, + "georeplica": CreateModeGeoReplica, + "pointintimerestore": CreateModePointInTimeRestore, + "replica": CreateModeReplica, + } + 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 HighAvailabilityMode string + +const ( + HighAvailabilityModeDisabled HighAvailabilityMode = "Disabled" + HighAvailabilityModeSameZone HighAvailabilityMode = "SameZone" + HighAvailabilityModeZoneRedundantPreferred HighAvailabilityMode = "ZoneRedundantPreferred" +) + +func PossibleValuesForHighAvailabilityMode() []string { + return []string{ + string(HighAvailabilityModeDisabled), + string(HighAvailabilityModeSameZone), + string(HighAvailabilityModeZoneRedundantPreferred), + } +} + +func (s *HighAvailabilityMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHighAvailabilityMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHighAvailabilityMode(input string) (*HighAvailabilityMode, error) { + vals := map[string]HighAvailabilityMode{ + "disabled": HighAvailabilityModeDisabled, + "samezone": HighAvailabilityModeSameZone, + "zoneredundantpreferred": HighAvailabilityModeZoneRedundantPreferred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HighAvailabilityMode(input) + return &out, nil +} + +type MongoClusterStatus string + +const ( + MongoClusterStatusDropping MongoClusterStatus = "Dropping" + MongoClusterStatusProvisioning MongoClusterStatus = "Provisioning" + MongoClusterStatusReady MongoClusterStatus = "Ready" + MongoClusterStatusStarting MongoClusterStatus = "Starting" + MongoClusterStatusStopped MongoClusterStatus = "Stopped" + MongoClusterStatusStopping MongoClusterStatus = "Stopping" + MongoClusterStatusUpdating MongoClusterStatus = "Updating" +) + +func PossibleValuesForMongoClusterStatus() []string { + return []string{ + string(MongoClusterStatusDropping), + string(MongoClusterStatusProvisioning), + string(MongoClusterStatusReady), + string(MongoClusterStatusStarting), + string(MongoClusterStatusStopped), + string(MongoClusterStatusStopping), + string(MongoClusterStatusUpdating), + } +} + +func (s *MongoClusterStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMongoClusterStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMongoClusterStatus(input string) (*MongoClusterStatus, error) { + vals := map[string]MongoClusterStatus{ + "dropping": MongoClusterStatusDropping, + "provisioning": MongoClusterStatusProvisioning, + "ready": MongoClusterStatusReady, + "starting": MongoClusterStatusStarting, + "stopped": MongoClusterStatusStopped, + "stopping": MongoClusterStatusStopping, + "updating": MongoClusterStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MongoClusterStatus(input) + return &out, nil +} + +type PreviewFeature string + +const ( + PreviewFeatureGeoReplicas PreviewFeature = "GeoReplicas" +) + +func PossibleValuesForPreviewFeature() []string { + return []string{ + string(PreviewFeatureGeoReplicas), + } +} + +func (s *PreviewFeature) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePreviewFeature(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePreviewFeature(input string) (*PreviewFeature, error) { + vals := map[string]PreviewFeature{ + "georeplicas": PreviewFeatureGeoReplicas, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PreviewFeature(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 (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDropping ProvisioningState = "Dropping" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDropping), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "dropping": ProvisioningStateDropping, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +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 ReplicationRole string + +const ( + ReplicationRoleAsyncReplica ReplicationRole = "AsyncReplica" + ReplicationRoleGeoAsyncReplica ReplicationRole = "GeoAsyncReplica" + ReplicationRolePrimary ReplicationRole = "Primary" +) + +func PossibleValuesForReplicationRole() []string { + return []string{ + string(ReplicationRoleAsyncReplica), + string(ReplicationRoleGeoAsyncReplica), + string(ReplicationRolePrimary), + } +} + +func (s *ReplicationRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationRole(input string) (*ReplicationRole, error) { + vals := map[string]ReplicationRole{ + "asyncreplica": ReplicationRoleAsyncReplica, + "geoasyncreplica": ReplicationRoleGeoAsyncReplica, + "primary": ReplicationRolePrimary, + } + 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 ReplicationState string + +const ( + ReplicationStateActive ReplicationState = "Active" + ReplicationStateBroken ReplicationState = "Broken" + ReplicationStateCatchup ReplicationState = "Catchup" + ReplicationStateProvisioning ReplicationState = "Provisioning" + ReplicationStateReconfiguring ReplicationState = "Reconfiguring" + ReplicationStateUpdating ReplicationState = "Updating" +) + +func PossibleValuesForReplicationState() []string { + return []string{ + string(ReplicationStateActive), + string(ReplicationStateBroken), + string(ReplicationStateCatchup), + string(ReplicationStateProvisioning), + string(ReplicationStateReconfiguring), + string(ReplicationStateUpdating), + } +} + +func (s *ReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationState(input string) (*ReplicationState, error) { + vals := map[string]ReplicationState{ + "active": ReplicationStateActive, + "broken": ReplicationStateBroken, + "catchup": ReplicationStateCatchup, + "provisioning": ReplicationStateProvisioning, + "reconfiguring": ReplicationStateReconfiguring, + "updating": ReplicationStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationState(input) + return &out, nil +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/id_mongocluster.go b/resource-manager/mongocluster/2024-07-01/replicas/id_mongocluster.go new file mode 100644 index 00000000000..a15f89b5acb --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/id_mongocluster.go @@ -0,0 +1,130 @@ +package replicas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MongoClusterId{}) +} + +var _ resourceids.ResourceId = &MongoClusterId{} + +// MongoClusterId is a struct representing the Resource ID for a Mongo Cluster +type MongoClusterId struct { + SubscriptionId string + ResourceGroupName string + MongoClusterName string +} + +// NewMongoClusterID returns a new MongoClusterId struct +func NewMongoClusterID(subscriptionId string, resourceGroupName string, mongoClusterName string) MongoClusterId { + return MongoClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MongoClusterName: mongoClusterName, + } +} + +// ParseMongoClusterID parses 'input' into a MongoClusterId +func ParseMongoClusterID(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMongoClusterIDInsensitively parses 'input' case-insensitively into a MongoClusterId +// note: this method should only be used for API response data and not user input +func ParseMongoClusterIDInsensitively(input string) (*MongoClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&MongoClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MongoClusterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MongoClusterId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MongoClusterName, ok = input.Parsed["mongoClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "mongoClusterName", input) + } + + return nil +} + +// ValidateMongoClusterID checks that 'input' can be parsed as a Mongo Cluster ID +func ValidateMongoClusterID(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 := ParseMongoClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Mongo Cluster ID +func (id MongoClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DocumentDB/mongoClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MongoClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Mongo Cluster ID +func (id MongoClusterId) 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("staticMicrosoftDocumentDB", "Microsoft.DocumentDB", "Microsoft.DocumentDB"), + resourceids.StaticSegment("staticMongoClusters", "mongoClusters", "mongoClusters"), + resourceids.UserSpecifiedSegment("mongoClusterName", "mongoClusterValue"), + } +} + +// String returns a human-readable description of this Mongo Cluster ID +func (id MongoClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Mongo Cluster Name: %q", id.MongoClusterName), + } + return fmt.Sprintf("Mongo Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/id_mongocluster_test.go b/resource-manager/mongocluster/2024-07-01/replicas/id_mongocluster_test.go new file mode 100644 index 00000000000..bb26c044c89 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/id_mongocluster_test.go @@ -0,0 +1,282 @@ +package replicas + +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 = &MongoClusterId{} + +func TestNewMongoClusterID(t *testing.T) { + id := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue") + + 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.MongoClusterName != "mongoClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'MongoClusterName'", id.MongoClusterName, "mongoClusterValue") + } +} + +func TestFormatMongoClusterID(t *testing.T) { + actual := NewMongoClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "mongoClusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMongoClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestParseMongoClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MongoClusterId + }{ + { + // 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.DocumentDB", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MongoClusterName: "mongoClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DocumentDB/mongoClusters/mongoClusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe", + Expected: &MongoClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MongoClusterName: "mOnGoClUsTeRvAlUe", + }, + }, + { + // 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.dOcUmEnTdB/mOnGoClUsTeRs/mOnGoClUsTeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMongoClusterIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MongoClusterName != v.Expected.MongoClusterName { + t.Fatalf("Expected %q but got %q for MongoClusterName", v.Expected.MongoClusterName, actual.MongoClusterName) + } + + } +} + +func TestSegmentsForMongoClusterId(t *testing.T) { + segments := MongoClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MongoClusterId 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/mongocluster/2024-07-01/replicas/method_listbyparent.go b/resource-manager/mongocluster/2024-07-01/replicas/method_listbyparent.go new file mode 100644 index 00000000000..b38b327ec46 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/method_listbyparent.go @@ -0,0 +1,105 @@ +package replicas + +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 ListByParentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Replica +} + +type ListByParentCompleteResult struct { + LatestHttpResponse *http.Response + Items []Replica +} + +type ListByParentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByParentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByParent ... +func (c ReplicasClient) ListByParent(ctx context.Context, id MongoClusterId) (result ListByParentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByParentCustomPager{}, + Path: fmt.Sprintf("%s/replicas", 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 *[]Replica `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByParentComplete retrieves all the results into a single object +func (c ReplicasClient) ListByParentComplete(ctx context.Context, id MongoClusterId) (ListByParentCompleteResult, error) { + return c.ListByParentCompleteMatchingPredicate(ctx, id, ReplicaOperationPredicate{}) +} + +// ListByParentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReplicasClient) ListByParentCompleteMatchingPredicate(ctx context.Context, id MongoClusterId, predicate ReplicaOperationPredicate) (result ListByParentCompleteResult, err error) { + items := make([]Replica, 0) + + resp, err := c.ListByParent(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + 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 = ListByParentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_administratorproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_administratorproperties.go new file mode 100644 index 00000000000..95d40a26d0e --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_administratorproperties.go @@ -0,0 +1,9 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdministratorProperties struct { + Password *string `json:"password,omitempty"` + UserName *string `json:"userName,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_backupproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_backupproperties.go new file mode 100644 index 00000000000..6dac1e4d52f --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_backupproperties.go @@ -0,0 +1,8 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupProperties struct { + EarliestRestoreTime *string `json:"earliestRestoreTime,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_computeproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_computeproperties.go new file mode 100644 index 00000000000..2012db5ec56 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_computeproperties.go @@ -0,0 +1,8 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ComputeProperties struct { + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_highavailabilityproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_highavailabilityproperties.go new file mode 100644 index 00000000000..674ffe63fae --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_highavailabilityproperties.go @@ -0,0 +1,8 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HighAvailabilityProperties struct { + TargetMode *HighAvailabilityMode `json:"targetMode,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterproperties.go new file mode 100644 index 00000000000..fb3ba1cca11 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterproperties.go @@ -0,0 +1,25 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClusterProperties struct { + Administrator *AdministratorProperties `json:"administrator,omitempty"` + Backup *BackupProperties `json:"backup,omitempty"` + ClusterStatus *MongoClusterStatus `json:"clusterStatus,omitempty"` + Compute *ComputeProperties `json:"compute,omitempty"` + ConnectionString *string `json:"connectionString,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + HighAvailability *HighAvailabilityProperties `json:"highAvailability,omitempty"` + InfrastructureVersion *string `json:"infrastructureVersion,omitempty"` + PreviewFeatures *[]PreviewFeature `json:"previewFeatures,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + Replica *ReplicationProperties `json:"replica,omitempty"` + ReplicaParameters *MongoClusterReplicaParameters `json:"replicaParameters,omitempty"` + RestoreParameters *MongoClusterRestoreParameters `json:"restoreParameters,omitempty"` + ServerVersion *string `json:"serverVersion,omitempty"` + Sharding *ShardingProperties `json:"sharding,omitempty"` + Storage *StorageProperties `json:"storage,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterreplicaparameters.go b/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterreplicaparameters.go new file mode 100644 index 00000000000..675f286a849 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterreplicaparameters.go @@ -0,0 +1,9 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MongoClusterReplicaParameters struct { + SourceLocation string `json:"sourceLocation"` + SourceResourceId string `json:"sourceResourceId"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterrestoreparameters.go b/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterrestoreparameters.go new file mode 100644 index 00000000000..7cbd10e8376 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_mongoclusterrestoreparameters.go @@ -0,0 +1,27 @@ +package replicas + +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 MongoClusterRestoreParameters struct { + PointInTimeUTC *string `json:"pointInTimeUTC,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +func (o *MongoClusterRestoreParameters) GetPointInTimeUTCAsTime() (*time.Time, error) { + if o.PointInTimeUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PointInTimeUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *MongoClusterRestoreParameters) SetPointInTimeUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PointInTimeUTC = &formatted +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_privateendpoint.go b/resource-manager/mongocluster/2024-07-01/replicas/model_privateendpoint.go new file mode 100644 index 00000000000..48ed00f3333 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_privateendpoint.go @@ -0,0 +1,8 @@ +package replicas + +// 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/mongocluster/2024-07-01/replicas/model_privateendpointconnection.go b/resource-manager/mongocluster/2024-07-01/replicas/model_privateendpointconnection.go new file mode 100644 index 00000000000..2ff0aaed8d4 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package replicas + +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/mongocluster/2024-07-01/replicas/model_privateendpointconnectionproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..d3068b6993f --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package replicas + +// 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/mongocluster/2024-07-01/replicas/model_privatelinkserviceconnectionstate.go b/resource-manager/mongocluster/2024-07-01/replicas/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..311ee4497b7 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package replicas + +// 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/mongocluster/2024-07-01/replicas/model_replica.go b/resource-manager/mongocluster/2024-07-01/replicas/model_replica.go new file mode 100644 index 00000000000..1527089f686 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_replica.go @@ -0,0 +1,16 @@ +package replicas + +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 Replica struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MongoClusterProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_replicationproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_replicationproperties.go new file mode 100644 index 00000000000..29d36a9bd9b --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_replicationproperties.go @@ -0,0 +1,10 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProperties struct { + ReplicationState *ReplicationState `json:"replicationState,omitempty"` + Role *ReplicationRole `json:"role,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_shardingproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_shardingproperties.go new file mode 100644 index 00000000000..73de4bf60f5 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_shardingproperties.go @@ -0,0 +1,8 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShardingProperties struct { + ShardCount *int64 `json:"shardCount,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/model_storageproperties.go b/resource-manager/mongocluster/2024-07-01/replicas/model_storageproperties.go new file mode 100644 index 00000000000..377bae9a096 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/model_storageproperties.go @@ -0,0 +1,8 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageProperties struct { + SizeGb *int64 `json:"sizeGb,omitempty"` +} diff --git a/resource-manager/mongocluster/2024-07-01/replicas/predicates.go b/resource-manager/mongocluster/2024-07-01/replicas/predicates.go new file mode 100644 index 00000000000..3f22701f0f2 --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/predicates.go @@ -0,0 +1,27 @@ +package replicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicaOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ReplicaOperationPredicate) Matches(input Replica) 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/mongocluster/2024-07-01/replicas/version.go b/resource-manager/mongocluster/2024-07-01/replicas/version.go new file mode 100644 index 00000000000..307b315b29f --- /dev/null +++ b/resource-manager/mongocluster/2024-07-01/replicas/version.go @@ -0,0 +1,12 @@ +package replicas + +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 = "2024-07-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicas/%s", defaultApiVersion) +}