diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/README.md b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/README.md new file mode 100644 index 00000000000..993a049dabb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/cacertificates` Documentation + +The `cacertificates` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/cacertificates" +``` + + +### Client Initialization + +```go +client := cacertificates.NewCaCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CaCertificatesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := cacertificates.NewCaCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "caCertificateValue") + +payload := cacertificates.CaCertificate{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CaCertificatesClient.Delete` + +```go +ctx := context.TODO() +id := cacertificates.NewCaCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "caCertificateValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CaCertificatesClient.Get` + +```go +ctx := context.TODO() +id := cacertificates.NewCaCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "caCertificateValue") + +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: `CaCertificatesClient.ListByNamespace` + +```go +ctx := context.TODO() +id := cacertificates.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +// alternatively `client.ListByNamespace(ctx, id, cacertificates.DefaultListByNamespaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByNamespaceComplete(ctx, id, cacertificates.DefaultListByNamespaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/client.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/client.go new file mode 100644 index 00000000000..8a649cab30f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/client.go @@ -0,0 +1,26 @@ +package cacertificates + +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 CaCertificatesClient struct { + Client *resourcemanager.Client +} + +func NewCaCertificatesClientWithBaseURI(sdkApi sdkEnv.Api) (*CaCertificatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "cacertificates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CaCertificatesClient: %+v", err) + } + + return &CaCertificatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/constants.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/constants.go new file mode 100644 index 00000000000..8f994c04dae --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/constants.go @@ -0,0 +1,66 @@ +package cacertificates + +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 CaCertificateProvisioningState string + +const ( + CaCertificateProvisioningStateCanceled CaCertificateProvisioningState = "Canceled" + CaCertificateProvisioningStateCreating CaCertificateProvisioningState = "Creating" + CaCertificateProvisioningStateDeleted CaCertificateProvisioningState = "Deleted" + CaCertificateProvisioningStateDeleting CaCertificateProvisioningState = "Deleting" + CaCertificateProvisioningStateFailed CaCertificateProvisioningState = "Failed" + CaCertificateProvisioningStateSucceeded CaCertificateProvisioningState = "Succeeded" + CaCertificateProvisioningStateUpdating CaCertificateProvisioningState = "Updating" +) + +func PossibleValuesForCaCertificateProvisioningState() []string { + return []string{ + string(CaCertificateProvisioningStateCanceled), + string(CaCertificateProvisioningStateCreating), + string(CaCertificateProvisioningStateDeleted), + string(CaCertificateProvisioningStateDeleting), + string(CaCertificateProvisioningStateFailed), + string(CaCertificateProvisioningStateSucceeded), + string(CaCertificateProvisioningStateUpdating), + } +} + +func (s *CaCertificateProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCaCertificateProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCaCertificateProvisioningState(input string) (*CaCertificateProvisioningState, error) { + vals := map[string]CaCertificateProvisioningState{ + "canceled": CaCertificateProvisioningStateCanceled, + "creating": CaCertificateProvisioningStateCreating, + "deleted": CaCertificateProvisioningStateDeleted, + "deleting": CaCertificateProvisioningStateDeleting, + "failed": CaCertificateProvisioningStateFailed, + "succeeded": CaCertificateProvisioningStateSucceeded, + "updating": CaCertificateProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CaCertificateProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_cacertificate.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_cacertificate.go new file mode 100644 index 00000000000..b3db1438a22 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_cacertificate.go @@ -0,0 +1,134 @@ +package cacertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CaCertificateId{} + +// CaCertificateId is a struct representing the Resource ID for a Ca Certificate +type CaCertificateId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + CaCertificateName string +} + +// NewCaCertificateID returns a new CaCertificateId struct +func NewCaCertificateID(subscriptionId string, resourceGroupName string, namespaceName string, caCertificateName string) CaCertificateId { + return CaCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + CaCertificateName: caCertificateName, + } +} + +// ParseCaCertificateID parses 'input' into a CaCertificateId +func ParseCaCertificateID(input string) (*CaCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CaCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CaCertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCaCertificateIDInsensitively parses 'input' case-insensitively into a CaCertificateId +// note: this method should only be used for API response data and not user input +func ParseCaCertificateIDInsensitively(input string) (*CaCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CaCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CaCertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CaCertificateId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.CaCertificateName, ok = input.Parsed["caCertificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "caCertificateName", input) + } + + return nil +} + +// ValidateCaCertificateID checks that 'input' can be parsed as a Ca Certificate ID +func ValidateCaCertificateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCaCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Ca Certificate ID +func (id CaCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/caCertificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.CaCertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Ca Certificate ID +func (id CaCertificateId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticCaCertificates", "caCertificates", "caCertificates"), + resourceids.UserSpecifiedSegment("caCertificateName", "caCertificateValue"), + } +} + +// String returns a human-readable description of this Ca Certificate ID +func (id CaCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Ca Certificate Name: %q", id.CaCertificateName), + } + return fmt.Sprintf("Ca Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_cacertificate_test.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_cacertificate_test.go new file mode 100644 index 00000000000..b4b118b5eb6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_cacertificate_test.go @@ -0,0 +1,327 @@ +package cacertificates + +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 = &CaCertificateId{} + +func TestNewCaCertificateID(t *testing.T) { + id := NewCaCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "caCertificateValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.CaCertificateName != "caCertificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CaCertificateName'", id.CaCertificateName, "caCertificateValue") + } +} + +func TestFormatCaCertificateID(t *testing.T) { + actual := NewCaCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "caCertificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/caCertificates/caCertificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCaCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CaCertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/caCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/caCertificates/caCertificateValue", + Expected: &CaCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + CaCertificateName: "caCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/caCertificates/caCertificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCaCertificateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.CaCertificateName != v.Expected.CaCertificateName { + t.Fatalf("Expected %q but got %q for CaCertificateName", v.Expected.CaCertificateName, actual.CaCertificateName) + } + + } +} + +func TestParseCaCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CaCertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/caCertificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cAcErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/caCertificates/caCertificateValue", + Expected: &CaCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + CaCertificateName: "caCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/caCertificates/caCertificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cAcErTiFiCaTeS/cAcErTiFiCaTeVaLuE", + Expected: &CaCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + CaCertificateName: "cAcErTiFiCaTeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cAcErTiFiCaTeS/cAcErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCaCertificateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.CaCertificateName != v.Expected.CaCertificateName { + t.Fatalf("Expected %q but got %q for CaCertificateName", v.Expected.CaCertificateName, actual.CaCertificateName) + } + + } +} + +func TestSegmentsForCaCertificateId(t *testing.T) { + segments := CaCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CaCertificateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_namespace.go new file mode 100644 index 00000000000..6d1d18b8e6a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_namespace.go @@ -0,0 +1,125 @@ +package cacertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceId{} + +// NamespaceId is a struct representing the Resource ID for a Namespace +type NamespaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string +} + +// NewNamespaceID returns a new NamespaceId struct +func NewNamespaceID(subscriptionId string, resourceGroupName string, namespaceName string) NamespaceId { + return NamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + } +} + +// ParseNamespaceID parses 'input' into a NamespaceId +func ParseNamespaceID(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceIDInsensitively parses 'input' case-insensitively into a NamespaceId +// note: this method should only be used for API response data and not user input +func ParseNamespaceIDInsensitively(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + return nil +} + +// ValidateNamespaceID checks that 'input' can be parsed as a Namespace ID +func ValidateNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace ID +func (id NamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace ID +func (id NamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + } +} + +// String returns a human-readable description of this Namespace ID +func (id NamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + } + return fmt.Sprintf("Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_namespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_namespace_test.go new file mode 100644 index 00000000000..6f11c830233 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/id_namespace_test.go @@ -0,0 +1,282 @@ +package cacertificates + +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 = &NamespaceId{} + +func TestNewNamespaceID(t *testing.T) { + id := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } +} + +func TestFormatNamespaceID(t *testing.T) { + actual := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestParseNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestSegmentsForNamespaceId(t *testing.T) { + segments := NamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_createorupdate.go new file mode 100644 index 00000000000..5c19ce77ec2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_createorupdate.go @@ -0,0 +1,75 @@ +package cacertificates + +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 *CaCertificate +} + +// CreateOrUpdate ... +func (c CaCertificatesClient) CreateOrUpdate(ctx context.Context, id CaCertificateId, input CaCertificate) (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 CaCertificatesClient) CreateOrUpdateThenPoll(ctx context.Context, id CaCertificateId, input CaCertificate) 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/eventgrid/2023-12-15-preview/cacertificates/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_delete.go new file mode 100644 index 00000000000..be92fda05b9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_delete.go @@ -0,0 +1,71 @@ +package cacertificates + +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 CaCertificatesClient) Delete(ctx context.Context, id CaCertificateId) (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 CaCertificatesClient) DeleteThenPoll(ctx context.Context, id CaCertificateId) 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/eventgrid/2023-12-15-preview/cacertificates/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_get.go new file mode 100644 index 00000000000..acea88723cf --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_get.go @@ -0,0 +1,54 @@ +package cacertificates + +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 *CaCertificate +} + +// Get ... +func (c CaCertificatesClient) Get(ctx context.Context, id CaCertificateId) (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 CaCertificate + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_listbynamespace.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_listbynamespace.go new file mode 100644 index 00000000000..fc8f30c252f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/method_listbynamespace.go @@ -0,0 +1,123 @@ +package cacertificates + +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 ListByNamespaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CaCertificate +} + +type ListByNamespaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []CaCertificate +} + +type ListByNamespaceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByNamespaceOperationOptions() ListByNamespaceOperationOptions { + return ListByNamespaceOperationOptions{} +} + +func (o ListByNamespaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByNamespaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByNamespaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByNamespace ... +func (c CaCertificatesClient) ListByNamespace(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (result ListByNamespaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/caCertificates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]CaCertificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNamespaceComplete retrieves all the results into a single object +func (c CaCertificatesClient) ListByNamespaceComplete(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (ListByNamespaceCompleteResult, error) { + return c.ListByNamespaceCompleteMatchingPredicate(ctx, id, options, CaCertificateOperationPredicate{}) +} + +// ListByNamespaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CaCertificatesClient) ListByNamespaceCompleteMatchingPredicate(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions, predicate CaCertificateOperationPredicate) (result ListByNamespaceCompleteResult, err error) { + items := make([]CaCertificate, 0) + + resp, err := c.ListByNamespace(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNamespaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/model_cacertificate.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/model_cacertificate.go new file mode 100644 index 00000000000..3bee43170b3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/model_cacertificate.go @@ -0,0 +1,16 @@ +package cacertificates + +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 CaCertificate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CaCertificateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/model_cacertificateproperties.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/model_cacertificateproperties.go new file mode 100644 index 00000000000..3225b91c9f8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/model_cacertificateproperties.go @@ -0,0 +1,42 @@ +package cacertificates + +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 CaCertificateProperties struct { + Description *string `json:"description,omitempty"` + EncodedCertificate *string `json:"encodedCertificate,omitempty"` + ExpiryTimeInUtc *string `json:"expiryTimeInUtc,omitempty"` + IssueTimeInUtc *string `json:"issueTimeInUtc,omitempty"` + ProvisioningState *CaCertificateProvisioningState `json:"provisioningState,omitempty"` +} + +func (o *CaCertificateProperties) GetExpiryTimeInUtcAsTime() (*time.Time, error) { + if o.ExpiryTimeInUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTimeInUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *CaCertificateProperties) SetExpiryTimeInUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTimeInUtc = &formatted +} + +func (o *CaCertificateProperties) GetIssueTimeInUtcAsTime() (*time.Time, error) { + if o.IssueTimeInUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.IssueTimeInUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *CaCertificateProperties) SetIssueTimeInUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.IssueTimeInUtc = &formatted +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/cacertificates/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/predicates.go new file mode 100644 index 00000000000..e73b7c0eb40 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/predicates.go @@ -0,0 +1,27 @@ +package cacertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CaCertificateOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CaCertificateOperationPredicate) Matches(input CaCertificate) 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/eventgrid/2023-12-15-preview/cacertificates/version.go b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/version.go new file mode 100644 index 00000000000..6ff32802947 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/cacertificates/version.go @@ -0,0 +1,12 @@ +package cacertificates + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/cacertificates/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/README.md b/resource-manager/eventgrid/2023-12-15-preview/channels/README.md new file mode 100644 index 00000000000..82f106d7593 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/README.md @@ -0,0 +1,123 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/channels` Documentation + +The `channels` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/channels" +``` + + +### Client Initialization + +```go +client := channels.NewChannelsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ChannelsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := channels.NewChannelID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue", "channelValue") + +payload := channels.Channel{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ChannelsClient.Delete` + +```go +ctx := context.TODO() +id := channels.NewChannelID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue", "channelValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ChannelsClient.Get` + +```go +ctx := context.TODO() +id := channels.NewChannelID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue", "channelValue") + +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: `ChannelsClient.GetFullUrl` + +```go +ctx := context.TODO() +id := channels.NewChannelID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue", "channelValue") + +read, err := client.GetFullUrl(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ChannelsClient.ListByPartnerNamespace` + +```go +ctx := context.TODO() +id := channels.NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + +// alternatively `client.ListByPartnerNamespace(ctx, id, channels.DefaultListByPartnerNamespaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByPartnerNamespaceComplete(ctx, id, channels.DefaultListByPartnerNamespaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ChannelsClient.Update` + +```go +ctx := context.TODO() +id := channels.NewChannelID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue", "channelValue") + +payload := channels.ChannelUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/client.go b/resource-manager/eventgrid/2023-12-15-preview/channels/client.go new file mode 100644 index 00000000000..c799cab7747 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/client.go @@ -0,0 +1,26 @@ +package channels + +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 ChannelsClient struct { + Client *resourcemanager.Client +} + +func NewChannelsClientWithBaseURI(sdkApi sdkEnv.Api) (*ChannelsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "channels", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ChannelsClient: %+v", err) + } + + return &ChannelsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/constants.go b/resource-manager/eventgrid/2023-12-15-preview/channels/constants.go new file mode 100644 index 00000000000..7eb691aa030 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/constants.go @@ -0,0 +1,265 @@ +package channels + +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 ChannelProvisioningState string + +const ( + ChannelProvisioningStateCanceled ChannelProvisioningState = "Canceled" + ChannelProvisioningStateCreating ChannelProvisioningState = "Creating" + ChannelProvisioningStateDeleting ChannelProvisioningState = "Deleting" + ChannelProvisioningStateFailed ChannelProvisioningState = "Failed" + ChannelProvisioningStateIdleDueToMirroredPartnerDestinationDeletion ChannelProvisioningState = "IdleDueToMirroredPartnerDestinationDeletion" + ChannelProvisioningStateIdleDueToMirroredPartnerTopicDeletion ChannelProvisioningState = "IdleDueToMirroredPartnerTopicDeletion" + ChannelProvisioningStateSucceeded ChannelProvisioningState = "Succeeded" + ChannelProvisioningStateUpdating ChannelProvisioningState = "Updating" +) + +func PossibleValuesForChannelProvisioningState() []string { + return []string{ + string(ChannelProvisioningStateCanceled), + string(ChannelProvisioningStateCreating), + string(ChannelProvisioningStateDeleting), + string(ChannelProvisioningStateFailed), + string(ChannelProvisioningStateIdleDueToMirroredPartnerDestinationDeletion), + string(ChannelProvisioningStateIdleDueToMirroredPartnerTopicDeletion), + string(ChannelProvisioningStateSucceeded), + string(ChannelProvisioningStateUpdating), + } +} + +func (s *ChannelProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseChannelProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseChannelProvisioningState(input string) (*ChannelProvisioningState, error) { + vals := map[string]ChannelProvisioningState{ + "canceled": ChannelProvisioningStateCanceled, + "creating": ChannelProvisioningStateCreating, + "deleting": ChannelProvisioningStateDeleting, + "failed": ChannelProvisioningStateFailed, + "idleduetomirroredpartnerdestinationdeletion": ChannelProvisioningStateIdleDueToMirroredPartnerDestinationDeletion, + "idleduetomirroredpartnertopicdeletion": ChannelProvisioningStateIdleDueToMirroredPartnerTopicDeletion, + "succeeded": ChannelProvisioningStateSucceeded, + "updating": ChannelProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ChannelProvisioningState(input) + return &out, nil +} + +type ChannelType string + +const ( + ChannelTypePartnerDestination ChannelType = "PartnerDestination" + ChannelTypePartnerTopic ChannelType = "PartnerTopic" +) + +func PossibleValuesForChannelType() []string { + return []string{ + string(ChannelTypePartnerDestination), + string(ChannelTypePartnerTopic), + } +} + +func (s *ChannelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseChannelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseChannelType(input string) (*ChannelType, error) { + vals := map[string]ChannelType{ + "partnerdestination": ChannelTypePartnerDestination, + "partnertopic": ChannelTypePartnerTopic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ChannelType(input) + return &out, nil +} + +type EventDefinitionKind string + +const ( + EventDefinitionKindInline EventDefinitionKind = "Inline" +) + +func PossibleValuesForEventDefinitionKind() []string { + return []string{ + string(EventDefinitionKindInline), + } +} + +func (s *EventDefinitionKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventDefinitionKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventDefinitionKind(input string) (*EventDefinitionKind, error) { + vals := map[string]EventDefinitionKind{ + "inline": EventDefinitionKindInline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventDefinitionKind(input) + return &out, nil +} + +type PartnerClientAuthenticationType string + +const ( + PartnerClientAuthenticationTypeAzureAD PartnerClientAuthenticationType = "AzureAD" +) + +func PossibleValuesForPartnerClientAuthenticationType() []string { + return []string{ + string(PartnerClientAuthenticationTypeAzureAD), + } +} + +func (s *PartnerClientAuthenticationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerClientAuthenticationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerClientAuthenticationType(input string) (*PartnerClientAuthenticationType, error) { + vals := map[string]PartnerClientAuthenticationType{ + "azuread": PartnerClientAuthenticationTypeAzureAD, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerClientAuthenticationType(input) + return &out, nil +} + +type PartnerEndpointType string + +const ( + PartnerEndpointTypeWebHook PartnerEndpointType = "WebHook" +) + +func PossibleValuesForPartnerEndpointType() []string { + return []string{ + string(PartnerEndpointTypeWebHook), + } +} + +func (s *PartnerEndpointType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerEndpointType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerEndpointType(input string) (*PartnerEndpointType, error) { + vals := map[string]PartnerEndpointType{ + "webhook": PartnerEndpointTypeWebHook, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerEndpointType(input) + return &out, nil +} + +type ReadinessState string + +const ( + ReadinessStateActivated ReadinessState = "Activated" + ReadinessStateNeverActivated ReadinessState = "NeverActivated" +) + +func PossibleValuesForReadinessState() []string { + return []string{ + string(ReadinessStateActivated), + string(ReadinessStateNeverActivated), + } +} + +func (s *ReadinessState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReadinessState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReadinessState(input string) (*ReadinessState, error) { + vals := map[string]ReadinessState{ + "activated": ReadinessStateActivated, + "neveractivated": ReadinessStateNeverActivated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReadinessState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/id_channel.go b/resource-manager/eventgrid/2023-12-15-preview/channels/id_channel.go new file mode 100644 index 00000000000..d48fb74380b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/id_channel.go @@ -0,0 +1,134 @@ +package channels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ChannelId{} + +// ChannelId is a struct representing the Resource ID for a Channel +type ChannelId struct { + SubscriptionId string + ResourceGroupName string + PartnerNamespaceName string + ChannelName string +} + +// NewChannelID returns a new ChannelId struct +func NewChannelID(subscriptionId string, resourceGroupName string, partnerNamespaceName string, channelName string) ChannelId { + return ChannelId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerNamespaceName: partnerNamespaceName, + ChannelName: channelName, + } +} + +// ParseChannelID parses 'input' into a ChannelId +func ParseChannelID(input string) (*ChannelId, error) { + parser := resourceids.NewParserFromResourceIdType(&ChannelId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ChannelId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseChannelIDInsensitively parses 'input' case-insensitively into a ChannelId +// note: this method should only be used for API response data and not user input +func ParseChannelIDInsensitively(input string) (*ChannelId, error) { + parser := resourceids.NewParserFromResourceIdType(&ChannelId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ChannelId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ChannelId) 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.PartnerNamespaceName, ok = input.Parsed["partnerNamespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerNamespaceName", input) + } + + if id.ChannelName, ok = input.Parsed["channelName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "channelName", input) + } + + return nil +} + +// ValidateChannelID checks that 'input' can be parsed as a Channel ID +func ValidateChannelID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseChannelID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Channel ID +func (id ChannelId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerNamespaces/%s/channels/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerNamespaceName, id.ChannelName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Channel ID +func (id ChannelId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerNamespaces", "partnerNamespaces", "partnerNamespaces"), + resourceids.UserSpecifiedSegment("partnerNamespaceName", "partnerNamespaceValue"), + resourceids.StaticSegment("staticChannels", "channels", "channels"), + resourceids.UserSpecifiedSegment("channelName", "channelValue"), + } +} + +// String returns a human-readable description of this Channel ID +func (id ChannelId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Namespace Name: %q", id.PartnerNamespaceName), + fmt.Sprintf("Channel Name: %q", id.ChannelName), + } + return fmt.Sprintf("Channel (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/id_channel_test.go b/resource-manager/eventgrid/2023-12-15-preview/channels/id_channel_test.go new file mode 100644 index 00000000000..0f12fce01ad --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/id_channel_test.go @@ -0,0 +1,327 @@ +package channels + +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 = &ChannelId{} + +func TestNewChannelID(t *testing.T) { + id := NewChannelID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue", "channelValue") + + if id.SubscriptionId != "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.PartnerNamespaceName != "partnerNamespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerNamespaceName'", id.PartnerNamespaceName, "partnerNamespaceValue") + } + + if id.ChannelName != "channelValue" { + t.Fatalf("Expected %q but got %q for Segment 'ChannelName'", id.ChannelName, "channelValue") + } +} + +func TestFormatChannelID(t *testing.T) { + actual := NewChannelID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue", "channelValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/channels/channelValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseChannelID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ChannelId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/channels", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/channels/channelValue", + Expected: &ChannelId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerNamespaceName: "partnerNamespaceValue", + ChannelName: "channelValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/channels/channelValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseChannelID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerNamespaceName != v.Expected.PartnerNamespaceName { + t.Fatalf("Expected %q but got %q for PartnerNamespaceName", v.Expected.PartnerNamespaceName, actual.PartnerNamespaceName) + } + + if actual.ChannelName != v.Expected.ChannelName { + t.Fatalf("Expected %q but got %q for ChannelName", v.Expected.ChannelName, actual.ChannelName) + } + + } +} + +func TestParseChannelIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ChannelId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/channels", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe/cHaNnElS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/channels/channelValue", + Expected: &ChannelId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerNamespaceName: "partnerNamespaceValue", + ChannelName: "channelValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/channels/channelValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe/cHaNnElS/cHaNnElVaLuE", + Expected: &ChannelId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerNamespaceName: "pArTnErNaMeSpAcEvAlUe", + ChannelName: "cHaNnElVaLuE", + }, + }, + { + // 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.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe/cHaNnElS/cHaNnElVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseChannelIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerNamespaceName != v.Expected.PartnerNamespaceName { + t.Fatalf("Expected %q but got %q for PartnerNamespaceName", v.Expected.PartnerNamespaceName, actual.PartnerNamespaceName) + } + + if actual.ChannelName != v.Expected.ChannelName { + t.Fatalf("Expected %q but got %q for ChannelName", v.Expected.ChannelName, actual.ChannelName) + } + + } +} + +func TestSegmentsForChannelId(t *testing.T) { + segments := ChannelId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ChannelId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/id_partnernamespace.go b/resource-manager/eventgrid/2023-12-15-preview/channels/id_partnernamespace.go new file mode 100644 index 00000000000..441d8a6a64d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/id_partnernamespace.go @@ -0,0 +1,125 @@ +package channels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PartnerNamespaceId{} + +// PartnerNamespaceId is a struct representing the Resource ID for a Partner Namespace +type PartnerNamespaceId struct { + SubscriptionId string + ResourceGroupName string + PartnerNamespaceName string +} + +// NewPartnerNamespaceID returns a new PartnerNamespaceId struct +func NewPartnerNamespaceID(subscriptionId string, resourceGroupName string, partnerNamespaceName string) PartnerNamespaceId { + return PartnerNamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerNamespaceName: partnerNamespaceName, + } +} + +// ParsePartnerNamespaceID parses 'input' into a PartnerNamespaceId +func ParsePartnerNamespaceID(input string) (*PartnerNamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerNamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerNamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePartnerNamespaceIDInsensitively parses 'input' case-insensitively into a PartnerNamespaceId +// note: this method should only be used for API response data and not user input +func ParsePartnerNamespaceIDInsensitively(input string) (*PartnerNamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerNamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerNamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PartnerNamespaceId) 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.PartnerNamespaceName, ok = input.Parsed["partnerNamespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerNamespaceName", input) + } + + return nil +} + +// ValidatePartnerNamespaceID checks that 'input' can be parsed as a Partner Namespace ID +func ValidatePartnerNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePartnerNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Partner Namespace ID +func (id PartnerNamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerNamespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerNamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Partner Namespace ID +func (id PartnerNamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerNamespaces", "partnerNamespaces", "partnerNamespaces"), + resourceids.UserSpecifiedSegment("partnerNamespaceName", "partnerNamespaceValue"), + } +} + +// String returns a human-readable description of this Partner Namespace ID +func (id PartnerNamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Namespace Name: %q", id.PartnerNamespaceName), + } + return fmt.Sprintf("Partner Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/id_partnernamespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/channels/id_partnernamespace_test.go new file mode 100644 index 00000000000..4bee1987f91 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/id_partnernamespace_test.go @@ -0,0 +1,282 @@ +package channels + +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 = &PartnerNamespaceId{} + +func TestNewPartnerNamespaceID(t *testing.T) { + id := NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + + if id.SubscriptionId != "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.PartnerNamespaceName != "partnerNamespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerNamespaceName'", id.PartnerNamespaceName, "partnerNamespaceValue") + } +} + +func TestFormatPartnerNamespaceID(t *testing.T) { + actual := NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePartnerNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerNamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue", + Expected: &PartnerNamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerNamespaceName: "partnerNamespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerNamespaceName != v.Expected.PartnerNamespaceName { + t.Fatalf("Expected %q but got %q for PartnerNamespaceName", v.Expected.PartnerNamespaceName, actual.PartnerNamespaceName) + } + + } +} + +func TestParsePartnerNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerNamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue", + Expected: &PartnerNamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerNamespaceName: "partnerNamespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe", + Expected: &PartnerNamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerNamespaceName: "pArTnErNaMeSpAcEvAlUe", + }, + }, + { + // 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.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerNamespaceName != v.Expected.PartnerNamespaceName { + t.Fatalf("Expected %q but got %q for PartnerNamespaceName", v.Expected.PartnerNamespaceName, actual.PartnerNamespaceName) + } + + } +} + +func TestSegmentsForPartnerNamespaceId(t *testing.T) { + segments := PartnerNamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PartnerNamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/channels/method_createorupdate.go new file mode 100644 index 00000000000..a4c40e77001 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/method_createorupdate.go @@ -0,0 +1,59 @@ +package channels + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Channel +} + +// CreateOrUpdate ... +func (c ChannelsClient) CreateOrUpdate(ctx context.Context, id ChannelId, input Channel) (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 + } + + var model Channel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/channels/method_delete.go new file mode 100644 index 00000000000..b2c716df2ac --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/method_delete.go @@ -0,0 +1,71 @@ +package channels + +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 ChannelsClient) Delete(ctx context.Context, id ChannelId) (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 ChannelsClient) DeleteThenPoll(ctx context.Context, id ChannelId) 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/eventgrid/2023-12-15-preview/channels/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/channels/method_get.go new file mode 100644 index 00000000000..eeb0504e931 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/method_get.go @@ -0,0 +1,54 @@ +package channels + +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 *Channel +} + +// Get ... +func (c ChannelsClient) Get(ctx context.Context, id ChannelId) (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 Channel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/method_getfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/channels/method_getfullurl.go new file mode 100644 index 00000000000..d720e485a8d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/method_getfullurl.go @@ -0,0 +1,55 @@ +package channels + +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 GetFullUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscriptionFullUrl +} + +// GetFullUrl ... +func (c ChannelsClient) GetFullUrl(ctx context.Context, id ChannelId) (result GetFullUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getFullUrl", 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 EventSubscriptionFullUrl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/method_listbypartnernamespace.go b/resource-manager/eventgrid/2023-12-15-preview/channels/method_listbypartnernamespace.go new file mode 100644 index 00000000000..9c4f935e1d9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/method_listbypartnernamespace.go @@ -0,0 +1,123 @@ +package channels + +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 ListByPartnerNamespaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Channel +} + +type ListByPartnerNamespaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []Channel +} + +type ListByPartnerNamespaceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByPartnerNamespaceOperationOptions() ListByPartnerNamespaceOperationOptions { + return ListByPartnerNamespaceOperationOptions{} +} + +func (o ListByPartnerNamespaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByPartnerNamespaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByPartnerNamespaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByPartnerNamespace ... +func (c ChannelsClient) ListByPartnerNamespace(ctx context.Context, id PartnerNamespaceId, options ListByPartnerNamespaceOperationOptions) (result ListByPartnerNamespaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/channels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Channel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByPartnerNamespaceComplete retrieves all the results into a single object +func (c ChannelsClient) ListByPartnerNamespaceComplete(ctx context.Context, id PartnerNamespaceId, options ListByPartnerNamespaceOperationOptions) (ListByPartnerNamespaceCompleteResult, error) { + return c.ListByPartnerNamespaceCompleteMatchingPredicate(ctx, id, options, ChannelOperationPredicate{}) +} + +// ListByPartnerNamespaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ChannelsClient) ListByPartnerNamespaceCompleteMatchingPredicate(ctx context.Context, id PartnerNamespaceId, options ListByPartnerNamespaceOperationOptions, predicate ChannelOperationPredicate) (result ListByPartnerNamespaceCompleteResult, err error) { + items := make([]Channel, 0) + + resp, err := c.ListByPartnerNamespace(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByPartnerNamespaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/channels/method_update.go new file mode 100644 index 00000000000..399a4d08960 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/method_update.go @@ -0,0 +1,50 @@ +package channels + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Update ... +func (c ChannelsClient) Update(ctx context.Context, id ChannelId, input ChannelUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_azureadpartnerclientauthentication.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_azureadpartnerclientauthentication.go new file mode 100644 index 00000000000..96a1c334d4b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_azureadpartnerclientauthentication.go @@ -0,0 +1,41 @@ +package channels + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ PartnerClientAuthentication = AzureADPartnerClientAuthentication{} + +type AzureADPartnerClientAuthentication struct { + Properties *AzureADPartnerClientAuthenticationProperties `json:"properties,omitempty"` + + // Fields inherited from PartnerClientAuthentication +} + +var _ json.Marshaler = AzureADPartnerClientAuthentication{} + +func (s AzureADPartnerClientAuthentication) MarshalJSON() ([]byte, error) { + type wrapper AzureADPartnerClientAuthentication + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureADPartnerClientAuthentication: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureADPartnerClientAuthentication: %+v", err) + } + decoded["clientAuthenticationType"] = "AzureAD" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureADPartnerClientAuthentication: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_azureadpartnerclientauthenticationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_azureadpartnerclientauthenticationproperties.go new file mode 100644 index 00000000000..37f3c587a61 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_azureadpartnerclientauthenticationproperties.go @@ -0,0 +1,9 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADPartnerClientAuthenticationProperties struct { + AzureActiveDirectoryApplicationIdOrUri *string `json:"azureActiveDirectoryApplicationIdOrUri,omitempty"` + AzureActiveDirectoryTenantId *string `json:"azureActiveDirectoryTenantId,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_channel.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channel.go new file mode 100644 index 00000000000..8e892556a55 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channel.go @@ -0,0 +1,16 @@ +package channels + +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 Channel struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ChannelProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelproperties.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelproperties.go new file mode 100644 index 00000000000..962ee6d3ee1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelproperties.go @@ -0,0 +1,65 @@ +package channels + +import ( + "encoding/json" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ChannelProperties struct { + ChannelType *ChannelType `json:"channelType,omitempty"` + ExpirationTimeIfNotActivatedUtc *string `json:"expirationTimeIfNotActivatedUtc,omitempty"` + MessageForActivation *string `json:"messageForActivation,omitempty"` + PartnerDestinationInfo PartnerDestinationInfo `json:"partnerDestinationInfo"` + PartnerTopicInfo *PartnerTopicInfo `json:"partnerTopicInfo,omitempty"` + ProvisioningState *ChannelProvisioningState `json:"provisioningState,omitempty"` + ReadinessState *ReadinessState `json:"readinessState,omitempty"` +} + +func (o *ChannelProperties) GetExpirationTimeIfNotActivatedUtcAsTime() (*time.Time, error) { + if o.ExpirationTimeIfNotActivatedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeIfNotActivatedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ChannelProperties) SetExpirationTimeIfNotActivatedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeIfNotActivatedUtc = &formatted +} + +var _ json.Unmarshaler = &ChannelProperties{} + +func (s *ChannelProperties) UnmarshalJSON(bytes []byte) error { + type alias ChannelProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ChannelProperties: %+v", err) + } + + s.ChannelType = decoded.ChannelType + s.ExpirationTimeIfNotActivatedUtc = decoded.ExpirationTimeIfNotActivatedUtc + s.MessageForActivation = decoded.MessageForActivation + s.PartnerTopicInfo = decoded.PartnerTopicInfo + s.ProvisioningState = decoded.ProvisioningState + s.ReadinessState = decoded.ReadinessState + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ChannelProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["partnerDestinationInfo"]; ok { + impl, err := unmarshalPartnerDestinationInfoImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'PartnerDestinationInfo' for 'ChannelProperties': %+v", err) + } + s.PartnerDestinationInfo = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelupdateparameters.go new file mode 100644 index 00000000000..68f744c5a24 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelupdateparameters.go @@ -0,0 +1,8 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ChannelUpdateParameters struct { + Properties *ChannelUpdateParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelupdateparametersproperties.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelupdateparametersproperties.go new file mode 100644 index 00000000000..b6685fea0c1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_channelupdateparametersproperties.go @@ -0,0 +1,57 @@ +package channels + +import ( + "encoding/json" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ChannelUpdateParametersProperties struct { + ExpirationTimeIfNotActivatedUtc *string `json:"expirationTimeIfNotActivatedUtc,omitempty"` + PartnerDestinationInfo PartnerUpdateDestinationInfo `json:"partnerDestinationInfo"` + PartnerTopicInfo *PartnerUpdateTopicInfo `json:"partnerTopicInfo,omitempty"` +} + +func (o *ChannelUpdateParametersProperties) GetExpirationTimeIfNotActivatedUtcAsTime() (*time.Time, error) { + if o.ExpirationTimeIfNotActivatedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeIfNotActivatedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ChannelUpdateParametersProperties) SetExpirationTimeIfNotActivatedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeIfNotActivatedUtc = &formatted +} + +var _ json.Unmarshaler = &ChannelUpdateParametersProperties{} + +func (s *ChannelUpdateParametersProperties) UnmarshalJSON(bytes []byte) error { + type alias ChannelUpdateParametersProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ChannelUpdateParametersProperties: %+v", err) + } + + s.ExpirationTimeIfNotActivatedUtc = decoded.ExpirationTimeIfNotActivatedUtc + s.PartnerTopicInfo = decoded.PartnerTopicInfo + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ChannelUpdateParametersProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["partnerDestinationInfo"]; ok { + impl, err := unmarshalPartnerUpdateDestinationInfoImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'PartnerDestinationInfo' for 'ChannelUpdateParametersProperties': %+v", err) + } + s.PartnerDestinationInfo = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_eventsubscriptionfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_eventsubscriptionfullurl.go new file mode 100644 index 00000000000..4c1178f2d13 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_eventsubscriptionfullurl.go @@ -0,0 +1,8 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventSubscriptionFullUrl struct { + EndpointUrl *string `json:"endpointUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_eventtypeinfo.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_eventtypeinfo.go new file mode 100644 index 00000000000..36b08224042 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_eventtypeinfo.go @@ -0,0 +1,9 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypeInfo struct { + InlineEventTypes *map[string]InlineEventProperties `json:"inlineEventTypes,omitempty"` + Kind *EventDefinitionKind `json:"kind,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_inlineeventproperties.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_inlineeventproperties.go new file mode 100644 index 00000000000..41e32688da0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_inlineeventproperties.go @@ -0,0 +1,11 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InlineEventProperties struct { + DataSchemaUrl *string `json:"dataSchemaUrl,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + DocumentationUrl *string `json:"documentationUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerclientauthentication.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerclientauthentication.go new file mode 100644 index 00000000000..6c50396b1bc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerclientauthentication.go @@ -0,0 +1,53 @@ +package channels + +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 PartnerClientAuthentication interface { +} + +// RawPartnerClientAuthenticationImpl 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 RawPartnerClientAuthenticationImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalPartnerClientAuthenticationImplementation(input []byte) (PartnerClientAuthentication, 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 PartnerClientAuthentication into map[string]interface: %+v", err) + } + + value, ok := temp["clientAuthenticationType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureAD") { + var out AzureADPartnerClientAuthentication + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureADPartnerClientAuthentication: %+v", err) + } + return out, nil + } + + out := RawPartnerClientAuthenticationImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerdestinationinfo.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerdestinationinfo.go new file mode 100644 index 00000000000..9632ff4309b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerdestinationinfo.go @@ -0,0 +1,53 @@ +package channels + +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 PartnerDestinationInfo interface { +} + +// RawPartnerDestinationInfoImpl 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 RawPartnerDestinationInfoImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalPartnerDestinationInfoImplementation(input []byte) (PartnerDestinationInfo, 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 PartnerDestinationInfo into map[string]interface: %+v", err) + } + + value, ok := temp["endpointType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "WebHook") { + var out WebhookPartnerDestinationInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into WebhookPartnerDestinationInfo: %+v", err) + } + return out, nil + } + + out := RawPartnerDestinationInfoImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnertopicinfo.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnertopicinfo.go new file mode 100644 index 00000000000..fd270adebe4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnertopicinfo.go @@ -0,0 +1,12 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerTopicInfo struct { + AzureSubscriptionId *string `json:"azureSubscriptionId,omitempty"` + EventTypeInfo *EventTypeInfo `json:"eventTypeInfo,omitempty"` + Name *string `json:"name,omitempty"` + ResourceGroupName *string `json:"resourceGroupName,omitempty"` + Source *string `json:"source,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerupdatedestinationinfo.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerupdatedestinationinfo.go new file mode 100644 index 00000000000..3b7e9562407 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerupdatedestinationinfo.go @@ -0,0 +1,53 @@ +package channels + +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 PartnerUpdateDestinationInfo interface { +} + +// RawPartnerUpdateDestinationInfoImpl 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 RawPartnerUpdateDestinationInfoImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalPartnerUpdateDestinationInfoImplementation(input []byte) (PartnerUpdateDestinationInfo, 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 PartnerUpdateDestinationInfo into map[string]interface: %+v", err) + } + + value, ok := temp["endpointType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "WebHook") { + var out WebhookUpdatePartnerDestinationInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into WebhookUpdatePartnerDestinationInfo: %+v", err) + } + return out, nil + } + + out := RawPartnerUpdateDestinationInfoImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerupdatetopicinfo.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerupdatetopicinfo.go new file mode 100644 index 00000000000..68226ed7956 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_partnerupdatetopicinfo.go @@ -0,0 +1,8 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerUpdateTopicInfo struct { + EventTypeInfo *EventTypeInfo `json:"eventTypeInfo,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_resourcemovechangehistory.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_resourcemovechangehistory.go new file mode 100644 index 00000000000..cdb35b7408f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_resourcemovechangehistory.go @@ -0,0 +1,28 @@ +package channels + +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 ResourceMoveChangeHistory struct { + AzureSubscriptionId *string `json:"azureSubscriptionId,omitempty"` + ChangedTimeUtc *string `json:"changedTimeUtc,omitempty"` + ResourceGroupName *string `json:"resourceGroupName,omitempty"` +} + +func (o *ResourceMoveChangeHistory) GetChangedTimeUtcAsTime() (*time.Time, error) { + if o.ChangedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ChangedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ResourceMoveChangeHistory) SetChangedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ChangedTimeUtc = &formatted +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookpartnerdestinationinfo.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookpartnerdestinationinfo.go new file mode 100644 index 00000000000..2c4c534a76b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookpartnerdestinationinfo.go @@ -0,0 +1,46 @@ +package channels + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ PartnerDestinationInfo = WebhookPartnerDestinationInfo{} + +type WebhookPartnerDestinationInfo struct { + Properties *WebhookPartnerDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from PartnerDestinationInfo + AzureSubscriptionId *string `json:"azureSubscriptionId,omitempty"` + EndpointServiceContext *string `json:"endpointServiceContext,omitempty"` + Name *string `json:"name,omitempty"` + ResourceGroupName *string `json:"resourceGroupName,omitempty"` + ResourceMoveChangeHistory *[]ResourceMoveChangeHistory `json:"resourceMoveChangeHistory,omitempty"` +} + +var _ json.Marshaler = WebhookPartnerDestinationInfo{} + +func (s WebhookPartnerDestinationInfo) MarshalJSON() ([]byte, error) { + type wrapper WebhookPartnerDestinationInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling WebhookPartnerDestinationInfo: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling WebhookPartnerDestinationInfo: %+v", err) + } + decoded["endpointType"] = "WebHook" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling WebhookPartnerDestinationInfo: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookpartnerdestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookpartnerdestinationproperties.go new file mode 100644 index 00000000000..4c62df5380a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookpartnerdestinationproperties.go @@ -0,0 +1,42 @@ +package channels + +import ( + "encoding/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 WebhookPartnerDestinationProperties struct { + ClientAuthentication PartnerClientAuthentication `json:"clientAuthentication"` + EndpointBaseUrl *string `json:"endpointBaseUrl,omitempty"` + EndpointUrl *string `json:"endpointUrl,omitempty"` +} + +var _ json.Unmarshaler = &WebhookPartnerDestinationProperties{} + +func (s *WebhookPartnerDestinationProperties) UnmarshalJSON(bytes []byte) error { + type alias WebhookPartnerDestinationProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into WebhookPartnerDestinationProperties: %+v", err) + } + + s.EndpointBaseUrl = decoded.EndpointBaseUrl + s.EndpointUrl = decoded.EndpointUrl + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling WebhookPartnerDestinationProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["clientAuthentication"]; ok { + impl, err := unmarshalPartnerClientAuthenticationImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ClientAuthentication' for 'WebhookPartnerDestinationProperties': %+v", err) + } + s.ClientAuthentication = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookupdatepartnerdestinationinfo.go b/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookupdatepartnerdestinationinfo.go new file mode 100644 index 00000000000..2ec9b0b765f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/model_webhookupdatepartnerdestinationinfo.go @@ -0,0 +1,41 @@ +package channels + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ PartnerUpdateDestinationInfo = WebhookUpdatePartnerDestinationInfo{} + +type WebhookUpdatePartnerDestinationInfo struct { + Properties *WebhookPartnerDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from PartnerUpdateDestinationInfo +} + +var _ json.Marshaler = WebhookUpdatePartnerDestinationInfo{} + +func (s WebhookUpdatePartnerDestinationInfo) MarshalJSON() ([]byte, error) { + type wrapper WebhookUpdatePartnerDestinationInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling WebhookUpdatePartnerDestinationInfo: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling WebhookUpdatePartnerDestinationInfo: %+v", err) + } + decoded["endpointType"] = "WebHook" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling WebhookUpdatePartnerDestinationInfo: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/channels/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/channels/predicates.go new file mode 100644 index 00000000000..4fe41cded7f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/predicates.go @@ -0,0 +1,27 @@ +package channels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ChannelOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ChannelOperationPredicate) Matches(input Channel) 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/eventgrid/2023-12-15-preview/channels/version.go b/resource-manager/eventgrid/2023-12-15-preview/channels/version.go new file mode 100644 index 00000000000..eed41055d88 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/channels/version.go @@ -0,0 +1,12 @@ +package channels + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/channels/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/client.go b/resource-manager/eventgrid/2023-12-15-preview/client.go new file mode 100644 index 00000000000..e61746a4102 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/client.go @@ -0,0 +1,226 @@ +package v2023_12_15_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/eventgrid/2023-12-15-preview/cacertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/channels" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/clientgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/clients" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/domains" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/domaintopics" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/namespaces" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/namespacetopics" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnertopics" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/permissionbindings" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/systemtopics" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/topics" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/topicspaces" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/topictypes" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + CaCertificates *cacertificates.CaCertificatesClient + Channels *channels.ChannelsClient + ClientGroups *clientgroups.ClientGroupsClient + Clients *clients.ClientsClient + DomainTopics *domaintopics.DomainTopicsClient + Domains *domains.DomainsClient + EventSubscriptions *eventsubscriptions.EventSubscriptionsClient + NamespaceTopics *namespacetopics.NamespaceTopicsClient + Namespaces *namespaces.NamespacesClient + PartnerConfigurations *partnerconfigurations.PartnerConfigurationsClient + PartnerDestinations *partnerdestinations.PartnerDestinationsClient + PartnerNamespaces *partnernamespaces.PartnerNamespacesClient + PartnerRegistrations *partnerregistrations.PartnerRegistrationsClient + PartnerTopics *partnertopics.PartnerTopicsClient + PerimeterAssociationProxies *perimeterassociationproxies.PerimeterAssociationProxiesClient + PermissionBindings *permissionbindings.PermissionBindingsClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + SystemTopics *systemtopics.SystemTopicsClient + TopicSpaces *topicspaces.TopicSpacesClient + TopicTypes *topictypes.TopicTypesClient + Topics *topics.TopicsClient + VerifiedPartners *verifiedpartners.VerifiedPartnersClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + caCertificatesClient, err := cacertificates.NewCaCertificatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CaCertificates client: %+v", err) + } + configureFunc(caCertificatesClient.Client) + + channelsClient, err := channels.NewChannelsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Channels client: %+v", err) + } + configureFunc(channelsClient.Client) + + clientGroupsClient, err := clientgroups.NewClientGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ClientGroups client: %+v", err) + } + configureFunc(clientGroupsClient.Client) + + clientsClient, err := clients.NewClientsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Clients client: %+v", err) + } + configureFunc(clientsClient.Client) + + domainTopicsClient, err := domaintopics.NewDomainTopicsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DomainTopics client: %+v", err) + } + configureFunc(domainTopicsClient.Client) + + domainsClient, err := domains.NewDomainsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Domains client: %+v", err) + } + configureFunc(domainsClient.Client) + + eventSubscriptionsClient, err := eventsubscriptions.NewEventSubscriptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EventSubscriptions client: %+v", err) + } + configureFunc(eventSubscriptionsClient.Client) + + namespaceTopicsClient, err := namespacetopics.NewNamespaceTopicsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NamespaceTopics client: %+v", err) + } + configureFunc(namespaceTopicsClient.Client) + + namespacesClient, err := namespaces.NewNamespacesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Namespaces client: %+v", err) + } + configureFunc(namespacesClient.Client) + + partnerConfigurationsClient, err := partnerconfigurations.NewPartnerConfigurationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PartnerConfigurations client: %+v", err) + } + configureFunc(partnerConfigurationsClient.Client) + + partnerDestinationsClient, err := partnerdestinations.NewPartnerDestinationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PartnerDestinations client: %+v", err) + } + configureFunc(partnerDestinationsClient.Client) + + partnerNamespacesClient, err := partnernamespaces.NewPartnerNamespacesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PartnerNamespaces client: %+v", err) + } + configureFunc(partnerNamespacesClient.Client) + + partnerRegistrationsClient, err := partnerregistrations.NewPartnerRegistrationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PartnerRegistrations client: %+v", err) + } + configureFunc(partnerRegistrationsClient.Client) + + partnerTopicsClient, err := partnertopics.NewPartnerTopicsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PartnerTopics client: %+v", err) + } + configureFunc(partnerTopicsClient.Client) + + perimeterAssociationProxiesClient, err := perimeterassociationproxies.NewPerimeterAssociationProxiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PerimeterAssociationProxies client: %+v", err) + } + configureFunc(perimeterAssociationProxiesClient.Client) + + permissionBindingsClient, err := permissionbindings.NewPermissionBindingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PermissionBindings client: %+v", err) + } + configureFunc(permissionBindingsClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + systemTopicsClient, err := systemtopics.NewSystemTopicsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SystemTopics client: %+v", err) + } + configureFunc(systemTopicsClient.Client) + + topicSpacesClient, err := topicspaces.NewTopicSpacesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TopicSpaces client: %+v", err) + } + configureFunc(topicSpacesClient.Client) + + topicTypesClient, err := topictypes.NewTopicTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TopicTypes client: %+v", err) + } + configureFunc(topicTypesClient.Client) + + topicsClient, err := topics.NewTopicsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Topics client: %+v", err) + } + configureFunc(topicsClient.Client) + + verifiedPartnersClient, err := verifiedpartners.NewVerifiedPartnersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building VerifiedPartners client: %+v", err) + } + configureFunc(verifiedPartnersClient.Client) + + return &Client{ + CaCertificates: caCertificatesClient, + Channels: channelsClient, + ClientGroups: clientGroupsClient, + Clients: clientsClient, + DomainTopics: domainTopicsClient, + Domains: domainsClient, + EventSubscriptions: eventSubscriptionsClient, + NamespaceTopics: namespaceTopicsClient, + Namespaces: namespacesClient, + PartnerConfigurations: partnerConfigurationsClient, + PartnerDestinations: partnerDestinationsClient, + PartnerNamespaces: partnerNamespacesClient, + PartnerRegistrations: partnerRegistrationsClient, + PartnerTopics: partnerTopicsClient, + PerimeterAssociationProxies: perimeterAssociationProxiesClient, + PermissionBindings: permissionBindingsClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + SystemTopics: systemTopicsClient, + TopicSpaces: topicSpacesClient, + TopicTypes: topicTypesClient, + Topics: topicsClient, + VerifiedPartners: verifiedPartnersClient, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/README.md b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/README.md new file mode 100644 index 00000000000..ae5bc174dbe --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/clientgroups` Documentation + +The `clientgroups` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/clientgroups" +``` + + +### Client Initialization + +```go +client := clientgroups.NewClientGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ClientGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := clientgroups.NewClientGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientGroupValue") + +payload := clientgroups.ClientGroup{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClientGroupsClient.Delete` + +```go +ctx := context.TODO() +id := clientgroups.NewClientGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientGroupValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClientGroupsClient.Get` + +```go +ctx := context.TODO() +id := clientgroups.NewClientGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientGroupValue") + +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: `ClientGroupsClient.ListByNamespace` + +```go +ctx := context.TODO() +id := clientgroups.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +// alternatively `client.ListByNamespace(ctx, id, clientgroups.DefaultListByNamespaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByNamespaceComplete(ctx, id, clientgroups.DefaultListByNamespaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/client.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/client.go new file mode 100644 index 00000000000..4fbbdcdf5f6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/client.go @@ -0,0 +1,26 @@ +package clientgroups + +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 ClientGroupsClient struct { + Client *resourcemanager.Client +} + +func NewClientGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*ClientGroupsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "clientgroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ClientGroupsClient: %+v", err) + } + + return &ClientGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/constants.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/constants.go new file mode 100644 index 00000000000..b17a0215bb1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/constants.go @@ -0,0 +1,66 @@ +package clientgroups + +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 ClientGroupProvisioningState string + +const ( + ClientGroupProvisioningStateCanceled ClientGroupProvisioningState = "Canceled" + ClientGroupProvisioningStateCreating ClientGroupProvisioningState = "Creating" + ClientGroupProvisioningStateDeleted ClientGroupProvisioningState = "Deleted" + ClientGroupProvisioningStateDeleting ClientGroupProvisioningState = "Deleting" + ClientGroupProvisioningStateFailed ClientGroupProvisioningState = "Failed" + ClientGroupProvisioningStateSucceeded ClientGroupProvisioningState = "Succeeded" + ClientGroupProvisioningStateUpdating ClientGroupProvisioningState = "Updating" +) + +func PossibleValuesForClientGroupProvisioningState() []string { + return []string{ + string(ClientGroupProvisioningStateCanceled), + string(ClientGroupProvisioningStateCreating), + string(ClientGroupProvisioningStateDeleted), + string(ClientGroupProvisioningStateDeleting), + string(ClientGroupProvisioningStateFailed), + string(ClientGroupProvisioningStateSucceeded), + string(ClientGroupProvisioningStateUpdating), + } +} + +func (s *ClientGroupProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientGroupProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientGroupProvisioningState(input string) (*ClientGroupProvisioningState, error) { + vals := map[string]ClientGroupProvisioningState{ + "canceled": ClientGroupProvisioningStateCanceled, + "creating": ClientGroupProvisioningStateCreating, + "deleted": ClientGroupProvisioningStateDeleted, + "deleting": ClientGroupProvisioningStateDeleting, + "failed": ClientGroupProvisioningStateFailed, + "succeeded": ClientGroupProvisioningStateSucceeded, + "updating": ClientGroupProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientGroupProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_clientgroup.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_clientgroup.go new file mode 100644 index 00000000000..f72eef21ab3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_clientgroup.go @@ -0,0 +1,134 @@ +package clientgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ClientGroupId{} + +// ClientGroupId is a struct representing the Resource ID for a Client Group +type ClientGroupId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + ClientGroupName string +} + +// NewClientGroupID returns a new ClientGroupId struct +func NewClientGroupID(subscriptionId string, resourceGroupName string, namespaceName string, clientGroupName string) ClientGroupId { + return ClientGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + ClientGroupName: clientGroupName, + } +} + +// ParseClientGroupID parses 'input' into a ClientGroupId +func ParseClientGroupID(input string) (*ClientGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClientGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClientGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClientGroupIDInsensitively parses 'input' case-insensitively into a ClientGroupId +// note: this method should only be used for API response data and not user input +func ParseClientGroupIDInsensitively(input string) (*ClientGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClientGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClientGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClientGroupId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.ClientGroupName, ok = input.Parsed["clientGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clientGroupName", input) + } + + return nil +} + +// ValidateClientGroupID checks that 'input' can be parsed as a Client Group ID +func ValidateClientGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseClientGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Client Group ID +func (id ClientGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/clientGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.ClientGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Client Group ID +func (id ClientGroupId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticClientGroups", "clientGroups", "clientGroups"), + resourceids.UserSpecifiedSegment("clientGroupName", "clientGroupValue"), + } +} + +// String returns a human-readable description of this Client Group ID +func (id ClientGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Client Group Name: %q", id.ClientGroupName), + } + return fmt.Sprintf("Client Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_clientgroup_test.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_clientgroup_test.go new file mode 100644 index 00000000000..c3494a96c79 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_clientgroup_test.go @@ -0,0 +1,327 @@ +package clientgroups + +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 = &ClientGroupId{} + +func TestNewClientGroupID(t *testing.T) { + id := NewClientGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientGroupValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.ClientGroupName != "clientGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClientGroupName'", id.ClientGroupName, "clientGroupValue") + } +} + +func TestFormatClientGroupID(t *testing.T) { + actual := NewClientGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clientGroups/clientGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClientGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClientGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clientGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clientGroups/clientGroupValue", + Expected: &ClientGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + ClientGroupName: "clientGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clientGroups/clientGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClientGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.ClientGroupName != v.Expected.ClientGroupName { + t.Fatalf("Expected %q but got %q for ClientGroupName", v.Expected.ClientGroupName, actual.ClientGroupName) + } + + } +} + +func TestParseClientGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClientGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clientGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cLiEnTgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clientGroups/clientGroupValue", + Expected: &ClientGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + ClientGroupName: "clientGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clientGroups/clientGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cLiEnTgRoUpS/cLiEnTgRoUpVaLuE", + Expected: &ClientGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + ClientGroupName: "cLiEnTgRoUpVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cLiEnTgRoUpS/cLiEnTgRoUpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClientGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.ClientGroupName != v.Expected.ClientGroupName { + t.Fatalf("Expected %q but got %q for ClientGroupName", v.Expected.ClientGroupName, actual.ClientGroupName) + } + + } +} + +func TestSegmentsForClientGroupId(t *testing.T) { + segments := ClientGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClientGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_namespace.go new file mode 100644 index 00000000000..6b4ae8155e7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_namespace.go @@ -0,0 +1,125 @@ +package clientgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceId{} + +// NamespaceId is a struct representing the Resource ID for a Namespace +type NamespaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string +} + +// NewNamespaceID returns a new NamespaceId struct +func NewNamespaceID(subscriptionId string, resourceGroupName string, namespaceName string) NamespaceId { + return NamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + } +} + +// ParseNamespaceID parses 'input' into a NamespaceId +func ParseNamespaceID(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceIDInsensitively parses 'input' case-insensitively into a NamespaceId +// note: this method should only be used for API response data and not user input +func ParseNamespaceIDInsensitively(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + return nil +} + +// ValidateNamespaceID checks that 'input' can be parsed as a Namespace ID +func ValidateNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace ID +func (id NamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace ID +func (id NamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + } +} + +// String returns a human-readable description of this Namespace ID +func (id NamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + } + return fmt.Sprintf("Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_namespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_namespace_test.go new file mode 100644 index 00000000000..b76c6be4479 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/id_namespace_test.go @@ -0,0 +1,282 @@ +package clientgroups + +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 = &NamespaceId{} + +func TestNewNamespaceID(t *testing.T) { + id := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } +} + +func TestFormatNamespaceID(t *testing.T) { + actual := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestParseNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestSegmentsForNamespaceId(t *testing.T) { + segments := NamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_createorupdate.go new file mode 100644 index 00000000000..cc576e1cc6f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_createorupdate.go @@ -0,0 +1,75 @@ +package clientgroups + +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 *ClientGroup +} + +// CreateOrUpdate ... +func (c ClientGroupsClient) CreateOrUpdate(ctx context.Context, id ClientGroupId, input ClientGroup) (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 ClientGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id ClientGroupId, input ClientGroup) 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/eventgrid/2023-12-15-preview/clientgroups/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_delete.go new file mode 100644 index 00000000000..a1ed20cfa0c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_delete.go @@ -0,0 +1,71 @@ +package clientgroups + +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 ClientGroupsClient) Delete(ctx context.Context, id ClientGroupId) (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 ClientGroupsClient) DeleteThenPoll(ctx context.Context, id ClientGroupId) 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/eventgrid/2023-12-15-preview/clientgroups/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_get.go new file mode 100644 index 00000000000..5982ad4e269 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_get.go @@ -0,0 +1,54 @@ +package clientgroups + +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 *ClientGroup +} + +// Get ... +func (c ClientGroupsClient) Get(ctx context.Context, id ClientGroupId) (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 ClientGroup + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_listbynamespace.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_listbynamespace.go new file mode 100644 index 00000000000..f152b3061f4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/method_listbynamespace.go @@ -0,0 +1,123 @@ +package clientgroups + +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 ListByNamespaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ClientGroup +} + +type ListByNamespaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ClientGroup +} + +type ListByNamespaceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByNamespaceOperationOptions() ListByNamespaceOperationOptions { + return ListByNamespaceOperationOptions{} +} + +func (o ListByNamespaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByNamespaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByNamespaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByNamespace ... +func (c ClientGroupsClient) ListByNamespace(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (result ListByNamespaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/clientGroups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ClientGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNamespaceComplete retrieves all the results into a single object +func (c ClientGroupsClient) ListByNamespaceComplete(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (ListByNamespaceCompleteResult, error) { + return c.ListByNamespaceCompleteMatchingPredicate(ctx, id, options, ClientGroupOperationPredicate{}) +} + +// ListByNamespaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClientGroupsClient) ListByNamespaceCompleteMatchingPredicate(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions, predicate ClientGroupOperationPredicate) (result ListByNamespaceCompleteResult, err error) { + items := make([]ClientGroup, 0) + + resp, err := c.ListByNamespace(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNamespaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/model_clientgroup.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/model_clientgroup.go new file mode 100644 index 00000000000..6b6c67df9c3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/model_clientgroup.go @@ -0,0 +1,16 @@ +package clientgroups + +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 ClientGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ClientGroupProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/model_clientgroupproperties.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/model_clientgroupproperties.go new file mode 100644 index 00000000000..bdbc9f50281 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/model_clientgroupproperties.go @@ -0,0 +1,10 @@ +package clientgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientGroupProperties struct { + Description *string `json:"description,omitempty"` + ProvisioningState *ClientGroupProvisioningState `json:"provisioningState,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clientgroups/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/predicates.go new file mode 100644 index 00000000000..71e85e69328 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/predicates.go @@ -0,0 +1,27 @@ +package clientgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ClientGroupOperationPredicate) Matches(input ClientGroup) 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/eventgrid/2023-12-15-preview/clientgroups/version.go b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/version.go new file mode 100644 index 00000000000..991f19507a6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clientgroups/version.go @@ -0,0 +1,12 @@ +package clientgroups + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/clientgroups/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/README.md b/resource-manager/eventgrid/2023-12-15-preview/clients/README.md new file mode 100644 index 00000000000..dbd14afcae4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/clients` Documentation + +The `clients` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/clients" +``` + + +### Client Initialization + +```go +client := clients.NewClientsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ClientsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := clients.NewClientID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientValue") + +payload := clients.Client{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClientsClient.Delete` + +```go +ctx := context.TODO() +id := clients.NewClientID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClientsClient.Get` + +```go +ctx := context.TODO() +id := clients.NewClientID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientValue") + +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: `ClientsClient.ListByNamespace` + +```go +ctx := context.TODO() +id := clients.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +// alternatively `client.ListByNamespace(ctx, id, clients.DefaultListByNamespaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByNamespaceComplete(ctx, id, clients.DefaultListByNamespaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/client.go b/resource-manager/eventgrid/2023-12-15-preview/clients/client.go new file mode 100644 index 00000000000..758bc008017 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/client.go @@ -0,0 +1,26 @@ +package clients + +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 ClientsClient struct { + Client *resourcemanager.Client +} + +func NewClientsClientWithBaseURI(sdkApi sdkEnv.Api) (*ClientsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "clients", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ClientsClient: %+v", err) + } + + return &ClientsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/constants.go b/resource-manager/eventgrid/2023-12-15-preview/clients/constants.go new file mode 100644 index 00000000000..aea697119f6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/constants.go @@ -0,0 +1,160 @@ +package clients + +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 ClientCertificateValidationScheme string + +const ( + ClientCertificateValidationSchemeDnsMatchesAuthenticationName ClientCertificateValidationScheme = "DnsMatchesAuthenticationName" + ClientCertificateValidationSchemeEmailMatchesAuthenticationName ClientCertificateValidationScheme = "EmailMatchesAuthenticationName" + ClientCertificateValidationSchemeIPMatchesAuthenticationName ClientCertificateValidationScheme = "IpMatchesAuthenticationName" + ClientCertificateValidationSchemeSubjectMatchesAuthenticationName ClientCertificateValidationScheme = "SubjectMatchesAuthenticationName" + ClientCertificateValidationSchemeThumbprintMatch ClientCertificateValidationScheme = "ThumbprintMatch" + ClientCertificateValidationSchemeUriMatchesAuthenticationName ClientCertificateValidationScheme = "UriMatchesAuthenticationName" +) + +func PossibleValuesForClientCertificateValidationScheme() []string { + return []string{ + string(ClientCertificateValidationSchemeDnsMatchesAuthenticationName), + string(ClientCertificateValidationSchemeEmailMatchesAuthenticationName), + string(ClientCertificateValidationSchemeIPMatchesAuthenticationName), + string(ClientCertificateValidationSchemeSubjectMatchesAuthenticationName), + string(ClientCertificateValidationSchemeThumbprintMatch), + string(ClientCertificateValidationSchemeUriMatchesAuthenticationName), + } +} + +func (s *ClientCertificateValidationScheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientCertificateValidationScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientCertificateValidationScheme(input string) (*ClientCertificateValidationScheme, error) { + vals := map[string]ClientCertificateValidationScheme{ + "dnsmatchesauthenticationname": ClientCertificateValidationSchemeDnsMatchesAuthenticationName, + "emailmatchesauthenticationname": ClientCertificateValidationSchemeEmailMatchesAuthenticationName, + "ipmatchesauthenticationname": ClientCertificateValidationSchemeIPMatchesAuthenticationName, + "subjectmatchesauthenticationname": ClientCertificateValidationSchemeSubjectMatchesAuthenticationName, + "thumbprintmatch": ClientCertificateValidationSchemeThumbprintMatch, + "urimatchesauthenticationname": ClientCertificateValidationSchemeUriMatchesAuthenticationName, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientCertificateValidationScheme(input) + return &out, nil +} + +type ClientProvisioningState string + +const ( + ClientProvisioningStateCanceled ClientProvisioningState = "Canceled" + ClientProvisioningStateCreating ClientProvisioningState = "Creating" + ClientProvisioningStateDeleted ClientProvisioningState = "Deleted" + ClientProvisioningStateDeleting ClientProvisioningState = "Deleting" + ClientProvisioningStateFailed ClientProvisioningState = "Failed" + ClientProvisioningStateSucceeded ClientProvisioningState = "Succeeded" + ClientProvisioningStateUpdating ClientProvisioningState = "Updating" +) + +func PossibleValuesForClientProvisioningState() []string { + return []string{ + string(ClientProvisioningStateCanceled), + string(ClientProvisioningStateCreating), + string(ClientProvisioningStateDeleted), + string(ClientProvisioningStateDeleting), + string(ClientProvisioningStateFailed), + string(ClientProvisioningStateSucceeded), + string(ClientProvisioningStateUpdating), + } +} + +func (s *ClientProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientProvisioningState(input string) (*ClientProvisioningState, error) { + vals := map[string]ClientProvisioningState{ + "canceled": ClientProvisioningStateCanceled, + "creating": ClientProvisioningStateCreating, + "deleted": ClientProvisioningStateDeleted, + "deleting": ClientProvisioningStateDeleting, + "failed": ClientProvisioningStateFailed, + "succeeded": ClientProvisioningStateSucceeded, + "updating": ClientProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientProvisioningState(input) + return &out, nil +} + +type ClientState string + +const ( + ClientStateDisabled ClientState = "Disabled" + ClientStateEnabled ClientState = "Enabled" +) + +func PossibleValuesForClientState() []string { + return []string{ + string(ClientStateDisabled), + string(ClientStateEnabled), + } +} + +func (s *ClientState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientState(input string) (*ClientState, error) { + vals := map[string]ClientState{ + "disabled": ClientStateDisabled, + "enabled": ClientStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/id_client.go b/resource-manager/eventgrid/2023-12-15-preview/clients/id_client.go new file mode 100644 index 00000000000..3344aa0565d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/id_client.go @@ -0,0 +1,134 @@ +package clients + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ClientId{} + +// ClientId is a struct representing the Resource ID for a Client +type ClientId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + ClientName string +} + +// NewClientID returns a new ClientId struct +func NewClientID(subscriptionId string, resourceGroupName string, namespaceName string, clientName string) ClientId { + return ClientId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + ClientName: clientName, + } +} + +// ParseClientID parses 'input' into a ClientId +func ParseClientID(input string) (*ClientId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClientId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClientId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseClientIDInsensitively parses 'input' case-insensitively into a ClientId +// note: this method should only be used for API response data and not user input +func ParseClientIDInsensitively(input string) (*ClientId, error) { + parser := resourceids.NewParserFromResourceIdType(&ClientId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ClientId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ClientId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.ClientName, ok = input.Parsed["clientName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "clientName", input) + } + + return nil +} + +// ValidateClientID checks that 'input' can be parsed as a Client ID +func ValidateClientID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseClientID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Client ID +func (id ClientId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/clients/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.ClientName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Client ID +func (id ClientId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticClients", "clients", "clients"), + resourceids.UserSpecifiedSegment("clientName", "clientValue"), + } +} + +// String returns a human-readable description of this Client ID +func (id ClientId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Client Name: %q", id.ClientName), + } + return fmt.Sprintf("Client (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/id_client_test.go b/resource-manager/eventgrid/2023-12-15-preview/clients/id_client_test.go new file mode 100644 index 00000000000..dc4fa575e73 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/id_client_test.go @@ -0,0 +1,327 @@ +package clients + +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 = &ClientId{} + +func TestNewClientID(t *testing.T) { + id := NewClientID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.ClientName != "clientValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClientName'", id.ClientName, "clientValue") + } +} + +func TestFormatClientID(t *testing.T) { + actual := NewClientID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "clientValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clients/clientValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseClientID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClientId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clients", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clients/clientValue", + Expected: &ClientId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + ClientName: "clientValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clients/clientValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClientID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.ClientName != v.Expected.ClientName { + t.Fatalf("Expected %q but got %q for ClientName", v.Expected.ClientName, actual.ClientName) + } + + } +} + +func TestParseClientIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ClientId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clients", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cLiEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clients/clientValue", + Expected: &ClientId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + ClientName: "clientValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/clients/clientValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cLiEnTs/cLiEnTvAlUe", + Expected: &ClientId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + ClientName: "cLiEnTvAlUe", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/cLiEnTs/cLiEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseClientIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.ClientName != v.Expected.ClientName { + t.Fatalf("Expected %q but got %q for ClientName", v.Expected.ClientName, actual.ClientName) + } + + } +} + +func TestSegmentsForClientId(t *testing.T) { + segments := ClientId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ClientId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/id_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/clients/id_namespace.go new file mode 100644 index 00000000000..abaa3f7c498 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/id_namespace.go @@ -0,0 +1,125 @@ +package clients + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceId{} + +// NamespaceId is a struct representing the Resource ID for a Namespace +type NamespaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string +} + +// NewNamespaceID returns a new NamespaceId struct +func NewNamespaceID(subscriptionId string, resourceGroupName string, namespaceName string) NamespaceId { + return NamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + } +} + +// ParseNamespaceID parses 'input' into a NamespaceId +func ParseNamespaceID(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceIDInsensitively parses 'input' case-insensitively into a NamespaceId +// note: this method should only be used for API response data and not user input +func ParseNamespaceIDInsensitively(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + return nil +} + +// ValidateNamespaceID checks that 'input' can be parsed as a Namespace ID +func ValidateNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace ID +func (id NamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace ID +func (id NamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + } +} + +// String returns a human-readable description of this Namespace ID +func (id NamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + } + return fmt.Sprintf("Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/id_namespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/clients/id_namespace_test.go new file mode 100644 index 00000000000..a62d41f3293 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/id_namespace_test.go @@ -0,0 +1,282 @@ +package clients + +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 = &NamespaceId{} + +func TestNewNamespaceID(t *testing.T) { + id := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } +} + +func TestFormatNamespaceID(t *testing.T) { + actual := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestParseNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestSegmentsForNamespaceId(t *testing.T) { + segments := NamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/clients/method_createorupdate.go new file mode 100644 index 00000000000..9bbe07f0a14 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/method_createorupdate.go @@ -0,0 +1,75 @@ +package clients + +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 *Client +} + +// CreateOrUpdate ... +func (c ClientsClient) CreateOrUpdate(ctx context.Context, id ClientId, input Client) (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 ClientsClient) CreateOrUpdateThenPoll(ctx context.Context, id ClientId, input Client) 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/eventgrid/2023-12-15-preview/clients/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/clients/method_delete.go new file mode 100644 index 00000000000..0dae343ce48 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/method_delete.go @@ -0,0 +1,71 @@ +package clients + +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 ClientsClient) Delete(ctx context.Context, id ClientId) (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 ClientsClient) DeleteThenPoll(ctx context.Context, id ClientId) 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/eventgrid/2023-12-15-preview/clients/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/clients/method_get.go new file mode 100644 index 00000000000..488ba4cea85 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/method_get.go @@ -0,0 +1,54 @@ +package clients + +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 *Client +} + +// Get ... +func (c ClientsClient) Get(ctx context.Context, id ClientId) (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 Client + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/method_listbynamespace.go b/resource-manager/eventgrid/2023-12-15-preview/clients/method_listbynamespace.go new file mode 100644 index 00000000000..48a51a8c8ef --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/method_listbynamespace.go @@ -0,0 +1,123 @@ +package clients + +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 ListByNamespaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Client +} + +type ListByNamespaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []Client +} + +type ListByNamespaceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByNamespaceOperationOptions() ListByNamespaceOperationOptions { + return ListByNamespaceOperationOptions{} +} + +func (o ListByNamespaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByNamespaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByNamespaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByNamespace ... +func (c ClientsClient) ListByNamespace(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (result ListByNamespaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/clients", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Client `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNamespaceComplete retrieves all the results into a single object +func (c ClientsClient) ListByNamespaceComplete(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (ListByNamespaceCompleteResult, error) { + return c.ListByNamespaceCompleteMatchingPredicate(ctx, id, options, ClientOperationPredicate{}) +} + +// ListByNamespaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClientsClient) ListByNamespaceCompleteMatchingPredicate(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions, predicate ClientOperationPredicate) (result ListByNamespaceCompleteResult, err error) { + items := make([]Client, 0) + + resp, err := c.ListByNamespace(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNamespaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/model_client.go b/resource-manager/eventgrid/2023-12-15-preview/clients/model_client.go new file mode 100644 index 00000000000..ce3799b0924 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/model_client.go @@ -0,0 +1,16 @@ +package clients + +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 Client struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ClientProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/model_clientcertificateauthentication.go b/resource-manager/eventgrid/2023-12-15-preview/clients/model_clientcertificateauthentication.go new file mode 100644 index 00000000000..d4c77ad730c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/model_clientcertificateauthentication.go @@ -0,0 +1,9 @@ +package clients + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientCertificateAuthentication struct { + AllowedThumbprints *[]string `json:"allowedThumbprints,omitempty"` + ValidationScheme *ClientCertificateValidationScheme `json:"validationScheme,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/model_clientproperties.go b/resource-manager/eventgrid/2023-12-15-preview/clients/model_clientproperties.go new file mode 100644 index 00000000000..095d65a4697 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/model_clientproperties.go @@ -0,0 +1,13 @@ +package clients + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientProperties struct { + Attributes *interface{} `json:"attributes,omitempty"` + AuthenticationName *string `json:"authenticationName,omitempty"` + ClientCertificateAuthentication *ClientCertificateAuthentication `json:"clientCertificateAuthentication,omitempty"` + Description *string `json:"description,omitempty"` + ProvisioningState *ClientProvisioningState `json:"provisioningState,omitempty"` + State *ClientState `json:"state,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/clients/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/clients/predicates.go new file mode 100644 index 00000000000..f5a7e574984 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/predicates.go @@ -0,0 +1,27 @@ +package clients + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ClientOperationPredicate) Matches(input Client) 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/eventgrid/2023-12-15-preview/clients/version.go b/resource-manager/eventgrid/2023-12-15-preview/clients/version.go new file mode 100644 index 00000000000..690bd3ebac0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/clients/version.go @@ -0,0 +1,12 @@ +package clients + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/clients/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/README.md b/resource-manager/eventgrid/2023-12-15-preview/domains/README.md new file mode 100644 index 00000000000..e9330dae571 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/README.md @@ -0,0 +1,154 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/domains` Documentation + +The `domains` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/domains" +``` + + +### Client Initialization + +```go +client := domains.NewDomainsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DomainsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := domains.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +payload := domains.Domain{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DomainsClient.Delete` + +```go +ctx := context.TODO() +id := domains.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DomainsClient.Get` + +```go +ctx := context.TODO() +id := domains.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +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: `DomainsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, domains.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, domains.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DomainsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, domains.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, domains.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DomainsClient.ListSharedAccessKeys` + +```go +ctx := context.TODO() +id := domains.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +read, err := client.ListSharedAccessKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DomainsClient.RegenerateKey` + +```go +ctx := context.TODO() +id := domains.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +payload := domains.DomainRegenerateKeyRequest{ + // ... +} + + +read, err := client.RegenerateKey(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DomainsClient.Update` + +```go +ctx := context.TODO() +id := domains.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +payload := domains.DomainUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/client.go b/resource-manager/eventgrid/2023-12-15-preview/domains/client.go new file mode 100644 index 00000000000..2ce822d248f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/client.go @@ -0,0 +1,26 @@ +package domains + +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 DomainsClient struct { + Client *resourcemanager.Client +} + +func NewDomainsClientWithBaseURI(sdkApi sdkEnv.Api) (*DomainsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "domains", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DomainsClient: %+v", err) + } + + return &DomainsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/constants.go b/resource-manager/eventgrid/2023-12-15-preview/domains/constants.go new file mode 100644 index 00000000000..a9d8fe6bbae --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/constants.go @@ -0,0 +1,491 @@ +package domains + +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 DataResidencyBoundary string + +const ( + DataResidencyBoundaryWithinGeopair DataResidencyBoundary = "WithinGeopair" + DataResidencyBoundaryWithinRegion DataResidencyBoundary = "WithinRegion" +) + +func PossibleValuesForDataResidencyBoundary() []string { + return []string{ + string(DataResidencyBoundaryWithinGeopair), + string(DataResidencyBoundaryWithinRegion), + } +} + +func (s *DataResidencyBoundary) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataResidencyBoundary(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataResidencyBoundary(input string) (*DataResidencyBoundary, error) { + vals := map[string]DataResidencyBoundary{ + "withingeopair": DataResidencyBoundaryWithinGeopair, + "withinregion": DataResidencyBoundaryWithinRegion, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataResidencyBoundary(input) + return &out, nil +} + +type DomainProvisioningState string + +const ( + DomainProvisioningStateCanceled DomainProvisioningState = "Canceled" + DomainProvisioningStateCreating DomainProvisioningState = "Creating" + DomainProvisioningStateDeleting DomainProvisioningState = "Deleting" + DomainProvisioningStateFailed DomainProvisioningState = "Failed" + DomainProvisioningStateSucceeded DomainProvisioningState = "Succeeded" + DomainProvisioningStateUpdating DomainProvisioningState = "Updating" +) + +func PossibleValuesForDomainProvisioningState() []string { + return []string{ + string(DomainProvisioningStateCanceled), + string(DomainProvisioningStateCreating), + string(DomainProvisioningStateDeleting), + string(DomainProvisioningStateFailed), + string(DomainProvisioningStateSucceeded), + string(DomainProvisioningStateUpdating), + } +} + +func (s *DomainProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDomainProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDomainProvisioningState(input string) (*DomainProvisioningState, error) { + vals := map[string]DomainProvisioningState{ + "canceled": DomainProvisioningStateCanceled, + "creating": DomainProvisioningStateCreating, + "deleting": DomainProvisioningStateDeleting, + "failed": DomainProvisioningStateFailed, + "succeeded": DomainProvisioningStateSucceeded, + "updating": DomainProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DomainProvisioningState(input) + return &out, nil +} + +type EventDefinitionKind string + +const ( + EventDefinitionKindInline EventDefinitionKind = "Inline" +) + +func PossibleValuesForEventDefinitionKind() []string { + return []string{ + string(EventDefinitionKindInline), + } +} + +func (s *EventDefinitionKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventDefinitionKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventDefinitionKind(input string) (*EventDefinitionKind, error) { + vals := map[string]EventDefinitionKind{ + "inline": EventDefinitionKindInline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventDefinitionKind(input) + return &out, nil +} + +type IPActionType string + +const ( + IPActionTypeAllow IPActionType = "Allow" +) + +func PossibleValuesForIPActionType() []string { + return []string{ + string(IPActionTypeAllow), + } +} + +func (s *IPActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIPActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIPActionType(input string) (*IPActionType, error) { + vals := map[string]IPActionType{ + "allow": IPActionTypeAllow, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPActionType(input) + return &out, nil +} + +type InputSchema string + +const ( + InputSchemaCloudEventSchemaVOneZero InputSchema = "CloudEventSchemaV1_0" + InputSchemaCustomEventSchema InputSchema = "CustomEventSchema" + InputSchemaEventGridSchema InputSchema = "EventGridSchema" +) + +func PossibleValuesForInputSchema() []string { + return []string{ + string(InputSchemaCloudEventSchemaVOneZero), + string(InputSchemaCustomEventSchema), + string(InputSchemaEventGridSchema), + } +} + +func (s *InputSchema) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInputSchema(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInputSchema(input string) (*InputSchema, error) { + vals := map[string]InputSchema{ + "cloudeventschemav1_0": InputSchemaCloudEventSchemaVOneZero, + "customeventschema": InputSchemaCustomEventSchema, + "eventgridschema": InputSchemaEventGridSchema, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InputSchema(input) + return &out, nil +} + +type InputSchemaMappingType string + +const ( + InputSchemaMappingTypeJson InputSchemaMappingType = "Json" +) + +func PossibleValuesForInputSchemaMappingType() []string { + return []string{ + string(InputSchemaMappingTypeJson), + } +} + +func (s *InputSchemaMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInputSchemaMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInputSchemaMappingType(input string) (*InputSchemaMappingType, error) { + vals := map[string]InputSchemaMappingType{ + "json": InputSchemaMappingTypeJson, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InputSchemaMappingType(input) + return &out, nil +} + +type PersistedConnectionStatus string + +const ( + PersistedConnectionStatusApproved PersistedConnectionStatus = "Approved" + PersistedConnectionStatusDisconnected PersistedConnectionStatus = "Disconnected" + PersistedConnectionStatusPending PersistedConnectionStatus = "Pending" + PersistedConnectionStatusRejected PersistedConnectionStatus = "Rejected" +) + +func PossibleValuesForPersistedConnectionStatus() []string { + return []string{ + string(PersistedConnectionStatusApproved), + string(PersistedConnectionStatusDisconnected), + string(PersistedConnectionStatusPending), + string(PersistedConnectionStatusRejected), + } +} + +func (s *PersistedConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePersistedConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePersistedConnectionStatus(input string) (*PersistedConnectionStatus, error) { + vals := map[string]PersistedConnectionStatus{ + "approved": PersistedConnectionStatusApproved, + "disconnected": PersistedConnectionStatusDisconnected, + "pending": PersistedConnectionStatusPending, + "rejected": PersistedConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersistedConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" + PublicNetworkAccessSecuredByPerimeter PublicNetworkAccess = "SecuredByPerimeter" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + string(PublicNetworkAccessSecuredByPerimeter), + } +} + +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, + "securedbyperimeter": PublicNetworkAccessSecuredByPerimeter, + } + 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 ResourceProvisioningState string + +const ( + ResourceProvisioningStateCanceled ResourceProvisioningState = "Canceled" + ResourceProvisioningStateCreating ResourceProvisioningState = "Creating" + ResourceProvisioningStateDeleting ResourceProvisioningState = "Deleting" + ResourceProvisioningStateFailed ResourceProvisioningState = "Failed" + ResourceProvisioningStateSucceeded ResourceProvisioningState = "Succeeded" + ResourceProvisioningStateUpdating ResourceProvisioningState = "Updating" +) + +func PossibleValuesForResourceProvisioningState() []string { + return []string{ + string(ResourceProvisioningStateCanceled), + string(ResourceProvisioningStateCreating), + string(ResourceProvisioningStateDeleting), + string(ResourceProvisioningStateFailed), + string(ResourceProvisioningStateSucceeded), + string(ResourceProvisioningStateUpdating), + } +} + +func (s *ResourceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceProvisioningState(input string) (*ResourceProvisioningState, error) { + vals := map[string]ResourceProvisioningState{ + "canceled": ResourceProvisioningStateCanceled, + "creating": ResourceProvisioningStateCreating, + "deleting": ResourceProvisioningStateDeleting, + "failed": ResourceProvisioningStateFailed, + "succeeded": ResourceProvisioningStateSucceeded, + "updating": ResourceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceProvisioningState(input) + return &out, nil +} + +type Sku string + +const ( + SkuBasic Sku = "Basic" + SkuPremium Sku = "Premium" +) + +func PossibleValuesForSku() []string { + return []string{ + string(SkuBasic), + string(SkuPremium), + } +} + +func (s *Sku) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSku(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSku(input string) (*Sku, error) { + vals := map[string]Sku{ + "basic": SkuBasic, + "premium": SkuPremium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Sku(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/id_domain.go b/resource-manager/eventgrid/2023-12-15-preview/domains/id_domain.go new file mode 100644 index 00000000000..60189a8a876 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/id_domain.go @@ -0,0 +1,125 @@ +package domains + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DomainId{} + +// DomainId is a struct representing the Resource ID for a Domain +type DomainId struct { + SubscriptionId string + ResourceGroupName string + DomainName string +} + +// NewDomainID returns a new DomainId struct +func NewDomainID(subscriptionId string, resourceGroupName string, domainName string) DomainId { + return DomainId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DomainName: domainName, + } +} + +// ParseDomainID parses 'input' into a DomainId +func ParseDomainID(input string) (*DomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDomainIDInsensitively parses 'input' case-insensitively into a DomainId +// note: this method should only be used for API response data and not user input +func ParseDomainIDInsensitively(input string) (*DomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DomainId) 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.DomainName, ok = input.Parsed["domainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "domainName", input) + } + + return nil +} + +// ValidateDomainID checks that 'input' can be parsed as a Domain ID +func ValidateDomainID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDomainID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Domain ID +func (id DomainId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/domains/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DomainName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Domain ID +func (id DomainId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticDomains", "domains", "domains"), + resourceids.UserSpecifiedSegment("domainName", "domainValue"), + } +} + +// String returns a human-readable description of this Domain ID +func (id DomainId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Domain Name: %q", id.DomainName), + } + return fmt.Sprintf("Domain (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/id_domain_test.go b/resource-manager/eventgrid/2023-12-15-preview/domains/id_domain_test.go new file mode 100644 index 00000000000..cc9fd047303 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/id_domain_test.go @@ -0,0 +1,282 @@ +package domains + +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 = &DomainId{} + +func TestNewDomainID(t *testing.T) { + id := NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + + if id.SubscriptionId != "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.DomainName != "domainValue" { + t.Fatalf("Expected %q but got %q for Segment 'DomainName'", id.DomainName, "domainValue") + } +} + +func TestFormatDomainID(t *testing.T) { + actual := NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDomainID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + } +} + +func TestParseDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DomainName: "dOmAiNvAlUe", + }, + }, + { + // 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.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + } +} + +func TestSegmentsForDomainId(t *testing.T) { + segments := DomainId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DomainId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_createorupdate.go new file mode 100644 index 00000000000..2aadf4db845 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_createorupdate.go @@ -0,0 +1,74 @@ +package domains + +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 *Domain +} + +// CreateOrUpdate ... +func (c DomainsClient) CreateOrUpdate(ctx context.Context, id DomainId, input Domain) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c DomainsClient) CreateOrUpdateThenPoll(ctx context.Context, id DomainId, input Domain) 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/eventgrid/2023-12-15-preview/domains/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_delete.go new file mode 100644 index 00000000000..ee4c9195547 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_delete.go @@ -0,0 +1,71 @@ +package domains + +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 DomainsClient) Delete(ctx context.Context, id DomainId) (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 DomainsClient) DeleteThenPoll(ctx context.Context, id DomainId) 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/eventgrid/2023-12-15-preview/domains/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_get.go new file mode 100644 index 00000000000..b35fd82d944 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_get.go @@ -0,0 +1,54 @@ +package domains + +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 *Domain +} + +// Get ... +func (c DomainsClient) Get(ctx context.Context, id DomainId) (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 Domain + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_listbyresourcegroup.go new file mode 100644 index 00000000000..0c193d8b773 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package domains + +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 *[]Domain +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Domain +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c DomainsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/domains", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Domain `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 DomainsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, DomainOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DomainsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate DomainOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Domain, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_listbysubscription.go new file mode 100644 index 00000000000..f312c80c44f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_listbysubscription.go @@ -0,0 +1,124 @@ +package domains + +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 *[]Domain +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Domain +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c DomainsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/domains", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Domain `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 DomainsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, DomainOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DomainsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate DomainOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Domain, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/method_listsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_listsharedaccesskeys.go new file mode 100644 index 00000000000..ce2010520a4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_listsharedaccesskeys.go @@ -0,0 +1,55 @@ +package domains + +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 ListSharedAccessKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DomainSharedAccessKeys +} + +// ListSharedAccessKeys ... +func (c DomainsClient) ListSharedAccessKeys(ctx context.Context, id DomainId) (result ListSharedAccessKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DomainSharedAccessKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/method_regeneratekey.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_regeneratekey.go new file mode 100644 index 00000000000..9e3ed3bff68 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_regeneratekey.go @@ -0,0 +1,59 @@ +package domains + +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 RegenerateKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DomainSharedAccessKeys +} + +// RegenerateKey ... +func (c DomainsClient) RegenerateKey(ctx context.Context, id DomainId, input DomainRegenerateKeyRequest) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DomainSharedAccessKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/domains/method_update.go new file mode 100644 index 00000000000..6866389edb0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/method_update.go @@ -0,0 +1,75 @@ +package domains + +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 *Domain +} + +// Update ... +func (c DomainsClient) Update(ctx context.Context, id DomainId, input DomainUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + 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 DomainsClient) UpdateThenPoll(ctx context.Context, id DomainId, input DomainUpdateParameters) 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/eventgrid/2023-12-15-preview/domains/model_connectionstate.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_connectionstate.go new file mode 100644 index 00000000000..b028ffc8a32 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_connectionstate.go @@ -0,0 +1,10 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PersistedConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_domain.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domain.go new file mode 100644 index 00000000000..b4dd38ca28c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domain.go @@ -0,0 +1,21 @@ +package domains + +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 Domain struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *DomainProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainproperties.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainproperties.go new file mode 100644 index 00000000000..fde7792536b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainproperties.go @@ -0,0 +1,64 @@ +package domains + +import ( + "encoding/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 DomainProperties struct { + AutoCreateTopicWithFirstSubscription *bool `json:"autoCreateTopicWithFirstSubscription,omitempty"` + AutoDeleteTopicWithLastSubscription *bool `json:"autoDeleteTopicWithLastSubscription,omitempty"` + DataResidencyBoundary *DataResidencyBoundary `json:"dataResidencyBoundary,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + Endpoint *string `json:"endpoint,omitempty"` + EventTypeInfo *EventTypeInfo `json:"eventTypeInfo,omitempty"` + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + InputSchema *InputSchema `json:"inputSchema,omitempty"` + InputSchemaMapping InputSchemaMapping `json:"inputSchemaMapping"` + MetricResourceId *string `json:"metricResourceId,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *DomainProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} + +var _ json.Unmarshaler = &DomainProperties{} + +func (s *DomainProperties) UnmarshalJSON(bytes []byte) error { + type alias DomainProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DomainProperties: %+v", err) + } + + s.AutoCreateTopicWithFirstSubscription = decoded.AutoCreateTopicWithFirstSubscription + s.AutoDeleteTopicWithLastSubscription = decoded.AutoDeleteTopicWithLastSubscription + s.DataResidencyBoundary = decoded.DataResidencyBoundary + s.DisableLocalAuth = decoded.DisableLocalAuth + s.Endpoint = decoded.Endpoint + s.EventTypeInfo = decoded.EventTypeInfo + s.InboundIPRules = decoded.InboundIPRules + s.InputSchema = decoded.InputSchema + s.MetricResourceId = decoded.MetricResourceId + s.MinimumTlsVersionAllowed = decoded.MinimumTlsVersionAllowed + s.PrivateEndpointConnections = decoded.PrivateEndpointConnections + s.ProvisioningState = decoded.ProvisioningState + s.PublicNetworkAccess = decoded.PublicNetworkAccess + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DomainProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["inputSchemaMapping"]; ok { + impl, err := unmarshalInputSchemaMappingImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'InputSchemaMapping' for 'DomainProperties': %+v", err) + } + s.InputSchemaMapping = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainregeneratekeyrequest.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainregeneratekeyrequest.go new file mode 100644 index 00000000000..ee742c5647b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainregeneratekeyrequest.go @@ -0,0 +1,8 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainRegenerateKeyRequest struct { + KeyName string `json:"keyName"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainsharedaccesskeys.go new file mode 100644 index 00000000000..68c0ada4fb0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainsharedaccesskeys.go @@ -0,0 +1,9 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainSharedAccessKeys struct { + Key1 *string `json:"key1,omitempty"` + Key2 *string `json:"key2,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainupdateparameterproperties.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainupdateparameterproperties.go new file mode 100644 index 00000000000..c751bd83403 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainupdateparameterproperties.go @@ -0,0 +1,15 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainUpdateParameterProperties struct { + AutoCreateTopicWithFirstSubscription *bool `json:"autoCreateTopicWithFirstSubscription,omitempty"` + AutoDeleteTopicWithLastSubscription *bool `json:"autoDeleteTopicWithLastSubscription,omitempty"` + DataResidencyBoundary *DataResidencyBoundary `json:"dataResidencyBoundary,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + EventTypeInfo *EventTypeInfo `json:"eventTypeInfo,omitempty"` + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainupdateparameters.go new file mode 100644 index 00000000000..85846d30c24 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_domainupdateparameters.go @@ -0,0 +1,15 @@ +package domains + +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 DomainUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *DomainUpdateParameterProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_eventtypeinfo.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_eventtypeinfo.go new file mode 100644 index 00000000000..3ff241033b9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_eventtypeinfo.go @@ -0,0 +1,9 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypeInfo struct { + InlineEventTypes *map[string]InlineEventProperties `json:"inlineEventTypes,omitempty"` + Kind *EventDefinitionKind `json:"kind,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_inboundiprule.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_inboundiprule.go new file mode 100644 index 00000000000..be6f6d43dde --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_inboundiprule.go @@ -0,0 +1,9 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InboundIPRule struct { + Action *IPActionType `json:"action,omitempty"` + IPMask *string `json:"ipMask,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_inlineeventproperties.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_inlineeventproperties.go new file mode 100644 index 00000000000..aeaa4d0db2c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_inlineeventproperties.go @@ -0,0 +1,11 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InlineEventProperties struct { + DataSchemaUrl *string `json:"dataSchemaUrl,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + DocumentationUrl *string `json:"documentationUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_inputschemamapping.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_inputschemamapping.go new file mode 100644 index 00000000000..2b57ba9fbd0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_inputschemamapping.go @@ -0,0 +1,53 @@ +package domains + +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 InputSchemaMapping interface { +} + +// RawInputSchemaMappingImpl 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 RawInputSchemaMappingImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalInputSchemaMappingImplementation(input []byte) (InputSchemaMapping, 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 InputSchemaMapping into map[string]interface: %+v", err) + } + + value, ok := temp["inputSchemaMappingType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Json") { + var out JsonInputSchemaMapping + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JsonInputSchemaMapping: %+v", err) + } + return out, nil + } + + out := RawInputSchemaMappingImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsonfield.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsonfield.go new file mode 100644 index 00000000000..30e2373bcf3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsonfield.go @@ -0,0 +1,8 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JsonField struct { + SourceField *string `json:"sourceField,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsonfieldwithdefault.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsonfieldwithdefault.go new file mode 100644 index 00000000000..39d8930172e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsonfieldwithdefault.go @@ -0,0 +1,9 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JsonFieldWithDefault struct { + DefaultValue *string `json:"defaultValue,omitempty"` + SourceField *string `json:"sourceField,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsoninputschemamapping.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsoninputschemamapping.go new file mode 100644 index 00000000000..c1d94f844f6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsoninputschemamapping.go @@ -0,0 +1,41 @@ +package domains + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ InputSchemaMapping = JsonInputSchemaMapping{} + +type JsonInputSchemaMapping struct { + Properties *JsonInputSchemaMappingProperties `json:"properties,omitempty"` + + // Fields inherited from InputSchemaMapping +} + +var _ json.Marshaler = JsonInputSchemaMapping{} + +func (s JsonInputSchemaMapping) MarshalJSON() ([]byte, error) { + type wrapper JsonInputSchemaMapping + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JsonInputSchemaMapping: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JsonInputSchemaMapping: %+v", err) + } + decoded["inputSchemaMappingType"] = "Json" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JsonInputSchemaMapping: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsoninputschemamappingproperties.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsoninputschemamappingproperties.go new file mode 100644 index 00000000000..d298ea00a1b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_jsoninputschemamappingproperties.go @@ -0,0 +1,13 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JsonInputSchemaMappingProperties struct { + DataVersion *JsonFieldWithDefault `json:"dataVersion,omitempty"` + EventTime *JsonField `json:"eventTime,omitempty"` + EventType *JsonFieldWithDefault `json:"eventType,omitempty"` + Id *JsonField `json:"id,omitempty"` + Subject *JsonFieldWithDefault `json:"subject,omitempty"` + Topic *JsonField `json:"topic,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpoint.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpoint.go new file mode 100644 index 00000000000..87ca3874612 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpoint.go @@ -0,0 +1,8 @@ +package domains + +// 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/eventgrid/2023-12-15-preview/domains/model_privateendpointconnection.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpointconnection.go new file mode 100644 index 00000000000..6cc638dda41 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpointconnectionproperties.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..185dbf193d2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package domains + +// 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 *ConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ResourceProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/model_resourcesku.go b/resource-manager/eventgrid/2023-12-15-preview/domains/model_resourcesku.go new file mode 100644 index 00000000000..c824f08ec95 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/model_resourcesku.go @@ -0,0 +1,8 @@ +package domains + +// 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 { + Name *Sku `json:"name,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domains/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/domains/predicates.go new file mode 100644 index 00000000000..1e6a76ee099 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/predicates.go @@ -0,0 +1,32 @@ +package domains + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DomainOperationPredicate) Matches(input Domain) 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/eventgrid/2023-12-15-preview/domains/version.go b/resource-manager/eventgrid/2023-12-15-preview/domains/version.go new file mode 100644 index 00000000000..8c99e72f1a2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domains/version.go @@ -0,0 +1,12 @@ +package domains + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/domains/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/README.md b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/README.md new file mode 100644 index 00000000000..0e4f46f2f09 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/README.md @@ -0,0 +1,77 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/domaintopics` Documentation + +The `domaintopics` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/domaintopics" +``` + + +### Client Initialization + +```go +client := domaintopics.NewDomainTopicsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DomainTopicsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := domaintopics.NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue") + +if err := client.CreateOrUpdateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DomainTopicsClient.Delete` + +```go +ctx := context.TODO() +id := domaintopics.NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DomainTopicsClient.Get` + +```go +ctx := context.TODO() +id := domaintopics.NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue") + +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: `DomainTopicsClient.ListByDomain` + +```go +ctx := context.TODO() +id := domaintopics.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +// alternatively `client.ListByDomain(ctx, id, domaintopics.DefaultListByDomainOperationOptions())` can be used to do batched pagination +items, err := client.ListByDomainComplete(ctx, id, domaintopics.DefaultListByDomainOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/client.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/client.go new file mode 100644 index 00000000000..2bff1850d61 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/client.go @@ -0,0 +1,26 @@ +package domaintopics + +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 DomainTopicsClient struct { + Client *resourcemanager.Client +} + +func NewDomainTopicsClientWithBaseURI(sdkApi sdkEnv.Api) (*DomainTopicsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "domaintopics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DomainTopicsClient: %+v", err) + } + + return &DomainTopicsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/constants.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/constants.go new file mode 100644 index 00000000000..d9cf20bd046 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/constants.go @@ -0,0 +1,63 @@ +package domaintopics + +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 DomainTopicProvisioningState string + +const ( + DomainTopicProvisioningStateCanceled DomainTopicProvisioningState = "Canceled" + DomainTopicProvisioningStateCreating DomainTopicProvisioningState = "Creating" + DomainTopicProvisioningStateDeleting DomainTopicProvisioningState = "Deleting" + DomainTopicProvisioningStateFailed DomainTopicProvisioningState = "Failed" + DomainTopicProvisioningStateSucceeded DomainTopicProvisioningState = "Succeeded" + DomainTopicProvisioningStateUpdating DomainTopicProvisioningState = "Updating" +) + +func PossibleValuesForDomainTopicProvisioningState() []string { + return []string{ + string(DomainTopicProvisioningStateCanceled), + string(DomainTopicProvisioningStateCreating), + string(DomainTopicProvisioningStateDeleting), + string(DomainTopicProvisioningStateFailed), + string(DomainTopicProvisioningStateSucceeded), + string(DomainTopicProvisioningStateUpdating), + } +} + +func (s *DomainTopicProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDomainTopicProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDomainTopicProvisioningState(input string) (*DomainTopicProvisioningState, error) { + vals := map[string]DomainTopicProvisioningState{ + "canceled": DomainTopicProvisioningStateCanceled, + "creating": DomainTopicProvisioningStateCreating, + "deleting": DomainTopicProvisioningStateDeleting, + "failed": DomainTopicProvisioningStateFailed, + "succeeded": DomainTopicProvisioningStateSucceeded, + "updating": DomainTopicProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DomainTopicProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domain.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domain.go new file mode 100644 index 00000000000..412e879aef4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domain.go @@ -0,0 +1,125 @@ +package domaintopics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DomainId{} + +// DomainId is a struct representing the Resource ID for a Domain +type DomainId struct { + SubscriptionId string + ResourceGroupName string + DomainName string +} + +// NewDomainID returns a new DomainId struct +func NewDomainID(subscriptionId string, resourceGroupName string, domainName string) DomainId { + return DomainId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DomainName: domainName, + } +} + +// ParseDomainID parses 'input' into a DomainId +func ParseDomainID(input string) (*DomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDomainIDInsensitively parses 'input' case-insensitively into a DomainId +// note: this method should only be used for API response data and not user input +func ParseDomainIDInsensitively(input string) (*DomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DomainId) 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.DomainName, ok = input.Parsed["domainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "domainName", input) + } + + return nil +} + +// ValidateDomainID checks that 'input' can be parsed as a Domain ID +func ValidateDomainID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDomainID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Domain ID +func (id DomainId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/domains/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DomainName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Domain ID +func (id DomainId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticDomains", "domains", "domains"), + resourceids.UserSpecifiedSegment("domainName", "domainValue"), + } +} + +// String returns a human-readable description of this Domain ID +func (id DomainId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Domain Name: %q", id.DomainName), + } + return fmt.Sprintf("Domain (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domain_test.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domain_test.go new file mode 100644 index 00000000000..c35e3a0fd0c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domain_test.go @@ -0,0 +1,282 @@ +package domaintopics + +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 = &DomainId{} + +func TestNewDomainID(t *testing.T) { + id := NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + + if id.SubscriptionId != "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.DomainName != "domainValue" { + t.Fatalf("Expected %q but got %q for Segment 'DomainName'", id.DomainName, "domainValue") + } +} + +func TestFormatDomainID(t *testing.T) { + actual := NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDomainID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + } +} + +func TestParseDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DomainName: "dOmAiNvAlUe", + }, + }, + { + // 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.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + } +} + +func TestSegmentsForDomainId(t *testing.T) { + segments := DomainId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DomainId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domaintopic.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domaintopic.go new file mode 100644 index 00000000000..ebac42df039 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domaintopic.go @@ -0,0 +1,134 @@ +package domaintopics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DomainTopicId{} + +// DomainTopicId is a struct representing the Resource ID for a Domain Topic +type DomainTopicId struct { + SubscriptionId string + ResourceGroupName string + DomainName string + TopicName string +} + +// NewDomainTopicID returns a new DomainTopicId struct +func NewDomainTopicID(subscriptionId string, resourceGroupName string, domainName string, topicName string) DomainTopicId { + return DomainTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DomainName: domainName, + TopicName: topicName, + } +} + +// ParseDomainTopicID parses 'input' into a DomainTopicId +func ParseDomainTopicID(input string) (*DomainTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDomainTopicIDInsensitively parses 'input' case-insensitively into a DomainTopicId +// note: this method should only be used for API response data and not user input +func ParseDomainTopicIDInsensitively(input string) (*DomainTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DomainTopicId) 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.DomainName, ok = input.Parsed["domainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "domainName", input) + } + + if id.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + return nil +} + +// ValidateDomainTopicID checks that 'input' can be parsed as a Domain Topic ID +func ValidateDomainTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDomainTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Domain Topic ID +func (id DomainTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/domains/%s/topics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DomainName, id.TopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Domain Topic ID +func (id DomainTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticDomains", "domains", "domains"), + resourceids.UserSpecifiedSegment("domainName", "domainValue"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + } +} + +// String returns a human-readable description of this Domain Topic ID +func (id DomainTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Domain Name: %q", id.DomainName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + } + return fmt.Sprintf("Domain Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domaintopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domaintopic_test.go new file mode 100644 index 00000000000..3f206a3b4b1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/id_domaintopic_test.go @@ -0,0 +1,327 @@ +package domaintopics + +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 = &DomainTopicId{} + +func TestNewDomainTopicID(t *testing.T) { + id := NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue") + + if id.SubscriptionId != "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.DomainName != "domainValue" { + t.Fatalf("Expected %q but got %q for Segment 'DomainName'", id.DomainName, "domainValue") + } + + if id.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } +} + +func TestFormatDomainTopicID(t *testing.T) { + actual := NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDomainTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue", + Expected: &DomainTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestParseDomainTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue", + Expected: &DomainTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE", + Expected: &DomainTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DomainName: "dOmAiNvAlUe", + TopicName: "tOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestSegmentsForDomainTopicId(t *testing.T) { + segments := DomainTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DomainTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_createorupdate.go new file mode 100644 index 00000000000..b3a6b566a08 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_createorupdate.go @@ -0,0 +1,70 @@ +package domaintopics + +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 *DomainTopic +} + +// CreateOrUpdate ... +func (c DomainTopicsClient) CreateOrUpdate(ctx context.Context, id DomainTopicId) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c DomainTopicsClient) CreateOrUpdateThenPoll(ctx context.Context, id DomainTopicId) error { + result, err := c.CreateOrUpdate(ctx, id) + 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/eventgrid/2023-12-15-preview/domaintopics/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_delete.go new file mode 100644 index 00000000000..a42300e107d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_delete.go @@ -0,0 +1,71 @@ +package domaintopics + +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 DomainTopicsClient) Delete(ctx context.Context, id DomainTopicId) (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 DomainTopicsClient) DeleteThenPoll(ctx context.Context, id DomainTopicId) 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/eventgrid/2023-12-15-preview/domaintopics/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_get.go new file mode 100644 index 00000000000..8b38c7d9766 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_get.go @@ -0,0 +1,54 @@ +package domaintopics + +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 *DomainTopic +} + +// Get ... +func (c DomainTopicsClient) Get(ctx context.Context, id DomainTopicId) (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 DomainTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_listbydomain.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_listbydomain.go new file mode 100644 index 00000000000..fa7c512323b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/method_listbydomain.go @@ -0,0 +1,123 @@ +package domaintopics + +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 ListByDomainOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DomainTopic +} + +type ListByDomainCompleteResult struct { + LatestHttpResponse *http.Response + Items []DomainTopic +} + +type ListByDomainOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByDomainOperationOptions() ListByDomainOperationOptions { + return ListByDomainOperationOptions{} +} + +func (o ListByDomainOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDomainOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByDomainOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByDomain ... +func (c DomainTopicsClient) ListByDomain(ctx context.Context, id DomainId, options ListByDomainOperationOptions) (result ListByDomainOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/topics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DomainTopic `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDomainComplete retrieves all the results into a single object +func (c DomainTopicsClient) ListByDomainComplete(ctx context.Context, id DomainId, options ListByDomainOperationOptions) (ListByDomainCompleteResult, error) { + return c.ListByDomainCompleteMatchingPredicate(ctx, id, options, DomainTopicOperationPredicate{}) +} + +// ListByDomainCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DomainTopicsClient) ListByDomainCompleteMatchingPredicate(ctx context.Context, id DomainId, options ListByDomainOperationOptions, predicate DomainTopicOperationPredicate) (result ListByDomainCompleteResult, err error) { + items := make([]DomainTopic, 0) + + resp, err := c.ListByDomain(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDomainCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/model_domaintopic.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/model_domaintopic.go new file mode 100644 index 00000000000..7877637887f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/model_domaintopic.go @@ -0,0 +1,16 @@ +package domaintopics + +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 DomainTopic struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DomainTopicProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/model_domaintopicproperties.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/model_domaintopicproperties.go new file mode 100644 index 00000000000..aa99edfde97 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/model_domaintopicproperties.go @@ -0,0 +1,8 @@ +package domaintopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainTopicProperties struct { + ProvisioningState *DomainTopicProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/domaintopics/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/predicates.go new file mode 100644 index 00000000000..3f34d344a23 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/predicates.go @@ -0,0 +1,27 @@ +package domaintopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainTopicOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DomainTopicOperationPredicate) Matches(input DomainTopic) 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/eventgrid/2023-12-15-preview/domaintopics/version.go b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/version.go new file mode 100644 index 00000000000..3af76c3d67f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/domaintopics/version.go @@ -0,0 +1,12 @@ +package domaintopics + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/domaintopics/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/README.md b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/README.md new file mode 100644 index 00000000000..253b4a062d2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/README.md @@ -0,0 +1,935 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions` Documentation + +The `eventsubscriptions` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/eventsubscriptions" +``` + + +### Client Initialization + +```go +client := eventsubscriptions.NewEventSubscriptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EventSubscriptionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscription{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.Delete` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainEventSubscriptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscription{ + // ... +} + + +if err := client.DomainEventSubscriptionsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainEventSubscriptionsDelete` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue") + +if err := client.DomainEventSubscriptionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainEventSubscriptionsGet` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue") + +read, err := client.DomainEventSubscriptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainEventSubscriptionsGetDeliveryAttributes` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue") + +read, err := client.DomainEventSubscriptionsGetDeliveryAttributes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainEventSubscriptionsGetFullUrl` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue") + +read, err := client.DomainEventSubscriptionsGetFullUrl(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainEventSubscriptionsList` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + +// alternatively `client.DomainEventSubscriptionsList(ctx, id, eventsubscriptions.DefaultDomainEventSubscriptionsListOperationOptions())` can be used to do batched pagination +items, err := client.DomainEventSubscriptionsListComplete(ctx, id, eventsubscriptions.DefaultDomainEventSubscriptionsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainEventSubscriptionsUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscriptionUpdateParameters{ + // ... +} + + +if err := client.DomainEventSubscriptionsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainTopicEventSubscriptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscription{ + // ... +} + + +if err := client.DomainTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainTopicEventSubscriptionsDelete` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue") + +if err := client.DomainTopicEventSubscriptionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainTopicEventSubscriptionsGet` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue") + +read, err := client.DomainTopicEventSubscriptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainTopicEventSubscriptionsGetDeliveryAttributes` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue") + +read, err := client.DomainTopicEventSubscriptionsGetDeliveryAttributes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainTopicEventSubscriptionsGetFullUrl` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue") + +read, err := client.DomainTopicEventSubscriptionsGetFullUrl(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainTopicEventSubscriptionsList` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue") + +// alternatively `client.DomainTopicEventSubscriptionsList(ctx, id, eventsubscriptions.DefaultDomainTopicEventSubscriptionsListOperationOptions())` can be used to do batched pagination +items, err := client.DomainTopicEventSubscriptionsListComplete(ctx, id, eventsubscriptions.DefaultDomainTopicEventSubscriptionsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.DomainTopicEventSubscriptionsUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscriptionUpdateParameters{ + // ... +} + + +if err := client.DomainTopicEventSubscriptionsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.Get` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue") + +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: `EventSubscriptionsClient.GetDeliveryAttributes` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue") + +read, err := client.GetDeliveryAttributes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.GetFullUrl` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue") + +read, err := client.GetFullUrl(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListByDomainTopic` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue") + +// alternatively `client.ListByDomainTopic(ctx, id, eventsubscriptions.DefaultListByDomainTopicOperationOptions())` can be used to do batched pagination +items, err := client.ListByDomainTopicComplete(ctx, id, eventsubscriptions.DefaultListByDomainTopicOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListByResource` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListByResource(ctx, id, eventsubscriptions.DefaultListByResourceOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceComplete(ctx, id, eventsubscriptions.DefaultListByResourceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListGlobalByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListGlobalByResourceGroup(ctx, id, eventsubscriptions.DefaultListGlobalByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListGlobalByResourceGroupComplete(ctx, id, eventsubscriptions.DefaultListGlobalByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListGlobalByResourceGroupForTopicType` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewResourceGroupProviderTopicTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicTypeValue") + +// alternatively `client.ListGlobalByResourceGroupForTopicType(ctx, id, eventsubscriptions.DefaultListGlobalByResourceGroupForTopicTypeOperationOptions())` can be used to do batched pagination +items, err := client.ListGlobalByResourceGroupForTopicTypeComplete(ctx, id, eventsubscriptions.DefaultListGlobalByResourceGroupForTopicTypeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListGlobalBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListGlobalBySubscription(ctx, id, eventsubscriptions.DefaultListGlobalBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListGlobalBySubscriptionComplete(ctx, id, eventsubscriptions.DefaultListGlobalBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListGlobalBySubscriptionForTopicType` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewProviderTopicTypeID("12345678-1234-9876-4563-123456789012", "topicTypeValue") + +// alternatively `client.ListGlobalBySubscriptionForTopicType(ctx, id, eventsubscriptions.DefaultListGlobalBySubscriptionForTopicTypeOperationOptions())` can be used to do batched pagination +items, err := client.ListGlobalBySubscriptionForTopicTypeComplete(ctx, id, eventsubscriptions.DefaultListGlobalBySubscriptionForTopicTypeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListRegionalByResourceGroup` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + +// alternatively `client.ListRegionalByResourceGroup(ctx, id, eventsubscriptions.DefaultListRegionalByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListRegionalByResourceGroupComplete(ctx, id, eventsubscriptions.DefaultListRegionalByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListRegionalByResourceGroupForTopicType` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewProviderLocationTopicTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "topicTypeValue") + +// alternatively `client.ListRegionalByResourceGroupForTopicType(ctx, id, eventsubscriptions.DefaultListRegionalByResourceGroupForTopicTypeOperationOptions())` can be used to do batched pagination +items, err := client.ListRegionalByResourceGroupForTopicTypeComplete(ctx, id, eventsubscriptions.DefaultListRegionalByResourceGroupForTopicTypeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListRegionalBySubscription` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.ListRegionalBySubscription(ctx, id, eventsubscriptions.DefaultListRegionalBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListRegionalBySubscriptionComplete(ctx, id, eventsubscriptions.DefaultListRegionalBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.ListRegionalBySubscriptionForTopicType` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewLocationTopicTypeID("12345678-1234-9876-4563-123456789012", "locationValue", "topicTypeValue") + +// alternatively `client.ListRegionalBySubscriptionForTopicType(ctx, id, eventsubscriptions.DefaultListRegionalBySubscriptionForTopicTypeOperationOptions())` can be used to do batched pagination +items, err := client.ListRegionalBySubscriptionForTopicTypeComplete(ctx, id, eventsubscriptions.DefaultListRegionalBySubscriptionForTopicTypeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.NamespaceTopicEventSubscriptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewNamespaceTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.Subscription{ + // ... +} + + +if err := client.NamespaceTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.NamespaceTopicEventSubscriptionsDelete` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewNamespaceTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue", "eventSubscriptionValue") + +if err := client.NamespaceTopicEventSubscriptionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.NamespaceTopicEventSubscriptionsGet` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewNamespaceTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue", "eventSubscriptionValue") + +read, err := client.NamespaceTopicEventSubscriptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.NamespaceTopicEventSubscriptionsGetDeliveryAttributes` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewNamespaceTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue", "eventSubscriptionValue") + +read, err := client.NamespaceTopicEventSubscriptionsGetDeliveryAttributes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.NamespaceTopicEventSubscriptionsListByNamespaceTopic` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + +// alternatively `client.NamespaceTopicEventSubscriptionsListByNamespaceTopic(ctx, id, eventsubscriptions.DefaultNamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions())` can be used to do batched pagination +items, err := client.NamespaceTopicEventSubscriptionsListByNamespaceTopicComplete(ctx, id, eventsubscriptions.DefaultNamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.NamespaceTopicEventSubscriptionsUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewNamespaceTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.SubscriptionUpdateParameters{ + // ... +} + + +if err := client.NamespaceTopicEventSubscriptionsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.PartnerTopicEventSubscriptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscription{ + // ... +} + + +if err := client.PartnerTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.PartnerTopicEventSubscriptionsDelete` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue") + +if err := client.PartnerTopicEventSubscriptionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.PartnerTopicEventSubscriptionsGet` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue") + +read, err := client.PartnerTopicEventSubscriptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.PartnerTopicEventSubscriptionsGetDeliveryAttributes` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue") + +read, err := client.PartnerTopicEventSubscriptionsGetDeliveryAttributes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.PartnerTopicEventSubscriptionsGetFullUrl` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue") + +read, err := client.PartnerTopicEventSubscriptionsGetFullUrl(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.PartnerTopicEventSubscriptionsListByPartnerTopic` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + +// alternatively `client.PartnerTopicEventSubscriptionsListByPartnerTopic(ctx, id, eventsubscriptions.DefaultPartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions())` can be used to do batched pagination +items, err := client.PartnerTopicEventSubscriptionsListByPartnerTopicComplete(ctx, id, eventsubscriptions.DefaultPartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.PartnerTopicEventSubscriptionsUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscriptionUpdateParameters{ + // ... +} + + +if err := client.PartnerTopicEventSubscriptionsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.SystemTopicEventSubscriptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscription{ + // ... +} + + +if err := client.SystemTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.SystemTopicEventSubscriptionsDelete` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue") + +if err := client.SystemTopicEventSubscriptionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.SystemTopicEventSubscriptionsGet` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue") + +read, err := client.SystemTopicEventSubscriptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.SystemTopicEventSubscriptionsGetDeliveryAttributes` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue") + +read, err := client.SystemTopicEventSubscriptionsGetDeliveryAttributes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.SystemTopicEventSubscriptionsGetFullUrl` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue") + +read, err := client.SystemTopicEventSubscriptionsGetFullUrl(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.SystemTopicEventSubscriptionsListBySystemTopic` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue") + +// alternatively `client.SystemTopicEventSubscriptionsListBySystemTopic(ctx, id, eventsubscriptions.DefaultSystemTopicEventSubscriptionsListBySystemTopicOperationOptions())` can be used to do batched pagination +items, err := client.SystemTopicEventSubscriptionsListBySystemTopicComplete(ctx, id, eventsubscriptions.DefaultSystemTopicEventSubscriptionsListBySystemTopicOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.SystemTopicEventSubscriptionsUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscriptionUpdateParameters{ + // ... +} + + +if err := client.SystemTopicEventSubscriptionsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.TopicEventSubscriptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscription{ + // ... +} + + +if err := client.TopicEventSubscriptionsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.TopicEventSubscriptionsDelete` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue") + +if err := client.TopicEventSubscriptionsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.TopicEventSubscriptionsGet` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue") + +read, err := client.TopicEventSubscriptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.TopicEventSubscriptionsGetDeliveryAttributes` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue") + +read, err := client.TopicEventSubscriptionsGetDeliveryAttributes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.TopicEventSubscriptionsGetFullUrl` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue") + +read, err := client.TopicEventSubscriptionsGetFullUrl(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EventSubscriptionsClient.TopicEventSubscriptionsList` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + +// alternatively `client.TopicEventSubscriptionsList(ctx, id, eventsubscriptions.DefaultTopicEventSubscriptionsListOperationOptions())` can be used to do batched pagination +items, err := client.TopicEventSubscriptionsListComplete(ctx, id, eventsubscriptions.DefaultTopicEventSubscriptionsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EventSubscriptionsClient.TopicEventSubscriptionsUpdate` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscriptionUpdateParameters{ + // ... +} + + +if err := client.TopicEventSubscriptionsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EventSubscriptionsClient.Update` + +```go +ctx := context.TODO() +id := eventsubscriptions.NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue") + +payload := eventsubscriptions.EventSubscriptionUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/client.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/client.go new file mode 100644 index 00000000000..0e948364c6c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/client.go @@ -0,0 +1,26 @@ +package eventsubscriptions + +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 EventSubscriptionsClient struct { + Client *resourcemanager.Client +} + +func NewEventSubscriptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*EventSubscriptionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "eventsubscriptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EventSubscriptionsClient: %+v", err) + } + + return &EventSubscriptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/constants.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/constants.go new file mode 100644 index 00000000000..9da2ed3c781 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/constants.go @@ -0,0 +1,720 @@ +package eventsubscriptions + +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 AdvancedFilterOperatorType string + +const ( + AdvancedFilterOperatorTypeBoolEquals AdvancedFilterOperatorType = "BoolEquals" + AdvancedFilterOperatorTypeIsNotNull AdvancedFilterOperatorType = "IsNotNull" + AdvancedFilterOperatorTypeIsNullOrUndefined AdvancedFilterOperatorType = "IsNullOrUndefined" + AdvancedFilterOperatorTypeNumberGreaterThan AdvancedFilterOperatorType = "NumberGreaterThan" + AdvancedFilterOperatorTypeNumberGreaterThanOrEquals AdvancedFilterOperatorType = "NumberGreaterThanOrEquals" + AdvancedFilterOperatorTypeNumberIn AdvancedFilterOperatorType = "NumberIn" + AdvancedFilterOperatorTypeNumberInRange AdvancedFilterOperatorType = "NumberInRange" + AdvancedFilterOperatorTypeNumberLessThan AdvancedFilterOperatorType = "NumberLessThan" + AdvancedFilterOperatorTypeNumberLessThanOrEquals AdvancedFilterOperatorType = "NumberLessThanOrEquals" + AdvancedFilterOperatorTypeNumberNotIn AdvancedFilterOperatorType = "NumberNotIn" + AdvancedFilterOperatorTypeNumberNotInRange AdvancedFilterOperatorType = "NumberNotInRange" + AdvancedFilterOperatorTypeStringBeginsWith AdvancedFilterOperatorType = "StringBeginsWith" + AdvancedFilterOperatorTypeStringContains AdvancedFilterOperatorType = "StringContains" + AdvancedFilterOperatorTypeStringEndsWith AdvancedFilterOperatorType = "StringEndsWith" + AdvancedFilterOperatorTypeStringIn AdvancedFilterOperatorType = "StringIn" + AdvancedFilterOperatorTypeStringNotBeginsWith AdvancedFilterOperatorType = "StringNotBeginsWith" + AdvancedFilterOperatorTypeStringNotContains AdvancedFilterOperatorType = "StringNotContains" + AdvancedFilterOperatorTypeStringNotEndsWith AdvancedFilterOperatorType = "StringNotEndsWith" + AdvancedFilterOperatorTypeStringNotIn AdvancedFilterOperatorType = "StringNotIn" +) + +func PossibleValuesForAdvancedFilterOperatorType() []string { + return []string{ + string(AdvancedFilterOperatorTypeBoolEquals), + string(AdvancedFilterOperatorTypeIsNotNull), + string(AdvancedFilterOperatorTypeIsNullOrUndefined), + string(AdvancedFilterOperatorTypeNumberGreaterThan), + string(AdvancedFilterOperatorTypeNumberGreaterThanOrEquals), + string(AdvancedFilterOperatorTypeNumberIn), + string(AdvancedFilterOperatorTypeNumberInRange), + string(AdvancedFilterOperatorTypeNumberLessThan), + string(AdvancedFilterOperatorTypeNumberLessThanOrEquals), + string(AdvancedFilterOperatorTypeNumberNotIn), + string(AdvancedFilterOperatorTypeNumberNotInRange), + string(AdvancedFilterOperatorTypeStringBeginsWith), + string(AdvancedFilterOperatorTypeStringContains), + string(AdvancedFilterOperatorTypeStringEndsWith), + string(AdvancedFilterOperatorTypeStringIn), + string(AdvancedFilterOperatorTypeStringNotBeginsWith), + string(AdvancedFilterOperatorTypeStringNotContains), + string(AdvancedFilterOperatorTypeStringNotEndsWith), + string(AdvancedFilterOperatorTypeStringNotIn), + } +} + +func (s *AdvancedFilterOperatorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdvancedFilterOperatorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdvancedFilterOperatorType(input string) (*AdvancedFilterOperatorType, error) { + vals := map[string]AdvancedFilterOperatorType{ + "boolequals": AdvancedFilterOperatorTypeBoolEquals, + "isnotnull": AdvancedFilterOperatorTypeIsNotNull, + "isnullorundefined": AdvancedFilterOperatorTypeIsNullOrUndefined, + "numbergreaterthan": AdvancedFilterOperatorTypeNumberGreaterThan, + "numbergreaterthanorequals": AdvancedFilterOperatorTypeNumberGreaterThanOrEquals, + "numberin": AdvancedFilterOperatorTypeNumberIn, + "numberinrange": AdvancedFilterOperatorTypeNumberInRange, + "numberlessthan": AdvancedFilterOperatorTypeNumberLessThan, + "numberlessthanorequals": AdvancedFilterOperatorTypeNumberLessThanOrEquals, + "numbernotin": AdvancedFilterOperatorTypeNumberNotIn, + "numbernotinrange": AdvancedFilterOperatorTypeNumberNotInRange, + "stringbeginswith": AdvancedFilterOperatorTypeStringBeginsWith, + "stringcontains": AdvancedFilterOperatorTypeStringContains, + "stringendswith": AdvancedFilterOperatorTypeStringEndsWith, + "stringin": AdvancedFilterOperatorTypeStringIn, + "stringnotbeginswith": AdvancedFilterOperatorTypeStringNotBeginsWith, + "stringnotcontains": AdvancedFilterOperatorTypeStringNotContains, + "stringnotendswith": AdvancedFilterOperatorTypeStringNotEndsWith, + "stringnotin": AdvancedFilterOperatorTypeStringNotIn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdvancedFilterOperatorType(input) + return &out, nil +} + +type DeadLetterEndPointType string + +const ( + DeadLetterEndPointTypeStorageBlob DeadLetterEndPointType = "StorageBlob" +) + +func PossibleValuesForDeadLetterEndPointType() []string { + return []string{ + string(DeadLetterEndPointTypeStorageBlob), + } +} + +func (s *DeadLetterEndPointType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeadLetterEndPointType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeadLetterEndPointType(input string) (*DeadLetterEndPointType, error) { + vals := map[string]DeadLetterEndPointType{ + "storageblob": DeadLetterEndPointTypeStorageBlob, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeadLetterEndPointType(input) + return &out, nil +} + +type DeliveryAttributeMappingType string + +const ( + DeliveryAttributeMappingTypeDynamic DeliveryAttributeMappingType = "Dynamic" + DeliveryAttributeMappingTypeStatic DeliveryAttributeMappingType = "Static" +) + +func PossibleValuesForDeliveryAttributeMappingType() []string { + return []string{ + string(DeliveryAttributeMappingTypeDynamic), + string(DeliveryAttributeMappingTypeStatic), + } +} + +func (s *DeliveryAttributeMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAttributeMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryAttributeMappingType(input string) (*DeliveryAttributeMappingType, error) { + vals := map[string]DeliveryAttributeMappingType{ + "dynamic": DeliveryAttributeMappingTypeDynamic, + "static": DeliveryAttributeMappingTypeStatic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryAttributeMappingType(input) + return &out, nil +} + +type DeliveryMode string + +const ( + DeliveryModePush DeliveryMode = "Push" + DeliveryModeQueue DeliveryMode = "Queue" +) + +func PossibleValuesForDeliveryMode() []string { + return []string{ + string(DeliveryModePush), + string(DeliveryModeQueue), + } +} + +func (s *DeliveryMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryMode(input string) (*DeliveryMode, error) { + vals := map[string]DeliveryMode{ + "push": DeliveryModePush, + "queue": DeliveryModeQueue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryMode(input) + return &out, nil +} + +type DeliverySchema string + +const ( + DeliverySchemaCloudEventSchemaVOneZero DeliverySchema = "CloudEventSchemaV1_0" +) + +func PossibleValuesForDeliverySchema() []string { + return []string{ + string(DeliverySchemaCloudEventSchemaVOneZero), + } +} + +func (s *DeliverySchema) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliverySchema(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliverySchema(input string) (*DeliverySchema, error) { + vals := map[string]DeliverySchema{ + "cloudeventschemav1_0": DeliverySchemaCloudEventSchemaVOneZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliverySchema(input) + return &out, nil +} + +type EndpointType string + +const ( + EndpointTypeAzureFunction EndpointType = "AzureFunction" + EndpointTypeEventHub EndpointType = "EventHub" + EndpointTypeHybridConnection EndpointType = "HybridConnection" + EndpointTypeMonitorAlert EndpointType = "MonitorAlert" + EndpointTypeNamespaceTopic EndpointType = "NamespaceTopic" + EndpointTypePartnerDestination EndpointType = "PartnerDestination" + EndpointTypeServiceBusQueue EndpointType = "ServiceBusQueue" + EndpointTypeServiceBusTopic EndpointType = "ServiceBusTopic" + EndpointTypeStorageQueue EndpointType = "StorageQueue" + EndpointTypeWebHook EndpointType = "WebHook" +) + +func PossibleValuesForEndpointType() []string { + return []string{ + string(EndpointTypeAzureFunction), + string(EndpointTypeEventHub), + string(EndpointTypeHybridConnection), + string(EndpointTypeMonitorAlert), + string(EndpointTypeNamespaceTopic), + string(EndpointTypePartnerDestination), + string(EndpointTypeServiceBusQueue), + string(EndpointTypeServiceBusTopic), + string(EndpointTypeStorageQueue), + string(EndpointTypeWebHook), + } +} + +func (s *EndpointType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEndpointType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEndpointType(input string) (*EndpointType, error) { + vals := map[string]EndpointType{ + "azurefunction": EndpointTypeAzureFunction, + "eventhub": EndpointTypeEventHub, + "hybridconnection": EndpointTypeHybridConnection, + "monitoralert": EndpointTypeMonitorAlert, + "namespacetopic": EndpointTypeNamespaceTopic, + "partnerdestination": EndpointTypePartnerDestination, + "servicebusqueue": EndpointTypeServiceBusQueue, + "servicebustopic": EndpointTypeServiceBusTopic, + "storagequeue": EndpointTypeStorageQueue, + "webhook": EndpointTypeWebHook, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EndpointType(input) + return &out, nil +} + +type EventDeliverySchema string + +const ( + EventDeliverySchemaCloudEventSchemaVOneZero EventDeliverySchema = "CloudEventSchemaV1_0" + EventDeliverySchemaCustomInputSchema EventDeliverySchema = "CustomInputSchema" + EventDeliverySchemaEventGridSchema EventDeliverySchema = "EventGridSchema" +) + +func PossibleValuesForEventDeliverySchema() []string { + return []string{ + string(EventDeliverySchemaCloudEventSchemaVOneZero), + string(EventDeliverySchemaCustomInputSchema), + string(EventDeliverySchemaEventGridSchema), + } +} + +func (s *EventDeliverySchema) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventDeliverySchema(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventDeliverySchema(input string) (*EventDeliverySchema, error) { + vals := map[string]EventDeliverySchema{ + "cloudeventschemav1_0": EventDeliverySchemaCloudEventSchemaVOneZero, + "custominputschema": EventDeliverySchemaCustomInputSchema, + "eventgridschema": EventDeliverySchemaEventGridSchema, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventDeliverySchema(input) + return &out, nil +} + +type EventSubscriptionIdentityType string + +const ( + EventSubscriptionIdentityTypeSystemAssigned EventSubscriptionIdentityType = "SystemAssigned" + EventSubscriptionIdentityTypeUserAssigned EventSubscriptionIdentityType = "UserAssigned" +) + +func PossibleValuesForEventSubscriptionIdentityType() []string { + return []string{ + string(EventSubscriptionIdentityTypeSystemAssigned), + string(EventSubscriptionIdentityTypeUserAssigned), + } +} + +func (s *EventSubscriptionIdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSubscriptionIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventSubscriptionIdentityType(input string) (*EventSubscriptionIdentityType, error) { + vals := map[string]EventSubscriptionIdentityType{ + "systemassigned": EventSubscriptionIdentityTypeSystemAssigned, + "userassigned": EventSubscriptionIdentityTypeUserAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventSubscriptionIdentityType(input) + return &out, nil +} + +type EventSubscriptionProvisioningState string + +const ( + EventSubscriptionProvisioningStateAwaitingManualAction EventSubscriptionProvisioningState = "AwaitingManualAction" + EventSubscriptionProvisioningStateCanceled EventSubscriptionProvisioningState = "Canceled" + EventSubscriptionProvisioningStateCreating EventSubscriptionProvisioningState = "Creating" + EventSubscriptionProvisioningStateDeleting EventSubscriptionProvisioningState = "Deleting" + EventSubscriptionProvisioningStateFailed EventSubscriptionProvisioningState = "Failed" + EventSubscriptionProvisioningStateSucceeded EventSubscriptionProvisioningState = "Succeeded" + EventSubscriptionProvisioningStateUpdating EventSubscriptionProvisioningState = "Updating" +) + +func PossibleValuesForEventSubscriptionProvisioningState() []string { + return []string{ + string(EventSubscriptionProvisioningStateAwaitingManualAction), + string(EventSubscriptionProvisioningStateCanceled), + string(EventSubscriptionProvisioningStateCreating), + string(EventSubscriptionProvisioningStateDeleting), + string(EventSubscriptionProvisioningStateFailed), + string(EventSubscriptionProvisioningStateSucceeded), + string(EventSubscriptionProvisioningStateUpdating), + } +} + +func (s *EventSubscriptionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSubscriptionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventSubscriptionProvisioningState(input string) (*EventSubscriptionProvisioningState, error) { + vals := map[string]EventSubscriptionProvisioningState{ + "awaitingmanualaction": EventSubscriptionProvisioningStateAwaitingManualAction, + "canceled": EventSubscriptionProvisioningStateCanceled, + "creating": EventSubscriptionProvisioningStateCreating, + "deleting": EventSubscriptionProvisioningStateDeleting, + "failed": EventSubscriptionProvisioningStateFailed, + "succeeded": EventSubscriptionProvisioningStateSucceeded, + "updating": EventSubscriptionProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventSubscriptionProvisioningState(input) + return &out, nil +} + +type FilterOperatorType string + +const ( + FilterOperatorTypeBoolEquals FilterOperatorType = "BoolEquals" + FilterOperatorTypeIsNotNull FilterOperatorType = "IsNotNull" + FilterOperatorTypeIsNullOrUndefined FilterOperatorType = "IsNullOrUndefined" + FilterOperatorTypeNumberGreaterThan FilterOperatorType = "NumberGreaterThan" + FilterOperatorTypeNumberGreaterThanOrEquals FilterOperatorType = "NumberGreaterThanOrEquals" + FilterOperatorTypeNumberIn FilterOperatorType = "NumberIn" + FilterOperatorTypeNumberInRange FilterOperatorType = "NumberInRange" + FilterOperatorTypeNumberLessThan FilterOperatorType = "NumberLessThan" + FilterOperatorTypeNumberLessThanOrEquals FilterOperatorType = "NumberLessThanOrEquals" + FilterOperatorTypeNumberNotIn FilterOperatorType = "NumberNotIn" + FilterOperatorTypeNumberNotInRange FilterOperatorType = "NumberNotInRange" + FilterOperatorTypeStringBeginsWith FilterOperatorType = "StringBeginsWith" + FilterOperatorTypeStringContains FilterOperatorType = "StringContains" + FilterOperatorTypeStringEndsWith FilterOperatorType = "StringEndsWith" + FilterOperatorTypeStringIn FilterOperatorType = "StringIn" + FilterOperatorTypeStringNotBeginsWith FilterOperatorType = "StringNotBeginsWith" + FilterOperatorTypeStringNotContains FilterOperatorType = "StringNotContains" + FilterOperatorTypeStringNotEndsWith FilterOperatorType = "StringNotEndsWith" + FilterOperatorTypeStringNotIn FilterOperatorType = "StringNotIn" +) + +func PossibleValuesForFilterOperatorType() []string { + return []string{ + string(FilterOperatorTypeBoolEquals), + string(FilterOperatorTypeIsNotNull), + string(FilterOperatorTypeIsNullOrUndefined), + string(FilterOperatorTypeNumberGreaterThan), + string(FilterOperatorTypeNumberGreaterThanOrEquals), + string(FilterOperatorTypeNumberIn), + string(FilterOperatorTypeNumberInRange), + string(FilterOperatorTypeNumberLessThan), + string(FilterOperatorTypeNumberLessThanOrEquals), + string(FilterOperatorTypeNumberNotIn), + string(FilterOperatorTypeNumberNotInRange), + string(FilterOperatorTypeStringBeginsWith), + string(FilterOperatorTypeStringContains), + string(FilterOperatorTypeStringEndsWith), + string(FilterOperatorTypeStringIn), + string(FilterOperatorTypeStringNotBeginsWith), + string(FilterOperatorTypeStringNotContains), + string(FilterOperatorTypeStringNotEndsWith), + string(FilterOperatorTypeStringNotIn), + } +} + +func (s *FilterOperatorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFilterOperatorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFilterOperatorType(input string) (*FilterOperatorType, error) { + vals := map[string]FilterOperatorType{ + "boolequals": FilterOperatorTypeBoolEquals, + "isnotnull": FilterOperatorTypeIsNotNull, + "isnullorundefined": FilterOperatorTypeIsNullOrUndefined, + "numbergreaterthan": FilterOperatorTypeNumberGreaterThan, + "numbergreaterthanorequals": FilterOperatorTypeNumberGreaterThanOrEquals, + "numberin": FilterOperatorTypeNumberIn, + "numberinrange": FilterOperatorTypeNumberInRange, + "numberlessthan": FilterOperatorTypeNumberLessThan, + "numberlessthanorequals": FilterOperatorTypeNumberLessThanOrEquals, + "numbernotin": FilterOperatorTypeNumberNotIn, + "numbernotinrange": FilterOperatorTypeNumberNotInRange, + "stringbeginswith": FilterOperatorTypeStringBeginsWith, + "stringcontains": FilterOperatorTypeStringContains, + "stringendswith": FilterOperatorTypeStringEndsWith, + "stringin": FilterOperatorTypeStringIn, + "stringnotbeginswith": FilterOperatorTypeStringNotBeginsWith, + "stringnotcontains": FilterOperatorTypeStringNotContains, + "stringnotendswith": FilterOperatorTypeStringNotEndsWith, + "stringnotin": FilterOperatorTypeStringNotIn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FilterOperatorType(input) + return &out, nil +} + +type MonitorAlertSeverity string + +const ( + MonitorAlertSeveritySevFour MonitorAlertSeverity = "Sev4" + MonitorAlertSeveritySevOne MonitorAlertSeverity = "Sev1" + MonitorAlertSeveritySevThree MonitorAlertSeverity = "Sev3" + MonitorAlertSeveritySevTwo MonitorAlertSeverity = "Sev2" + MonitorAlertSeveritySevZero MonitorAlertSeverity = "Sev0" +) + +func PossibleValuesForMonitorAlertSeverity() []string { + return []string{ + string(MonitorAlertSeveritySevFour), + string(MonitorAlertSeveritySevOne), + string(MonitorAlertSeveritySevThree), + string(MonitorAlertSeveritySevTwo), + string(MonitorAlertSeveritySevZero), + } +} + +func (s *MonitorAlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMonitorAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMonitorAlertSeverity(input string) (*MonitorAlertSeverity, error) { + vals := map[string]MonitorAlertSeverity{ + "sev4": MonitorAlertSeveritySevFour, + "sev1": MonitorAlertSeveritySevOne, + "sev3": MonitorAlertSeveritySevThree, + "sev2": MonitorAlertSeveritySevTwo, + "sev0": MonitorAlertSeveritySevZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MonitorAlertSeverity(input) + return &out, nil +} + +type SubscriptionProvisioningState string + +const ( + SubscriptionProvisioningStateAwaitingManualAction SubscriptionProvisioningState = "AwaitingManualAction" + SubscriptionProvisioningStateCanceled SubscriptionProvisioningState = "Canceled" + SubscriptionProvisioningStateCreateFailed SubscriptionProvisioningState = "CreateFailed" + SubscriptionProvisioningStateCreating SubscriptionProvisioningState = "Creating" + SubscriptionProvisioningStateDeleteFailed SubscriptionProvisioningState = "DeleteFailed" + SubscriptionProvisioningStateDeleted SubscriptionProvisioningState = "Deleted" + SubscriptionProvisioningStateDeleting SubscriptionProvisioningState = "Deleting" + SubscriptionProvisioningStateFailed SubscriptionProvisioningState = "Failed" + SubscriptionProvisioningStateSucceeded SubscriptionProvisioningState = "Succeeded" + SubscriptionProvisioningStateUpdatedFailed SubscriptionProvisioningState = "UpdatedFailed" + SubscriptionProvisioningStateUpdating SubscriptionProvisioningState = "Updating" +) + +func PossibleValuesForSubscriptionProvisioningState() []string { + return []string{ + string(SubscriptionProvisioningStateAwaitingManualAction), + string(SubscriptionProvisioningStateCanceled), + string(SubscriptionProvisioningStateCreateFailed), + string(SubscriptionProvisioningStateCreating), + string(SubscriptionProvisioningStateDeleteFailed), + string(SubscriptionProvisioningStateDeleted), + string(SubscriptionProvisioningStateDeleting), + string(SubscriptionProvisioningStateFailed), + string(SubscriptionProvisioningStateSucceeded), + string(SubscriptionProvisioningStateUpdatedFailed), + string(SubscriptionProvisioningStateUpdating), + } +} + +func (s *SubscriptionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSubscriptionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSubscriptionProvisioningState(input string) (*SubscriptionProvisioningState, error) { + vals := map[string]SubscriptionProvisioningState{ + "awaitingmanualaction": SubscriptionProvisioningStateAwaitingManualAction, + "canceled": SubscriptionProvisioningStateCanceled, + "createfailed": SubscriptionProvisioningStateCreateFailed, + "creating": SubscriptionProvisioningStateCreating, + "deletefailed": SubscriptionProvisioningStateDeleteFailed, + "deleted": SubscriptionProvisioningStateDeleted, + "deleting": SubscriptionProvisioningStateDeleting, + "failed": SubscriptionProvisioningStateFailed, + "succeeded": SubscriptionProvisioningStateSucceeded, + "updatedfailed": SubscriptionProvisioningStateUpdatedFailed, + "updating": SubscriptionProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SubscriptionProvisioningState(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domain.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domain.go new file mode 100644 index 00000000000..cdf7b0df58a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domain.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DomainId{} + +// DomainId is a struct representing the Resource ID for a Domain +type DomainId struct { + SubscriptionId string + ResourceGroupName string + DomainName string +} + +// NewDomainID returns a new DomainId struct +func NewDomainID(subscriptionId string, resourceGroupName string, domainName string) DomainId { + return DomainId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DomainName: domainName, + } +} + +// ParseDomainID parses 'input' into a DomainId +func ParseDomainID(input string) (*DomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDomainIDInsensitively parses 'input' case-insensitively into a DomainId +// note: this method should only be used for API response data and not user input +func ParseDomainIDInsensitively(input string) (*DomainId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DomainId) 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.DomainName, ok = input.Parsed["domainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "domainName", input) + } + + return nil +} + +// ValidateDomainID checks that 'input' can be parsed as a Domain ID +func ValidateDomainID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDomainID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Domain ID +func (id DomainId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/domains/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DomainName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Domain ID +func (id DomainId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticDomains", "domains", "domains"), + resourceids.UserSpecifiedSegment("domainName", "domainValue"), + } +} + +// String returns a human-readable description of this Domain ID +func (id DomainId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Domain Name: %q", id.DomainName), + } + return fmt.Sprintf("Domain (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domain_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domain_test.go new file mode 100644 index 00000000000..1a3ac686bf4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domain_test.go @@ -0,0 +1,282 @@ +package eventsubscriptions + +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 = &DomainId{} + +func TestNewDomainID(t *testing.T) { + id := NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue") + + if id.SubscriptionId != "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.DomainName != "domainValue" { + t.Fatalf("Expected %q but got %q for Segment 'DomainName'", id.DomainName, "domainValue") + } +} + +func TestFormatDomainID(t *testing.T) { + actual := NewDomainID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDomainID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + } +} + +func TestParseDomainIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe", + Expected: &DomainId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DomainName: "dOmAiNvAlUe", + }, + }, + { + // 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.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + } +} + +func TestSegmentsForDomainId(t *testing.T) { + segments := DomainId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DomainId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaineventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaineventsubscription.go new file mode 100644 index 00000000000..1b30cf6e603 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaineventsubscription.go @@ -0,0 +1,134 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DomainEventSubscriptionId{} + +// DomainEventSubscriptionId is a struct representing the Resource ID for a Domain Event Subscription +type DomainEventSubscriptionId struct { + SubscriptionId string + ResourceGroupName string + DomainName string + EventSubscriptionName string +} + +// NewDomainEventSubscriptionID returns a new DomainEventSubscriptionId struct +func NewDomainEventSubscriptionID(subscriptionId string, resourceGroupName string, domainName string, eventSubscriptionName string) DomainEventSubscriptionId { + return DomainEventSubscriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DomainName: domainName, + EventSubscriptionName: eventSubscriptionName, + } +} + +// ParseDomainEventSubscriptionID parses 'input' into a DomainEventSubscriptionId +func ParseDomainEventSubscriptionID(input string) (*DomainEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainEventSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDomainEventSubscriptionIDInsensitively parses 'input' case-insensitively into a DomainEventSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseDomainEventSubscriptionIDInsensitively(input string) (*DomainEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainEventSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DomainEventSubscriptionId) 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.DomainName, ok = input.Parsed["domainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "domainName", input) + } + + if id.EventSubscriptionName, ok = input.Parsed["eventSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "eventSubscriptionName", input) + } + + return nil +} + +// ValidateDomainEventSubscriptionID checks that 'input' can be parsed as a Domain Event Subscription ID +func ValidateDomainEventSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDomainEventSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Domain Event Subscription ID +func (id DomainEventSubscriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/domains/%s/eventSubscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DomainName, id.EventSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Domain Event Subscription ID +func (id DomainEventSubscriptionId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticDomains", "domains", "domains"), + resourceids.UserSpecifiedSegment("domainName", "domainValue"), + resourceids.StaticSegment("staticEventSubscriptions", "eventSubscriptions", "eventSubscriptions"), + resourceids.UserSpecifiedSegment("eventSubscriptionName", "eventSubscriptionValue"), + } +} + +// String returns a human-readable description of this Domain Event Subscription ID +func (id DomainEventSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Domain Name: %q", id.DomainName), + fmt.Sprintf("Event Subscription Name: %q", id.EventSubscriptionName), + } + return fmt.Sprintf("Domain Event Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaineventsubscription_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaineventsubscription_test.go new file mode 100644 index 00000000000..73223485978 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaineventsubscription_test.go @@ -0,0 +1,327 @@ +package eventsubscriptions + +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 = &DomainEventSubscriptionId{} + +func TestNewDomainEventSubscriptionID(t *testing.T) { + id := NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue") + + if id.SubscriptionId != "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.DomainName != "domainValue" { + t.Fatalf("Expected %q but got %q for Segment 'DomainName'", id.DomainName, "domainValue") + } + + if id.EventSubscriptionName != "eventSubscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EventSubscriptionName'", id.EventSubscriptionName, "eventSubscriptionValue") + } +} + +func TestFormatDomainEventSubscriptionID(t *testing.T) { + actual := NewDomainEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "eventSubscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/eventSubscriptions/eventSubscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDomainEventSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/eventSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/eventSubscriptions/eventSubscriptionValue", + Expected: &DomainEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainEventSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestParseDomainEventSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/eventSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/eVeNtSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/eventSubscriptions/eventSubscriptionValue", + Expected: &DomainEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE", + Expected: &DomainEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DomainName: "dOmAiNvAlUe", + EventSubscriptionName: "eVeNtSuBsCrIpTiOnVaLuE", + }, + }, + { + // 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.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainEventSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestSegmentsForDomainEventSubscriptionId(t *testing.T) { + segments := DomainEventSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DomainEventSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaintopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaintopic.go new file mode 100644 index 00000000000..198795d88ba --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaintopic.go @@ -0,0 +1,134 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DomainTopicId{} + +// DomainTopicId is a struct representing the Resource ID for a Domain Topic +type DomainTopicId struct { + SubscriptionId string + ResourceGroupName string + DomainName string + TopicName string +} + +// NewDomainTopicID returns a new DomainTopicId struct +func NewDomainTopicID(subscriptionId string, resourceGroupName string, domainName string, topicName string) DomainTopicId { + return DomainTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DomainName: domainName, + TopicName: topicName, + } +} + +// ParseDomainTopicID parses 'input' into a DomainTopicId +func ParseDomainTopicID(input string) (*DomainTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDomainTopicIDInsensitively parses 'input' case-insensitively into a DomainTopicId +// note: this method should only be used for API response data and not user input +func ParseDomainTopicIDInsensitively(input string) (*DomainTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&DomainTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DomainTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DomainTopicId) 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.DomainName, ok = input.Parsed["domainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "domainName", input) + } + + if id.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + return nil +} + +// ValidateDomainTopicID checks that 'input' can be parsed as a Domain Topic ID +func ValidateDomainTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDomainTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Domain Topic ID +func (id DomainTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/domains/%s/topics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DomainName, id.TopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Domain Topic ID +func (id DomainTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticDomains", "domains", "domains"), + resourceids.UserSpecifiedSegment("domainName", "domainValue"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + } +} + +// String returns a human-readable description of this Domain Topic ID +func (id DomainTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Domain Name: %q", id.DomainName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + } + return fmt.Sprintf("Domain Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaintopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaintopic_test.go new file mode 100644 index 00000000000..8e7a58222d7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_domaintopic_test.go @@ -0,0 +1,327 @@ +package eventsubscriptions + +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 = &DomainTopicId{} + +func TestNewDomainTopicID(t *testing.T) { + id := NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue") + + if id.SubscriptionId != "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.DomainName != "domainValue" { + t.Fatalf("Expected %q but got %q for Segment 'DomainName'", id.DomainName, "domainValue") + } + + if id.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } +} + +func TestFormatDomainTopicID(t *testing.T) { + actual := NewDomainTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDomainTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue", + Expected: &DomainTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestParseDomainTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DomainTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue", + Expected: &DomainTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE", + Expected: &DomainTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DomainName: "dOmAiNvAlUe", + TopicName: "tOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDomainTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestSegmentsForDomainTopicId(t *testing.T) { + segments := DomainTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DomainTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_eventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_eventsubscription.go new file mode 100644 index 00000000000..4fe6543965e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_eventsubscription.go @@ -0,0 +1,134 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &EventSubscriptionId{} + +// EventSubscriptionId is a struct representing the Resource ID for a Event Subscription +type EventSubscriptionId struct { + SubscriptionId string + ResourceGroupName string + TopicName string + EventSubscriptionName string +} + +// NewEventSubscriptionID returns a new EventSubscriptionId struct +func NewEventSubscriptionID(subscriptionId string, resourceGroupName string, topicName string, eventSubscriptionName string) EventSubscriptionId { + return EventSubscriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TopicName: topicName, + EventSubscriptionName: eventSubscriptionName, + } +} + +// ParseEventSubscriptionID parses 'input' into a EventSubscriptionId +func ParseEventSubscriptionID(input string) (*EventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&EventSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEventSubscriptionIDInsensitively parses 'input' case-insensitively into a EventSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseEventSubscriptionIDInsensitively(input string) (*EventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&EventSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EventSubscriptionId) 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.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + if id.EventSubscriptionName, ok = input.Parsed["eventSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "eventSubscriptionName", input) + } + + return nil +} + +// ValidateEventSubscriptionID checks that 'input' can be parsed as a Event Subscription ID +func ValidateEventSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseEventSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Event Subscription ID +func (id EventSubscriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/topics/%s/eventSubscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TopicName, id.EventSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Event Subscription ID +func (id EventSubscriptionId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + resourceids.StaticSegment("staticEventSubscriptions", "eventSubscriptions", "eventSubscriptions"), + resourceids.UserSpecifiedSegment("eventSubscriptionName", "eventSubscriptionValue"), + } +} + +// String returns a human-readable description of this Event Subscription ID +func (id EventSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + fmt.Sprintf("Event Subscription Name: %q", id.EventSubscriptionName), + } + return fmt.Sprintf("Event Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_eventsubscription_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_eventsubscription_test.go new file mode 100644 index 00000000000..324ca60e5e9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_eventsubscription_test.go @@ -0,0 +1,327 @@ +package eventsubscriptions + +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 = &EventSubscriptionId{} + +func TestNewEventSubscriptionID(t *testing.T) { + id := NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue") + + if id.SubscriptionId != "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.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } + + if id.EventSubscriptionName != "eventSubscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EventSubscriptionName'", id.EventSubscriptionName, "eventSubscriptionValue") + } +} + +func TestFormatEventSubscriptionID(t *testing.T) { + actual := NewEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue", "eventSubscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/eventSubscriptions/eventSubscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEventSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/eventSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &EventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicName: "topicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEventSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestParseEventSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS/tOpIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/eventSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &EventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicName: "topicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE", + Expected: &EventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TopicName: "tOpIcVaLuE", + EventSubscriptionName: "eVeNtSuBsCrIpTiOnVaLuE", + }, + }, + { + // 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.eVeNtGrId/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEventSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestSegmentsForEventSubscriptionId(t *testing.T) { + segments := EventSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EventSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_location.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_location.go new file mode 100644 index 00000000000..4ddfe5eb485 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_location.go @@ -0,0 +1,116 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.EventGrid/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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + 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/eventgrid/2023-12-15-preview/eventsubscriptions/id_location_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_location_test.go new file mode 100644 index 00000000000..f6c00a69415 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_location_test.go @@ -0,0 +1,237 @@ +package eventsubscriptions + +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.EventGrid/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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/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.EventGrid/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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/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.EventGrid/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/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.eVeNtGrId/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/eventgrid/2023-12-15-preview/eventsubscriptions/id_locationtopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_locationtopictype.go new file mode 100644 index 00000000000..37caf3a87ab --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_locationtopictype.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &LocationTopicTypeId{} + +// LocationTopicTypeId is a struct representing the Resource ID for a Location Topic Type +type LocationTopicTypeId struct { + SubscriptionId string + LocationName string + TopicTypeName string +} + +// NewLocationTopicTypeID returns a new LocationTopicTypeId struct +func NewLocationTopicTypeID(subscriptionId string, locationName string, topicTypeName string) LocationTopicTypeId { + return LocationTopicTypeId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + TopicTypeName: topicTypeName, + } +} + +// ParseLocationTopicTypeID parses 'input' into a LocationTopicTypeId +func ParseLocationTopicTypeID(input string) (*LocationTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationTopicTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationTopicTypeIDInsensitively parses 'input' case-insensitively into a LocationTopicTypeId +// note: this method should only be used for API response data and not user input +func ParseLocationTopicTypeIDInsensitively(input string) (*LocationTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationTopicTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationTopicTypeId) 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) + } + + if id.TopicTypeName, ok = input.Parsed["topicTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicTypeName", input) + } + + return nil +} + +// ValidateLocationTopicTypeID checks that 'input' can be parsed as a Location Topic Type ID +func ValidateLocationTopicTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLocationTopicTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location Topic Type ID +func (id LocationTopicTypeId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.EventGrid/locations/%s/topicTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.TopicTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location Topic Type ID +func (id LocationTopicTypeId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + resourceids.StaticSegment("staticTopicTypes", "topicTypes", "topicTypes"), + resourceids.UserSpecifiedSegment("topicTypeName", "topicTypeValue"), + } +} + +// String returns a human-readable description of this Location Topic Type ID +func (id LocationTopicTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Topic Type Name: %q", id.TopicTypeName), + } + return fmt.Sprintf("Location Topic Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_locationtopictype_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_locationtopictype_test.go new file mode 100644 index 00000000000..46b67819130 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_locationtopictype_test.go @@ -0,0 +1,282 @@ +package eventsubscriptions + +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 = &LocationTopicTypeId{} + +func TestNewLocationTopicTypeID(t *testing.T) { + id := NewLocationTopicTypeID("12345678-1234-9876-4563-123456789012", "locationValue", "topicTypeValue") + + if id.SubscriptionId != "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") + } + + if id.TopicTypeName != "topicTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicTypeName'", id.TopicTypeName, "topicTypeValue") + } +} + +func TestFormatLocationTopicTypeID(t *testing.T) { + actual := NewLocationTopicTypeID("12345678-1234-9876-4563-123456789012", "locationValue", "topicTypeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationTopicTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue/topicTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue", + Expected: &LocationTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationTopicTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't 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) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestParseLocationTopicTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue/topicTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe/tOpIcTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue", + Expected: &LocationTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe/tOpIcTyPeS/tOpIcTyPeVaLuE", + Expected: &LocationTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + TopicTypeName: "tOpIcTyPeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe/tOpIcTyPeS/tOpIcTyPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationTopicTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't 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) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestSegmentsForLocationTopicTypeId(t *testing.T) { + segments := LocationTopicTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationTopicTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopic.go new file mode 100644 index 00000000000..0fd39839fab --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopic.go @@ -0,0 +1,134 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceTopicId{} + +// NamespaceTopicId is a struct representing the Resource ID for a Namespace Topic +type NamespaceTopicId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + TopicName string +} + +// NewNamespaceTopicID returns a new NamespaceTopicId struct +func NewNamespaceTopicID(subscriptionId string, resourceGroupName string, namespaceName string, topicName string) NamespaceTopicId { + return NamespaceTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + TopicName: topicName, + } +} + +// ParseNamespaceTopicID parses 'input' into a NamespaceTopicId +func ParseNamespaceTopicID(input string) (*NamespaceTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceTopicIDInsensitively parses 'input' case-insensitively into a NamespaceTopicId +// note: this method should only be used for API response data and not user input +func ParseNamespaceTopicIDInsensitively(input string) (*NamespaceTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceTopicId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + return nil +} + +// ValidateNamespaceTopicID checks that 'input' can be parsed as a Namespace Topic ID +func ValidateNamespaceTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace Topic ID +func (id NamespaceTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/topics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.TopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace Topic ID +func (id NamespaceTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + } +} + +// String returns a human-readable description of this Namespace Topic ID +func (id NamespaceTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + } + return fmt.Sprintf("Namespace Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopic_test.go new file mode 100644 index 00000000000..e022f3711fb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopic_test.go @@ -0,0 +1,327 @@ +package eventsubscriptions + +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 = &NamespaceTopicId{} + +func TestNewNamespaceTopicID(t *testing.T) { + id := NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } +} + +func TestFormatNamespaceTopicID(t *testing.T) { + actual := NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue", + Expected: &NamespaceTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestParseNamespaceTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue", + Expected: &NamespaceTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE", + Expected: &NamespaceTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + TopicName: "tOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestSegmentsForNamespaceTopicId(t *testing.T) { + segments := NamespaceTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopiceventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopiceventsubscription.go new file mode 100644 index 00000000000..b67cd603a61 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopiceventsubscription.go @@ -0,0 +1,143 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceTopicEventSubscriptionId{} + +// NamespaceTopicEventSubscriptionId is a struct representing the Resource ID for a Namespace Topic Event Subscription +type NamespaceTopicEventSubscriptionId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + TopicName string + EventSubscriptionName string +} + +// NewNamespaceTopicEventSubscriptionID returns a new NamespaceTopicEventSubscriptionId struct +func NewNamespaceTopicEventSubscriptionID(subscriptionId string, resourceGroupName string, namespaceName string, topicName string, eventSubscriptionName string) NamespaceTopicEventSubscriptionId { + return NamespaceTopicEventSubscriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + TopicName: topicName, + EventSubscriptionName: eventSubscriptionName, + } +} + +// ParseNamespaceTopicEventSubscriptionID parses 'input' into a NamespaceTopicEventSubscriptionId +func ParseNamespaceTopicEventSubscriptionID(input string) (*NamespaceTopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceTopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceTopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceTopicEventSubscriptionIDInsensitively parses 'input' case-insensitively into a NamespaceTopicEventSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseNamespaceTopicEventSubscriptionIDInsensitively(input string) (*NamespaceTopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceTopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceTopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceTopicEventSubscriptionId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + if id.EventSubscriptionName, ok = input.Parsed["eventSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "eventSubscriptionName", input) + } + + return nil +} + +// ValidateNamespaceTopicEventSubscriptionID checks that 'input' can be parsed as a Namespace Topic Event Subscription ID +func ValidateNamespaceTopicEventSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceTopicEventSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace Topic Event Subscription ID +func (id NamespaceTopicEventSubscriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/topics/%s/eventSubscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.TopicName, id.EventSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace Topic Event Subscription ID +func (id NamespaceTopicEventSubscriptionId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + resourceids.StaticSegment("staticEventSubscriptions", "eventSubscriptions", "eventSubscriptions"), + resourceids.UserSpecifiedSegment("eventSubscriptionName", "eventSubscriptionValue"), + } +} + +// String returns a human-readable description of this Namespace Topic Event Subscription ID +func (id NamespaceTopicEventSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + fmt.Sprintf("Event Subscription Name: %q", id.EventSubscriptionName), + } + return fmt.Sprintf("Namespace Topic Event Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopiceventsubscription_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopiceventsubscription_test.go new file mode 100644 index 00000000000..21663554951 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_namespacetopiceventsubscription_test.go @@ -0,0 +1,372 @@ +package eventsubscriptions + +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 = &NamespaceTopicEventSubscriptionId{} + +func TestNewNamespaceTopicEventSubscriptionID(t *testing.T) { + id := NewNamespaceTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue", "eventSubscriptionValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } + + if id.EventSubscriptionName != "eventSubscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EventSubscriptionName'", id.EventSubscriptionName, "eventSubscriptionValue") + } +} + +func TestFormatNamespaceTopicEventSubscriptionID(t *testing.T) { + actual := NewNamespaceTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue", "eventSubscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceTopicEventSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceTopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/eventSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &NamespaceTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicName: "topicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceTopicEventSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestParseNamespaceTopicEventSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceTopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/eventSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &NamespaceTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicName: "topicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE", + Expected: &NamespaceTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + TopicName: "tOpIcVaLuE", + EventSubscriptionName: "eVeNtSuBsCrIpTiOnVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceTopicEventSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestSegmentsForNamespaceTopicEventSubscriptionId(t *testing.T) { + segments := NamespaceTopicEventSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceTopicEventSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopic.go new file mode 100644 index 00000000000..b79b45589d2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopic.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PartnerTopicId{} + +// PartnerTopicId is a struct representing the Resource ID for a Partner Topic +type PartnerTopicId struct { + SubscriptionId string + ResourceGroupName string + PartnerTopicName string +} + +// NewPartnerTopicID returns a new PartnerTopicId struct +func NewPartnerTopicID(subscriptionId string, resourceGroupName string, partnerTopicName string) PartnerTopicId { + return PartnerTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerTopicName: partnerTopicName, + } +} + +// ParsePartnerTopicID parses 'input' into a PartnerTopicId +func ParsePartnerTopicID(input string) (*PartnerTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePartnerTopicIDInsensitively parses 'input' case-insensitively into a PartnerTopicId +// note: this method should only be used for API response data and not user input +func ParsePartnerTopicIDInsensitively(input string) (*PartnerTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PartnerTopicId) 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.PartnerTopicName, ok = input.Parsed["partnerTopicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerTopicName", input) + } + + return nil +} + +// ValidatePartnerTopicID checks that 'input' can be parsed as a Partner Topic ID +func ValidatePartnerTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePartnerTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Partner Topic ID +func (id PartnerTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerTopics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerTopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Partner Topic ID +func (id PartnerTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerTopics", "partnerTopics", "partnerTopics"), + resourceids.UserSpecifiedSegment("partnerTopicName", "partnerTopicValue"), + } +} + +// String returns a human-readable description of this Partner Topic ID +func (id PartnerTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Topic Name: %q", id.PartnerTopicName), + } + return fmt.Sprintf("Partner Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopic_test.go new file mode 100644 index 00000000000..8f209303081 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopic_test.go @@ -0,0 +1,282 @@ +package eventsubscriptions + +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 = &PartnerTopicId{} + +func TestNewPartnerTopicID(t *testing.T) { + id := NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + + if id.SubscriptionId != "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.PartnerTopicName != "partnerTopicValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerTopicName'", id.PartnerTopicName, "partnerTopicValue") + } +} + +func TestFormatPartnerTopicID(t *testing.T) { + actual := NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePartnerTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue", + Expected: &PartnerTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerTopicName: "partnerTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerTopicName != v.Expected.PartnerTopicName { + t.Fatalf("Expected %q but got %q for PartnerTopicName", v.Expected.PartnerTopicName, actual.PartnerTopicName) + } + + } +} + +func TestParsePartnerTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue", + Expected: &PartnerTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerTopicName: "partnerTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe", + Expected: &PartnerTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerTopicName: "pArTnErToPiCvAlUe", + }, + }, + { + // 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.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerTopicName != v.Expected.PartnerTopicName { + t.Fatalf("Expected %q but got %q for PartnerTopicName", v.Expected.PartnerTopicName, actual.PartnerTopicName) + } + + } +} + +func TestSegmentsForPartnerTopicId(t *testing.T) { + segments := PartnerTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PartnerTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopiceventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopiceventsubscription.go new file mode 100644 index 00000000000..51524edd3b6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopiceventsubscription.go @@ -0,0 +1,134 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PartnerTopicEventSubscriptionId{} + +// PartnerTopicEventSubscriptionId is a struct representing the Resource ID for a Partner Topic Event Subscription +type PartnerTopicEventSubscriptionId struct { + SubscriptionId string + ResourceGroupName string + PartnerTopicName string + EventSubscriptionName string +} + +// NewPartnerTopicEventSubscriptionID returns a new PartnerTopicEventSubscriptionId struct +func NewPartnerTopicEventSubscriptionID(subscriptionId string, resourceGroupName string, partnerTopicName string, eventSubscriptionName string) PartnerTopicEventSubscriptionId { + return PartnerTopicEventSubscriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerTopicName: partnerTopicName, + EventSubscriptionName: eventSubscriptionName, + } +} + +// ParsePartnerTopicEventSubscriptionID parses 'input' into a PartnerTopicEventSubscriptionId +func ParsePartnerTopicEventSubscriptionID(input string) (*PartnerTopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerTopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerTopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePartnerTopicEventSubscriptionIDInsensitively parses 'input' case-insensitively into a PartnerTopicEventSubscriptionId +// note: this method should only be used for API response data and not user input +func ParsePartnerTopicEventSubscriptionIDInsensitively(input string) (*PartnerTopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerTopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerTopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PartnerTopicEventSubscriptionId) 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.PartnerTopicName, ok = input.Parsed["partnerTopicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerTopicName", input) + } + + if id.EventSubscriptionName, ok = input.Parsed["eventSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "eventSubscriptionName", input) + } + + return nil +} + +// ValidatePartnerTopicEventSubscriptionID checks that 'input' can be parsed as a Partner Topic Event Subscription ID +func ValidatePartnerTopicEventSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePartnerTopicEventSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Partner Topic Event Subscription ID +func (id PartnerTopicEventSubscriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerTopics/%s/eventSubscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerTopicName, id.EventSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Partner Topic Event Subscription ID +func (id PartnerTopicEventSubscriptionId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerTopics", "partnerTopics", "partnerTopics"), + resourceids.UserSpecifiedSegment("partnerTopicName", "partnerTopicValue"), + resourceids.StaticSegment("staticEventSubscriptions", "eventSubscriptions", "eventSubscriptions"), + resourceids.UserSpecifiedSegment("eventSubscriptionName", "eventSubscriptionValue"), + } +} + +// String returns a human-readable description of this Partner Topic Event Subscription ID +func (id PartnerTopicEventSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Topic Name: %q", id.PartnerTopicName), + fmt.Sprintf("Event Subscription Name: %q", id.EventSubscriptionName), + } + return fmt.Sprintf("Partner Topic Event Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopiceventsubscription_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopiceventsubscription_test.go new file mode 100644 index 00000000000..559c695cc37 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_partnertopiceventsubscription_test.go @@ -0,0 +1,327 @@ +package eventsubscriptions + +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 = &PartnerTopicEventSubscriptionId{} + +func TestNewPartnerTopicEventSubscriptionID(t *testing.T) { + id := NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue") + + if id.SubscriptionId != "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.PartnerTopicName != "partnerTopicValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerTopicName'", id.PartnerTopicName, "partnerTopicValue") + } + + if id.EventSubscriptionName != "eventSubscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EventSubscriptionName'", id.EventSubscriptionName, "eventSubscriptionValue") + } +} + +func TestFormatPartnerTopicEventSubscriptionID(t *testing.T) { + actual := NewPartnerTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue", "eventSubscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/eventSubscriptions/eventSubscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePartnerTopicEventSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerTopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/eventSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &PartnerTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerTopicName: "partnerTopicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerTopicEventSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerTopicName != v.Expected.PartnerTopicName { + t.Fatalf("Expected %q but got %q for PartnerTopicName", v.Expected.PartnerTopicName, actual.PartnerTopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestParsePartnerTopicEventSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerTopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/eventSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe/eVeNtSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &PartnerTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerTopicName: "partnerTopicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE", + Expected: &PartnerTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerTopicName: "pArTnErToPiCvAlUe", + EventSubscriptionName: "eVeNtSuBsCrIpTiOnVaLuE", + }, + }, + { + // 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.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerTopicEventSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerTopicName != v.Expected.PartnerTopicName { + t.Fatalf("Expected %q but got %q for PartnerTopicName", v.Expected.PartnerTopicName, actual.PartnerTopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestSegmentsForPartnerTopicEventSubscriptionId(t *testing.T) { + segments := PartnerTopicEventSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PartnerTopicEventSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocation.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocation.go new file mode 100644 index 00000000000..a49969b1ef9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocation.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocation_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocation_test.go new file mode 100644 index 00000000000..b0602925507 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package eventsubscriptions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocationtopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocationtopictype.go new file mode 100644 index 00000000000..ff5a1b3f360 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocationtopictype.go @@ -0,0 +1,134 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProviderLocationTopicTypeId{} + +// ProviderLocationTopicTypeId is a struct representing the Resource ID for a Provider Location Topic Type +type ProviderLocationTopicTypeId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + TopicTypeName string +} + +// NewProviderLocationTopicTypeID returns a new ProviderLocationTopicTypeId struct +func NewProviderLocationTopicTypeID(subscriptionId string, resourceGroupName string, locationName string, topicTypeName string) ProviderLocationTopicTypeId { + return ProviderLocationTopicTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + TopicTypeName: topicTypeName, + } +} + +// ParseProviderLocationTopicTypeID parses 'input' into a ProviderLocationTopicTypeId +func ParseProviderLocationTopicTypeID(input string) (*ProviderLocationTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationTopicTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationTopicTypeIDInsensitively parses 'input' case-insensitively into a ProviderLocationTopicTypeId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationTopicTypeIDInsensitively(input string) (*ProviderLocationTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationTopicTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationTopicTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.TopicTypeName, ok = input.Parsed["topicTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicTypeName", input) + } + + return nil +} + +// ValidateProviderLocationTopicTypeID checks that 'input' can be parsed as a Provider Location Topic Type ID +func ValidateProviderLocationTopicTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProviderLocationTopicTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location Topic Type ID +func (id ProviderLocationTopicTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/locations/%s/topicTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.TopicTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location Topic Type ID +func (id ProviderLocationTopicTypeId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + resourceids.StaticSegment("staticTopicTypes", "topicTypes", "topicTypes"), + resourceids.UserSpecifiedSegment("topicTypeName", "topicTypeValue"), + } +} + +// String returns a human-readable description of this Provider Location Topic Type ID +func (id ProviderLocationTopicTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Topic Type Name: %q", id.TopicTypeName), + } + return fmt.Sprintf("Provider Location Topic Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocationtopictype_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocationtopictype_test.go new file mode 100644 index 00000000000..7ecd1071b2d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providerlocationtopictype_test.go @@ -0,0 +1,327 @@ +package eventsubscriptions + +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 = &ProviderLocationTopicTypeId{} + +func TestNewProviderLocationTopicTypeID(t *testing.T) { + id := NewProviderLocationTopicTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "topicTypeValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.TopicTypeName != "topicTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicTypeName'", id.TopicTypeName, "topicTypeValue") + } +} + +func TestFormatProviderLocationTopicTypeID(t *testing.T) { + actual := NewProviderLocationTopicTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "topicTypeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationTopicTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/topicTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue", + Expected: &ProviderLocationTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationTopicTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestParseProviderLocationTopicTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/topicTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe/tOpIcTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue", + Expected: &ProviderLocationTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/locations/locationValue/topicTypes/topicTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe/tOpIcTyPeS/tOpIcTyPeVaLuE", + Expected: &ProviderLocationTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + TopicTypeName: "tOpIcTyPeVaLuE", + }, + }, + { + // 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.eVeNtGrId/lOcAtIoNs/lOcAtIoNvAlUe/tOpIcTyPeS/tOpIcTyPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationTopicTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestSegmentsForProviderLocationTopicTypeId(t *testing.T) { + segments := ProviderLocationTopicTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationTopicTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providertopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providertopictype.go new file mode 100644 index 00000000000..f328828b566 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providertopictype.go @@ -0,0 +1,116 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProviderTopicTypeId{} + +// ProviderTopicTypeId is a struct representing the Resource ID for a Provider Topic Type +type ProviderTopicTypeId struct { + SubscriptionId string + TopicTypeName string +} + +// NewProviderTopicTypeID returns a new ProviderTopicTypeId struct +func NewProviderTopicTypeID(subscriptionId string, topicTypeName string) ProviderTopicTypeId { + return ProviderTopicTypeId{ + SubscriptionId: subscriptionId, + TopicTypeName: topicTypeName, + } +} + +// ParseProviderTopicTypeID parses 'input' into a ProviderTopicTypeId +func ParseProviderTopicTypeID(input string) (*ProviderTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderTopicTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderTopicTypeIDInsensitively parses 'input' case-insensitively into a ProviderTopicTypeId +// note: this method should only be used for API response data and not user input +func ParseProviderTopicTypeIDInsensitively(input string) (*ProviderTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderTopicTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderTopicTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.TopicTypeName, ok = input.Parsed["topicTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicTypeName", input) + } + + return nil +} + +// ValidateProviderTopicTypeID checks that 'input' can be parsed as a Provider Topic Type ID +func ValidateProviderTopicTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProviderTopicTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Topic Type ID +func (id ProviderTopicTypeId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.EventGrid/topicTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.TopicTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Topic Type ID +func (id ProviderTopicTypeId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticTopicTypes", "topicTypes", "topicTypes"), + resourceids.UserSpecifiedSegment("topicTypeName", "topicTypeValue"), + } +} + +// String returns a human-readable description of this Provider Topic Type ID +func (id ProviderTopicTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Topic Type Name: %q", id.TopicTypeName), + } + return fmt.Sprintf("Provider Topic Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providertopictype_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providertopictype_test.go new file mode 100644 index 00000000000..066e2bfb037 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_providertopictype_test.go @@ -0,0 +1,237 @@ +package eventsubscriptions + +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 = &ProviderTopicTypeId{} + +func TestNewProviderTopicTypeID(t *testing.T) { + id := NewProviderTopicTypeID("12345678-1234-9876-4563-123456789012", "topicTypeValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.TopicTypeName != "topicTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicTypeName'", id.TopicTypeName, "topicTypeValue") + } +} + +func TestFormatProviderTopicTypeID(t *testing.T) { + actual := NewProviderTopicTypeID("12345678-1234-9876-4563-123456789012", "topicTypeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/topicTypes/topicTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderTopicTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/topicTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/topicTypes/topicTypeValue", + Expected: &ProviderTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/topicTypes/topicTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderTopicTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestParseProviderTopicTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/topicTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/topicTypes/topicTypeValue", + Expected: &ProviderTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.EventGrid/topicTypes/topicTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS/tOpIcTyPeVaLuE", + Expected: &ProviderTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TopicTypeName: "tOpIcTyPeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS/tOpIcTyPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderTopicTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestSegmentsForProviderTopicTypeId(t *testing.T) { + segments := ProviderTopicTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderTopicTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_resourcegroupprovidertopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_resourcegroupprovidertopictype.go new file mode 100644 index 00000000000..e9358a124b2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_resourcegroupprovidertopictype.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ResourceGroupProviderTopicTypeId{} + +// ResourceGroupProviderTopicTypeId is a struct representing the Resource ID for a Resource Group Provider Topic Type +type ResourceGroupProviderTopicTypeId struct { + SubscriptionId string + ResourceGroupName string + TopicTypeName string +} + +// NewResourceGroupProviderTopicTypeID returns a new ResourceGroupProviderTopicTypeId struct +func NewResourceGroupProviderTopicTypeID(subscriptionId string, resourceGroupName string, topicTypeName string) ResourceGroupProviderTopicTypeId { + return ResourceGroupProviderTopicTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TopicTypeName: topicTypeName, + } +} + +// ParseResourceGroupProviderTopicTypeID parses 'input' into a ResourceGroupProviderTopicTypeId +func ParseResourceGroupProviderTopicTypeID(input string) (*ResourceGroupProviderTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupProviderTopicTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupProviderTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResourceGroupProviderTopicTypeIDInsensitively parses 'input' case-insensitively into a ResourceGroupProviderTopicTypeId +// note: this method should only be used for API response data and not user input +func ParseResourceGroupProviderTopicTypeIDInsensitively(input string) (*ResourceGroupProviderTopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupProviderTopicTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupProviderTopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResourceGroupProviderTopicTypeId) 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.TopicTypeName, ok = input.Parsed["topicTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicTypeName", input) + } + + return nil +} + +// ValidateResourceGroupProviderTopicTypeID checks that 'input' can be parsed as a Resource Group Provider Topic Type ID +func ValidateResourceGroupProviderTopicTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseResourceGroupProviderTopicTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Group Provider Topic Type ID +func (id ResourceGroupProviderTopicTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/topicTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TopicTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Group Provider Topic Type ID +func (id ResourceGroupProviderTopicTypeId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticTopicTypes", "topicTypes", "topicTypes"), + resourceids.UserSpecifiedSegment("topicTypeName", "topicTypeValue"), + } +} + +// String returns a human-readable description of this Resource Group Provider Topic Type ID +func (id ResourceGroupProviderTopicTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Topic Type Name: %q", id.TopicTypeName), + } + return fmt.Sprintf("Resource Group Provider Topic Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_resourcegroupprovidertopictype_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_resourcegroupprovidertopictype_test.go new file mode 100644 index 00000000000..01c131dc46e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_resourcegroupprovidertopictype_test.go @@ -0,0 +1,282 @@ +package eventsubscriptions + +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 = &ResourceGroupProviderTopicTypeId{} + +func TestNewResourceGroupProviderTopicTypeID(t *testing.T) { + id := NewResourceGroupProviderTopicTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicTypeValue") + + if id.SubscriptionId != "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.TopicTypeName != "topicTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicTypeName'", id.TopicTypeName, "topicTypeValue") + } +} + +func TestFormatResourceGroupProviderTopicTypeID(t *testing.T) { + actual := NewResourceGroupProviderTopicTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicTypeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topicTypes/topicTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResourceGroupProviderTopicTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupProviderTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topicTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topicTypes/topicTypeValue", + Expected: &ResourceGroupProviderTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topicTypes/topicTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupProviderTopicTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestParseResourceGroupProviderTopicTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupProviderTopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topicTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topicTypes/topicTypeValue", + Expected: &ResourceGroupProviderTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topicTypes/topicTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS/tOpIcTyPeVaLuE", + Expected: &ResourceGroupProviderTopicTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TopicTypeName: "tOpIcTyPeVaLuE", + }, + }, + { + // 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.eVeNtGrId/tOpIcTyPeS/tOpIcTyPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupProviderTopicTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestSegmentsForResourceGroupProviderTopicTypeId(t *testing.T) { + segments := ResourceGroupProviderTopicTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResourceGroupProviderTopicTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_scopedeventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_scopedeventsubscription.go new file mode 100644 index 00000000000..cad200a4ad7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_scopedeventsubscription.go @@ -0,0 +1,115 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedEventSubscriptionId{} + +// ScopedEventSubscriptionId is a struct representing the Resource ID for a Scoped Event Subscription +type ScopedEventSubscriptionId struct { + Scope string + EventSubscriptionName string +} + +// NewScopedEventSubscriptionID returns a new ScopedEventSubscriptionId struct +func NewScopedEventSubscriptionID(scope string, eventSubscriptionName string) ScopedEventSubscriptionId { + return ScopedEventSubscriptionId{ + Scope: scope, + EventSubscriptionName: eventSubscriptionName, + } +} + +// ParseScopedEventSubscriptionID parses 'input' into a ScopedEventSubscriptionId +func ParseScopedEventSubscriptionID(input string) (*ScopedEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedEventSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedEventSubscriptionIDInsensitively parses 'input' case-insensitively into a ScopedEventSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseScopedEventSubscriptionIDInsensitively(input string) (*ScopedEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedEventSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedEventSubscriptionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.EventSubscriptionName, ok = input.Parsed["eventSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "eventSubscriptionName", input) + } + + return nil +} + +// ValidateScopedEventSubscriptionID checks that 'input' can be parsed as a Scoped Event Subscription ID +func ValidateScopedEventSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedEventSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Event Subscription ID +func (id ScopedEventSubscriptionId) ID() string { + fmtString := "/%s/providers/Microsoft.EventGrid/eventSubscriptions/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.EventSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Event Subscription ID +func (id ScopedEventSubscriptionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticEventSubscriptions", "eventSubscriptions", "eventSubscriptions"), + resourceids.UserSpecifiedSegment("eventSubscriptionName", "eventSubscriptionValue"), + } +} + +// String returns a human-readable description of this Scoped Event Subscription ID +func (id ScopedEventSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Event Subscription Name: %q", id.EventSubscriptionName), + } + return fmt.Sprintf("Scoped Event Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_scopedeventsubscription_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_scopedeventsubscription_test.go new file mode 100644 index 00000000000..db53eaeefc1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_scopedeventsubscription_test.go @@ -0,0 +1,222 @@ +package eventsubscriptions + +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 = &ScopedEventSubscriptionId{} + +func TestNewScopedEventSubscriptionID(t *testing.T) { + id := NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.EventSubscriptionName != "eventSubscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EventSubscriptionName'", id.EventSubscriptionName, "eventSubscriptionValue") + } +} + +func TestFormatScopedEventSubscriptionID(t *testing.T) { + actual := NewScopedEventSubscriptionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "eventSubscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid/eventSubscriptions/eventSubscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedEventSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid/eventSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid/eventSubscriptions/eventSubscriptionValue", + Expected: &ScopedEventSubscriptionId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedEventSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestParseScopedEventSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid/eventSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.eVeNtGrId/eVeNtSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid/eventSubscriptions/eventSubscriptionValue", + Expected: &ScopedEventSubscriptionId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.EventGrid/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.eVeNtGrId/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE", + Expected: &ScopedEventSubscriptionId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + EventSubscriptionName: "eVeNtSuBsCrIpTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.eVeNtGrId/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedEventSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestSegmentsForScopedEventSubscriptionId(t *testing.T) { + segments := ScopedEventSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedEventSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopic.go new file mode 100644 index 00000000000..3bf979d9818 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopic.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SystemTopicId{} + +// SystemTopicId is a struct representing the Resource ID for a System Topic +type SystemTopicId struct { + SubscriptionId string + ResourceGroupName string + SystemTopicName string +} + +// NewSystemTopicID returns a new SystemTopicId struct +func NewSystemTopicID(subscriptionId string, resourceGroupName string, systemTopicName string) SystemTopicId { + return SystemTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SystemTopicName: systemTopicName, + } +} + +// ParseSystemTopicID parses 'input' into a SystemTopicId +func ParseSystemTopicID(input string) (*SystemTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&SystemTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SystemTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSystemTopicIDInsensitively parses 'input' case-insensitively into a SystemTopicId +// note: this method should only be used for API response data and not user input +func ParseSystemTopicIDInsensitively(input string) (*SystemTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&SystemTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SystemTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SystemTopicId) 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.SystemTopicName, ok = input.Parsed["systemTopicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "systemTopicName", input) + } + + return nil +} + +// ValidateSystemTopicID checks that 'input' can be parsed as a System Topic ID +func ValidateSystemTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSystemTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted System Topic ID +func (id SystemTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/systemTopics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SystemTopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this System Topic ID +func (id SystemTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticSystemTopics", "systemTopics", "systemTopics"), + resourceids.UserSpecifiedSegment("systemTopicName", "systemTopicValue"), + } +} + +// String returns a human-readable description of this System Topic ID +func (id SystemTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("System Topic Name: %q", id.SystemTopicName), + } + return fmt.Sprintf("System Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopic_test.go new file mode 100644 index 00000000000..9ccf75c9277 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopic_test.go @@ -0,0 +1,282 @@ +package eventsubscriptions + +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 = &SystemTopicId{} + +func TestNewSystemTopicID(t *testing.T) { + id := NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue") + + if id.SubscriptionId != "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.SystemTopicName != "systemTopicValue" { + t.Fatalf("Expected %q but got %q for Segment 'SystemTopicName'", id.SystemTopicName, "systemTopicValue") + } +} + +func TestFormatSystemTopicID(t *testing.T) { + actual := NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSystemTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SystemTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue", + Expected: &SystemTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SystemTopicName: "systemTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSystemTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SystemTopicName != v.Expected.SystemTopicName { + t.Fatalf("Expected %q but got %q for SystemTopicName", v.Expected.SystemTopicName, actual.SystemTopicName) + } + + } +} + +func TestParseSystemTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SystemTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue", + Expected: &SystemTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SystemTopicName: "systemTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE", + Expected: &SystemTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SystemTopicName: "sYsTeMtOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSystemTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SystemTopicName != v.Expected.SystemTopicName { + t.Fatalf("Expected %q but got %q for SystemTopicName", v.Expected.SystemTopicName, actual.SystemTopicName) + } + + } +} + +func TestSegmentsForSystemTopicId(t *testing.T) { + segments := SystemTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SystemTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopiceventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopiceventsubscription.go new file mode 100644 index 00000000000..2ff173509a0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopiceventsubscription.go @@ -0,0 +1,134 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SystemTopicEventSubscriptionId{} + +// SystemTopicEventSubscriptionId is a struct representing the Resource ID for a System Topic Event Subscription +type SystemTopicEventSubscriptionId struct { + SubscriptionId string + ResourceGroupName string + SystemTopicName string + EventSubscriptionName string +} + +// NewSystemTopicEventSubscriptionID returns a new SystemTopicEventSubscriptionId struct +func NewSystemTopicEventSubscriptionID(subscriptionId string, resourceGroupName string, systemTopicName string, eventSubscriptionName string) SystemTopicEventSubscriptionId { + return SystemTopicEventSubscriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SystemTopicName: systemTopicName, + EventSubscriptionName: eventSubscriptionName, + } +} + +// ParseSystemTopicEventSubscriptionID parses 'input' into a SystemTopicEventSubscriptionId +func ParseSystemTopicEventSubscriptionID(input string) (*SystemTopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&SystemTopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SystemTopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSystemTopicEventSubscriptionIDInsensitively parses 'input' case-insensitively into a SystemTopicEventSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseSystemTopicEventSubscriptionIDInsensitively(input string) (*SystemTopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&SystemTopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SystemTopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SystemTopicEventSubscriptionId) 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.SystemTopicName, ok = input.Parsed["systemTopicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "systemTopicName", input) + } + + if id.EventSubscriptionName, ok = input.Parsed["eventSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "eventSubscriptionName", input) + } + + return nil +} + +// ValidateSystemTopicEventSubscriptionID checks that 'input' can be parsed as a System Topic Event Subscription ID +func ValidateSystemTopicEventSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSystemTopicEventSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted System Topic Event Subscription ID +func (id SystemTopicEventSubscriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/systemTopics/%s/eventSubscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SystemTopicName, id.EventSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this System Topic Event Subscription ID +func (id SystemTopicEventSubscriptionId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticSystemTopics", "systemTopics", "systemTopics"), + resourceids.UserSpecifiedSegment("systemTopicName", "systemTopicValue"), + resourceids.StaticSegment("staticEventSubscriptions", "eventSubscriptions", "eventSubscriptions"), + resourceids.UserSpecifiedSegment("eventSubscriptionName", "eventSubscriptionValue"), + } +} + +// String returns a human-readable description of this System Topic Event Subscription ID +func (id SystemTopicEventSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("System Topic Name: %q", id.SystemTopicName), + fmt.Sprintf("Event Subscription Name: %q", id.EventSubscriptionName), + } + return fmt.Sprintf("System Topic Event Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopiceventsubscription_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopiceventsubscription_test.go new file mode 100644 index 00000000000..c51c16f82e4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_systemtopiceventsubscription_test.go @@ -0,0 +1,327 @@ +package eventsubscriptions + +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 = &SystemTopicEventSubscriptionId{} + +func TestNewSystemTopicEventSubscriptionID(t *testing.T) { + id := NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue") + + if id.SubscriptionId != "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.SystemTopicName != "systemTopicValue" { + t.Fatalf("Expected %q but got %q for Segment 'SystemTopicName'", id.SystemTopicName, "systemTopicValue") + } + + if id.EventSubscriptionName != "eventSubscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EventSubscriptionName'", id.EventSubscriptionName, "eventSubscriptionValue") + } +} + +func TestFormatSystemTopicEventSubscriptionID(t *testing.T) { + actual := NewSystemTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue", "eventSubscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/eventSubscriptions/eventSubscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSystemTopicEventSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SystemTopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/eventSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &SystemTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SystemTopicName: "systemTopicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSystemTopicEventSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SystemTopicName != v.Expected.SystemTopicName { + t.Fatalf("Expected %q but got %q for SystemTopicName", v.Expected.SystemTopicName, actual.SystemTopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestParseSystemTopicEventSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SystemTopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/eventSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE/eVeNtSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &SystemTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SystemTopicName: "systemTopicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE", + Expected: &SystemTopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SystemTopicName: "sYsTeMtOpIcVaLuE", + EventSubscriptionName: "eVeNtSuBsCrIpTiOnVaLuE", + }, + }, + { + // 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.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSystemTopicEventSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SystemTopicName != v.Expected.SystemTopicName { + t.Fatalf("Expected %q but got %q for SystemTopicName", v.Expected.SystemTopicName, actual.SystemTopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestSegmentsForSystemTopicEventSubscriptionId(t *testing.T) { + segments := SystemTopicEventSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SystemTopicEventSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topic.go new file mode 100644 index 00000000000..3f918fd8b13 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topic.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TopicId{} + +// TopicId is a struct representing the Resource ID for a Topic +type TopicId struct { + SubscriptionId string + ResourceGroupName string + TopicName string +} + +// NewTopicID returns a new TopicId struct +func NewTopicID(subscriptionId string, resourceGroupName string, topicName string) TopicId { + return TopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TopicName: topicName, + } +} + +// ParseTopicID parses 'input' into a TopicId +func ParseTopicID(input string) (*TopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTopicIDInsensitively parses 'input' case-insensitively into a TopicId +// note: this method should only be used for API response data and not user input +func ParseTopicIDInsensitively(input string) (*TopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TopicId) 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.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + return nil +} + +// ValidateTopicID checks that 'input' can be parsed as a Topic ID +func ValidateTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Topic ID +func (id TopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/topics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Topic ID +func (id TopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + } +} + +// String returns a human-readable description of this Topic ID +func (id TopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + } + return fmt.Sprintf("Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topic_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topic_test.go new file mode 100644 index 00000000000..88183f553e8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topic_test.go @@ -0,0 +1,282 @@ +package eventsubscriptions + +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 = &TopicId{} + +func TestNewTopicID(t *testing.T) { + id := NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + + if id.SubscriptionId != "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.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } +} + +func TestFormatTopicID(t *testing.T) { + actual := NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue", + Expected: &TopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestParseTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue", + Expected: &TopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS/tOpIcVaLuE", + Expected: &TopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TopicName: "tOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/tOpIcS/tOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestSegmentsForTopicId(t *testing.T) { + segments := TopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topiceventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topiceventsubscription.go new file mode 100644 index 00000000000..6876f153c12 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topiceventsubscription.go @@ -0,0 +1,143 @@ +package eventsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TopicEventSubscriptionId{} + +// TopicEventSubscriptionId is a struct representing the Resource ID for a Topic Event Subscription +type TopicEventSubscriptionId struct { + SubscriptionId string + ResourceGroupName string + DomainName string + TopicName string + EventSubscriptionName string +} + +// NewTopicEventSubscriptionID returns a new TopicEventSubscriptionId struct +func NewTopicEventSubscriptionID(subscriptionId string, resourceGroupName string, domainName string, topicName string, eventSubscriptionName string) TopicEventSubscriptionId { + return TopicEventSubscriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DomainName: domainName, + TopicName: topicName, + EventSubscriptionName: eventSubscriptionName, + } +} + +// ParseTopicEventSubscriptionID parses 'input' into a TopicEventSubscriptionId +func ParseTopicEventSubscriptionID(input string) (*TopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTopicEventSubscriptionIDInsensitively parses 'input' case-insensitively into a TopicEventSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseTopicEventSubscriptionIDInsensitively(input string) (*TopicEventSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicEventSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicEventSubscriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TopicEventSubscriptionId) 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.DomainName, ok = input.Parsed["domainName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "domainName", input) + } + + if id.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + if id.EventSubscriptionName, ok = input.Parsed["eventSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "eventSubscriptionName", input) + } + + return nil +} + +// ValidateTopicEventSubscriptionID checks that 'input' can be parsed as a Topic Event Subscription ID +func ValidateTopicEventSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTopicEventSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Topic Event Subscription ID +func (id TopicEventSubscriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/domains/%s/topics/%s/eventSubscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DomainName, id.TopicName, id.EventSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Topic Event Subscription ID +func (id TopicEventSubscriptionId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticDomains", "domains", "domains"), + resourceids.UserSpecifiedSegment("domainName", "domainValue"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + resourceids.StaticSegment("staticEventSubscriptions", "eventSubscriptions", "eventSubscriptions"), + resourceids.UserSpecifiedSegment("eventSubscriptionName", "eventSubscriptionValue"), + } +} + +// String returns a human-readable description of this Topic Event Subscription ID +func (id TopicEventSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Domain Name: %q", id.DomainName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + fmt.Sprintf("Event Subscription Name: %q", id.EventSubscriptionName), + } + return fmt.Sprintf("Topic Event Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topiceventsubscription_test.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topiceventsubscription_test.go new file mode 100644 index 00000000000..7ad3392dbda --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/id_topiceventsubscription_test.go @@ -0,0 +1,372 @@ +package eventsubscriptions + +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 = &TopicEventSubscriptionId{} + +func TestNewTopicEventSubscriptionID(t *testing.T) { + id := NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue") + + if id.SubscriptionId != "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.DomainName != "domainValue" { + t.Fatalf("Expected %q but got %q for Segment 'DomainName'", id.DomainName, "domainValue") + } + + if id.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } + + if id.EventSubscriptionName != "eventSubscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EventSubscriptionName'", id.EventSubscriptionName, "eventSubscriptionValue") + } +} + +func TestFormatTopicEventSubscriptionID(t *testing.T) { + actual := NewTopicEventSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "domainValue", "topicValue", "eventSubscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTopicEventSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/eventSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &TopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + TopicName: "topicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicEventSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestParseTopicEventSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicEventSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/eventSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue", + Expected: &TopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DomainName: "domainValue", + TopicName: "topicValue", + EventSubscriptionName: "eventSubscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/domains/domainValue/topics/topicValue/eventSubscriptions/eventSubscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE", + Expected: &TopicEventSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DomainName: "dOmAiNvAlUe", + TopicName: "tOpIcVaLuE", + EventSubscriptionName: "eVeNtSuBsCrIpTiOnVaLuE", + }, + }, + { + // 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.eVeNtGrId/dOmAiNs/dOmAiNvAlUe/tOpIcS/tOpIcVaLuE/eVeNtSuBsCrIpTiOnS/eVeNtSuBsCrIpTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicEventSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DomainName != v.Expected.DomainName { + t.Fatalf("Expected %q but got %q for DomainName", v.Expected.DomainName, actual.DomainName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + if actual.EventSubscriptionName != v.Expected.EventSubscriptionName { + t.Fatalf("Expected %q but got %q for EventSubscriptionName", v.Expected.EventSubscriptionName, actual.EventSubscriptionName) + } + + } +} + +func TestSegmentsForTopicEventSubscriptionId(t *testing.T) { + segments := TopicEventSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TopicEventSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_createorupdate.go new file mode 100644 index 00000000000..538e180aeee --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_createorupdate.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 *EventSubscription +} + +// CreateOrUpdate ... +func (c EventSubscriptionsClient) CreateOrUpdate(ctx context.Context, id ScopedEventSubscriptionId, input EventSubscription) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c EventSubscriptionsClient) CreateOrUpdateThenPoll(ctx context.Context, id ScopedEventSubscriptionId, input EventSubscription) 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/eventgrid/2023-12-15-preview/eventsubscriptions/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_delete.go new file mode 100644 index 00000000000..4e1aaab3a40 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_delete.go @@ -0,0 +1,71 @@ +package eventsubscriptions + +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 EventSubscriptionsClient) Delete(ctx context.Context, id ScopedEventSubscriptionId) (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 EventSubscriptionsClient) DeleteThenPoll(ctx context.Context, id ScopedEventSubscriptionId) 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/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionscreateorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionscreateorupdate.go new file mode 100644 index 00000000000..d4977283093 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionscreateorupdate.go @@ -0,0 +1,75 @@ +package eventsubscriptions + +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 DomainEventSubscriptionsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// DomainEventSubscriptionsCreateOrUpdate ... +func (c EventSubscriptionsClient) DomainEventSubscriptionsCreateOrUpdate(ctx context.Context, id DomainEventSubscriptionId, input EventSubscription) (result DomainEventSubscriptionsCreateOrUpdateOperationResponse, 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 +} + +// DomainEventSubscriptionsCreateOrUpdateThenPoll performs DomainEventSubscriptionsCreateOrUpdate then polls until it's completed +func (c EventSubscriptionsClient) DomainEventSubscriptionsCreateOrUpdateThenPoll(ctx context.Context, id DomainEventSubscriptionId, input EventSubscription) error { + result, err := c.DomainEventSubscriptionsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DomainEventSubscriptionsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DomainEventSubscriptionsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsdelete.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsdelete.go new file mode 100644 index 00000000000..0533257f108 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsdelete.go @@ -0,0 +1,71 @@ +package eventsubscriptions + +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 DomainEventSubscriptionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DomainEventSubscriptionsDelete ... +func (c EventSubscriptionsClient) DomainEventSubscriptionsDelete(ctx context.Context, id DomainEventSubscriptionId) (result DomainEventSubscriptionsDeleteOperationResponse, 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 +} + +// DomainEventSubscriptionsDeleteThenPoll performs DomainEventSubscriptionsDelete then polls until it's completed +func (c EventSubscriptionsClient) DomainEventSubscriptionsDeleteThenPoll(ctx context.Context, id DomainEventSubscriptionId) error { + result, err := c.DomainEventSubscriptionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing DomainEventSubscriptionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DomainEventSubscriptionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsget.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsget.go new file mode 100644 index 00000000000..fc4a22816c7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsget.go @@ -0,0 +1,54 @@ +package eventsubscriptions + +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 DomainEventSubscriptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// DomainEventSubscriptionsGet ... +func (c EventSubscriptionsClient) DomainEventSubscriptionsGet(ctx context.Context, id DomainEventSubscriptionId) (result DomainEventSubscriptionsGetOperationResponse, 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 EventSubscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsgetdeliveryattributes.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsgetdeliveryattributes.go new file mode 100644 index 00000000000..43be5abe0f1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsgetdeliveryattributes.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 DomainEventSubscriptionsGetDeliveryAttributesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeliveryAttributeListResult +} + +// DomainEventSubscriptionsGetDeliveryAttributes ... +func (c EventSubscriptionsClient) DomainEventSubscriptionsGetDeliveryAttributes(ctx context.Context, id DomainEventSubscriptionId) (result DomainEventSubscriptionsGetDeliveryAttributesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDeliveryAttributes", 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 DeliveryAttributeListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsgetfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsgetfullurl.go new file mode 100644 index 00000000000..9ae6056e572 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsgetfullurl.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 DomainEventSubscriptionsGetFullUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscriptionFullUrl +} + +// DomainEventSubscriptionsGetFullUrl ... +func (c EventSubscriptionsClient) DomainEventSubscriptionsGetFullUrl(ctx context.Context, id DomainEventSubscriptionId) (result DomainEventSubscriptionsGetFullUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getFullUrl", 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 EventSubscriptionFullUrl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionslist.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionslist.go new file mode 100644 index 00000000000..170e2d45e78 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionslist.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 DomainEventSubscriptionsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type DomainEventSubscriptionsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type DomainEventSubscriptionsListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultDomainEventSubscriptionsListOperationOptions() DomainEventSubscriptionsListOperationOptions { + return DomainEventSubscriptionsListOperationOptions{} +} + +func (o DomainEventSubscriptionsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DomainEventSubscriptionsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DomainEventSubscriptionsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// DomainEventSubscriptionsList ... +func (c EventSubscriptionsClient) DomainEventSubscriptionsList(ctx context.Context, id DomainId, options DomainEventSubscriptionsListOperationOptions) (result DomainEventSubscriptionsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DomainEventSubscriptionsListComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) DomainEventSubscriptionsListComplete(ctx context.Context, id DomainId, options DomainEventSubscriptionsListOperationOptions) (DomainEventSubscriptionsListCompleteResult, error) { + return c.DomainEventSubscriptionsListCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// DomainEventSubscriptionsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) DomainEventSubscriptionsListCompleteMatchingPredicate(ctx context.Context, id DomainId, options DomainEventSubscriptionsListOperationOptions, predicate EventSubscriptionOperationPredicate) (result DomainEventSubscriptionsListCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.DomainEventSubscriptionsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DomainEventSubscriptionsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsupdate.go new file mode 100644 index 00000000000..c8c4a84d8be --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaineventsubscriptionsupdate.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 DomainEventSubscriptionsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// DomainEventSubscriptionsUpdate ... +func (c EventSubscriptionsClient) DomainEventSubscriptionsUpdate(ctx context.Context, id DomainEventSubscriptionId, input EventSubscriptionUpdateParameters) (result DomainEventSubscriptionsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 +} + +// DomainEventSubscriptionsUpdateThenPoll performs DomainEventSubscriptionsUpdate then polls until it's completed +func (c EventSubscriptionsClient) DomainEventSubscriptionsUpdateThenPoll(ctx context.Context, id DomainEventSubscriptionId, input EventSubscriptionUpdateParameters) error { + result, err := c.DomainEventSubscriptionsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DomainEventSubscriptionsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DomainEventSubscriptionsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionscreateorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionscreateorupdate.go new file mode 100644 index 00000000000..f0b845ca30e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionscreateorupdate.go @@ -0,0 +1,75 @@ +package eventsubscriptions + +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 DomainTopicEventSubscriptionsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// DomainTopicEventSubscriptionsCreateOrUpdate ... +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsCreateOrUpdate(ctx context.Context, id TopicEventSubscriptionId, input EventSubscription) (result DomainTopicEventSubscriptionsCreateOrUpdateOperationResponse, 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 +} + +// DomainTopicEventSubscriptionsCreateOrUpdateThenPoll performs DomainTopicEventSubscriptionsCreateOrUpdate then polls until it's completed +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx context.Context, id TopicEventSubscriptionId, input EventSubscription) error { + result, err := c.DomainTopicEventSubscriptionsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DomainTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DomainTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsdelete.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsdelete.go new file mode 100644 index 00000000000..b8717ea5eb2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsdelete.go @@ -0,0 +1,71 @@ +package eventsubscriptions + +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 DomainTopicEventSubscriptionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DomainTopicEventSubscriptionsDelete ... +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsDelete(ctx context.Context, id TopicEventSubscriptionId) (result DomainTopicEventSubscriptionsDeleteOperationResponse, 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 +} + +// DomainTopicEventSubscriptionsDeleteThenPoll performs DomainTopicEventSubscriptionsDelete then polls until it's completed +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsDeleteThenPoll(ctx context.Context, id TopicEventSubscriptionId) error { + result, err := c.DomainTopicEventSubscriptionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing DomainTopicEventSubscriptionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DomainTopicEventSubscriptionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsget.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsget.go new file mode 100644 index 00000000000..81fcdc52e47 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsget.go @@ -0,0 +1,54 @@ +package eventsubscriptions + +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 DomainTopicEventSubscriptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// DomainTopicEventSubscriptionsGet ... +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsGet(ctx context.Context, id TopicEventSubscriptionId) (result DomainTopicEventSubscriptionsGetOperationResponse, 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 EventSubscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsgetdeliveryattributes.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsgetdeliveryattributes.go new file mode 100644 index 00000000000..e86151c60ea --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsgetdeliveryattributes.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 DomainTopicEventSubscriptionsGetDeliveryAttributesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeliveryAttributeListResult +} + +// DomainTopicEventSubscriptionsGetDeliveryAttributes ... +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsGetDeliveryAttributes(ctx context.Context, id TopicEventSubscriptionId) (result DomainTopicEventSubscriptionsGetDeliveryAttributesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDeliveryAttributes", 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 DeliveryAttributeListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsgetfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsgetfullurl.go new file mode 100644 index 00000000000..f2c901e3055 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsgetfullurl.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 DomainTopicEventSubscriptionsGetFullUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscriptionFullUrl +} + +// DomainTopicEventSubscriptionsGetFullUrl ... +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsGetFullUrl(ctx context.Context, id TopicEventSubscriptionId) (result DomainTopicEventSubscriptionsGetFullUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getFullUrl", 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 EventSubscriptionFullUrl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionslist.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionslist.go new file mode 100644 index 00000000000..61e80bc114d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionslist.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 DomainTopicEventSubscriptionsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type DomainTopicEventSubscriptionsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type DomainTopicEventSubscriptionsListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultDomainTopicEventSubscriptionsListOperationOptions() DomainTopicEventSubscriptionsListOperationOptions { + return DomainTopicEventSubscriptionsListOperationOptions{} +} + +func (o DomainTopicEventSubscriptionsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DomainTopicEventSubscriptionsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DomainTopicEventSubscriptionsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// DomainTopicEventSubscriptionsList ... +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsList(ctx context.Context, id DomainTopicId, options DomainTopicEventSubscriptionsListOperationOptions) (result DomainTopicEventSubscriptionsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DomainTopicEventSubscriptionsListComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsListComplete(ctx context.Context, id DomainTopicId, options DomainTopicEventSubscriptionsListOperationOptions) (DomainTopicEventSubscriptionsListCompleteResult, error) { + return c.DomainTopicEventSubscriptionsListCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// DomainTopicEventSubscriptionsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsListCompleteMatchingPredicate(ctx context.Context, id DomainTopicId, options DomainTopicEventSubscriptionsListOperationOptions, predicate EventSubscriptionOperationPredicate) (result DomainTopicEventSubscriptionsListCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.DomainTopicEventSubscriptionsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DomainTopicEventSubscriptionsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsupdate.go new file mode 100644 index 00000000000..7ad436f6c0b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_domaintopiceventsubscriptionsupdate.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 DomainTopicEventSubscriptionsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// DomainTopicEventSubscriptionsUpdate ... +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsUpdate(ctx context.Context, id TopicEventSubscriptionId, input EventSubscriptionUpdateParameters) (result DomainTopicEventSubscriptionsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 +} + +// DomainTopicEventSubscriptionsUpdateThenPoll performs DomainTopicEventSubscriptionsUpdate then polls until it's completed +func (c EventSubscriptionsClient) DomainTopicEventSubscriptionsUpdateThenPoll(ctx context.Context, id TopicEventSubscriptionId, input EventSubscriptionUpdateParameters) error { + result, err := c.DomainTopicEventSubscriptionsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DomainTopicEventSubscriptionsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DomainTopicEventSubscriptionsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_get.go new file mode 100644 index 00000000000..8f4e1bb89cf --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_get.go @@ -0,0 +1,54 @@ +package eventsubscriptions + +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 *EventSubscription +} + +// Get ... +func (c EventSubscriptionsClient) Get(ctx context.Context, id ScopedEventSubscriptionId) (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 EventSubscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_getdeliveryattributes.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_getdeliveryattributes.go new file mode 100644 index 00000000000..07b422dfe34 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_getdeliveryattributes.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 GetDeliveryAttributesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeliveryAttributeListResult +} + +// GetDeliveryAttributes ... +func (c EventSubscriptionsClient) GetDeliveryAttributes(ctx context.Context, id ScopedEventSubscriptionId) (result GetDeliveryAttributesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDeliveryAttributes", 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 DeliveryAttributeListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_getfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_getfullurl.go new file mode 100644 index 00000000000..e86dc536f30 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_getfullurl.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 GetFullUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscriptionFullUrl +} + +// GetFullUrl ... +func (c EventSubscriptionsClient) GetFullUrl(ctx context.Context, id ScopedEventSubscriptionId) (result GetFullUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getFullUrl", 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 EventSubscriptionFullUrl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listbydomaintopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listbydomaintopic.go new file mode 100644 index 00000000000..8099f2ba3b3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listbydomaintopic.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 ListByDomainTopicOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListByDomainTopicCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListByDomainTopicOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByDomainTopicOperationOptions() ListByDomainTopicOperationOptions { + return ListByDomainTopicOperationOptions{} +} + +func (o ListByDomainTopicOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDomainTopicOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByDomainTopicOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByDomainTopic ... +func (c EventSubscriptionsClient) ListByDomainTopic(ctx context.Context, id DomainTopicId, options ListByDomainTopicOperationOptions) (result ListByDomainTopicOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDomainTopicComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListByDomainTopicComplete(ctx context.Context, id DomainTopicId, options ListByDomainTopicOperationOptions) (ListByDomainTopicCompleteResult, error) { + return c.ListByDomainTopicCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListByDomainTopicCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListByDomainTopicCompleteMatchingPredicate(ctx context.Context, id DomainTopicId, options ListByDomainTopicOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListByDomainTopicCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListByDomainTopic(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDomainTopicCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listbyresource.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listbyresource.go new file mode 100644 index 00000000000..86d78d6cf41 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listbyresource.go @@ -0,0 +1,124 @@ +package eventsubscriptions + +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 ListByResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListByResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListByResourceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceOperationOptions() ListByResourceOperationOptions { + return ListByResourceOperationOptions{} +} + +func (o ListByResourceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResource ... +func (c EventSubscriptionsClient) ListByResource(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions) (result ListByResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListByResourceComplete(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions) (ListByResourceCompleteResult, error) { + return c.ListByResourceCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListByResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListByResourceCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListByResourceCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListByResource(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbyresourcegroup.go new file mode 100644 index 00000000000..91291bfe7e1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbyresourcegroup.go @@ -0,0 +1,124 @@ +package eventsubscriptions + +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 ListGlobalByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListGlobalByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListGlobalByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListGlobalByResourceGroupOperationOptions() ListGlobalByResourceGroupOperationOptions { + return ListGlobalByResourceGroupOperationOptions{} +} + +func (o ListGlobalByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListGlobalByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListGlobalByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListGlobalByResourceGroup ... +func (c EventSubscriptionsClient) ListGlobalByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListGlobalByResourceGroupOperationOptions) (result ListGlobalByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListGlobalByResourceGroupComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListGlobalByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListGlobalByResourceGroupOperationOptions) (ListGlobalByResourceGroupCompleteResult, error) { + return c.ListGlobalByResourceGroupCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListGlobalByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListGlobalByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListGlobalByResourceGroupOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListGlobalByResourceGroupCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListGlobalByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListGlobalByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbyresourcegroupfortopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbyresourcegroupfortopictype.go new file mode 100644 index 00000000000..ddc56a51b5b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbyresourcegroupfortopictype.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 ListGlobalByResourceGroupForTopicTypeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListGlobalByResourceGroupForTopicTypeCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListGlobalByResourceGroupForTopicTypeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListGlobalByResourceGroupForTopicTypeOperationOptions() ListGlobalByResourceGroupForTopicTypeOperationOptions { + return ListGlobalByResourceGroupForTopicTypeOperationOptions{} +} + +func (o ListGlobalByResourceGroupForTopicTypeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListGlobalByResourceGroupForTopicTypeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListGlobalByResourceGroupForTopicTypeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListGlobalByResourceGroupForTopicType ... +func (c EventSubscriptionsClient) ListGlobalByResourceGroupForTopicType(ctx context.Context, id ResourceGroupProviderTopicTypeId, options ListGlobalByResourceGroupForTopicTypeOperationOptions) (result ListGlobalByResourceGroupForTopicTypeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListGlobalByResourceGroupForTopicTypeComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListGlobalByResourceGroupForTopicTypeComplete(ctx context.Context, id ResourceGroupProviderTopicTypeId, options ListGlobalByResourceGroupForTopicTypeOperationOptions) (ListGlobalByResourceGroupForTopicTypeCompleteResult, error) { + return c.ListGlobalByResourceGroupForTopicTypeCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListGlobalByResourceGroupForTopicTypeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListGlobalByResourceGroupForTopicTypeCompleteMatchingPredicate(ctx context.Context, id ResourceGroupProviderTopicTypeId, options ListGlobalByResourceGroupForTopicTypeOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListGlobalByResourceGroupForTopicTypeCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListGlobalByResourceGroupForTopicType(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListGlobalByResourceGroupForTopicTypeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbysubscription.go new file mode 100644 index 00000000000..eb1c3708fd5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbysubscription.go @@ -0,0 +1,124 @@ +package eventsubscriptions + +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 ListGlobalBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListGlobalBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListGlobalBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListGlobalBySubscriptionOperationOptions() ListGlobalBySubscriptionOperationOptions { + return ListGlobalBySubscriptionOperationOptions{} +} + +func (o ListGlobalBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListGlobalBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListGlobalBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListGlobalBySubscription ... +func (c EventSubscriptionsClient) ListGlobalBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListGlobalBySubscriptionOperationOptions) (result ListGlobalBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListGlobalBySubscriptionComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListGlobalBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListGlobalBySubscriptionOperationOptions) (ListGlobalBySubscriptionCompleteResult, error) { + return c.ListGlobalBySubscriptionCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListGlobalBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListGlobalBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListGlobalBySubscriptionOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListGlobalBySubscriptionCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListGlobalBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListGlobalBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbysubscriptionfortopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbysubscriptionfortopictype.go new file mode 100644 index 00000000000..03dd7eca7b3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listglobalbysubscriptionfortopictype.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 ListGlobalBySubscriptionForTopicTypeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListGlobalBySubscriptionForTopicTypeCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListGlobalBySubscriptionForTopicTypeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListGlobalBySubscriptionForTopicTypeOperationOptions() ListGlobalBySubscriptionForTopicTypeOperationOptions { + return ListGlobalBySubscriptionForTopicTypeOperationOptions{} +} + +func (o ListGlobalBySubscriptionForTopicTypeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListGlobalBySubscriptionForTopicTypeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListGlobalBySubscriptionForTopicTypeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListGlobalBySubscriptionForTopicType ... +func (c EventSubscriptionsClient) ListGlobalBySubscriptionForTopicType(ctx context.Context, id ProviderTopicTypeId, options ListGlobalBySubscriptionForTopicTypeOperationOptions) (result ListGlobalBySubscriptionForTopicTypeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListGlobalBySubscriptionForTopicTypeComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListGlobalBySubscriptionForTopicTypeComplete(ctx context.Context, id ProviderTopicTypeId, options ListGlobalBySubscriptionForTopicTypeOperationOptions) (ListGlobalBySubscriptionForTopicTypeCompleteResult, error) { + return c.ListGlobalBySubscriptionForTopicTypeCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListGlobalBySubscriptionForTopicTypeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListGlobalBySubscriptionForTopicTypeCompleteMatchingPredicate(ctx context.Context, id ProviderTopicTypeId, options ListGlobalBySubscriptionForTopicTypeOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListGlobalBySubscriptionForTopicTypeCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListGlobalBySubscriptionForTopicType(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListGlobalBySubscriptionForTopicTypeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbyresourcegroup.go new file mode 100644 index 00000000000..2d66a177e5b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbyresourcegroup.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 ListRegionalByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListRegionalByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListRegionalByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListRegionalByResourceGroupOperationOptions() ListRegionalByResourceGroupOperationOptions { + return ListRegionalByResourceGroupOperationOptions{} +} + +func (o ListRegionalByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListRegionalByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListRegionalByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListRegionalByResourceGroup ... +func (c EventSubscriptionsClient) ListRegionalByResourceGroup(ctx context.Context, id ProviderLocationId, options ListRegionalByResourceGroupOperationOptions) (result ListRegionalByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListRegionalByResourceGroupComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListRegionalByResourceGroupComplete(ctx context.Context, id ProviderLocationId, options ListRegionalByResourceGroupOperationOptions) (ListRegionalByResourceGroupCompleteResult, error) { + return c.ListRegionalByResourceGroupCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListRegionalByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListRegionalByResourceGroupCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, options ListRegionalByResourceGroupOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListRegionalByResourceGroupCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListRegionalByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListRegionalByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbyresourcegroupfortopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbyresourcegroupfortopictype.go new file mode 100644 index 00000000000..1eae7b2dab0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbyresourcegroupfortopictype.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 ListRegionalByResourceGroupForTopicTypeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListRegionalByResourceGroupForTopicTypeCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListRegionalByResourceGroupForTopicTypeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListRegionalByResourceGroupForTopicTypeOperationOptions() ListRegionalByResourceGroupForTopicTypeOperationOptions { + return ListRegionalByResourceGroupForTopicTypeOperationOptions{} +} + +func (o ListRegionalByResourceGroupForTopicTypeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListRegionalByResourceGroupForTopicTypeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListRegionalByResourceGroupForTopicTypeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListRegionalByResourceGroupForTopicType ... +func (c EventSubscriptionsClient) ListRegionalByResourceGroupForTopicType(ctx context.Context, id ProviderLocationTopicTypeId, options ListRegionalByResourceGroupForTopicTypeOperationOptions) (result ListRegionalByResourceGroupForTopicTypeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListRegionalByResourceGroupForTopicTypeComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListRegionalByResourceGroupForTopicTypeComplete(ctx context.Context, id ProviderLocationTopicTypeId, options ListRegionalByResourceGroupForTopicTypeOperationOptions) (ListRegionalByResourceGroupForTopicTypeCompleteResult, error) { + return c.ListRegionalByResourceGroupForTopicTypeCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListRegionalByResourceGroupForTopicTypeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListRegionalByResourceGroupForTopicTypeCompleteMatchingPredicate(ctx context.Context, id ProviderLocationTopicTypeId, options ListRegionalByResourceGroupForTopicTypeOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListRegionalByResourceGroupForTopicTypeCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListRegionalByResourceGroupForTopicType(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListRegionalByResourceGroupForTopicTypeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbysubscription.go new file mode 100644 index 00000000000..dfc23dfde54 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbysubscription.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 ListRegionalBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListRegionalBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListRegionalBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListRegionalBySubscriptionOperationOptions() ListRegionalBySubscriptionOperationOptions { + return ListRegionalBySubscriptionOperationOptions{} +} + +func (o ListRegionalBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListRegionalBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListRegionalBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListRegionalBySubscription ... +func (c EventSubscriptionsClient) ListRegionalBySubscription(ctx context.Context, id LocationId, options ListRegionalBySubscriptionOperationOptions) (result ListRegionalBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListRegionalBySubscriptionComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListRegionalBySubscriptionComplete(ctx context.Context, id LocationId, options ListRegionalBySubscriptionOperationOptions) (ListRegionalBySubscriptionCompleteResult, error) { + return c.ListRegionalBySubscriptionCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListRegionalBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListRegionalBySubscriptionCompleteMatchingPredicate(ctx context.Context, id LocationId, options ListRegionalBySubscriptionOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListRegionalBySubscriptionCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListRegionalBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListRegionalBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbysubscriptionfortopictype.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbysubscriptionfortopictype.go new file mode 100644 index 00000000000..90bd319ec96 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_listregionalbysubscriptionfortopictype.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 ListRegionalBySubscriptionForTopicTypeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type ListRegionalBySubscriptionForTopicTypeCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type ListRegionalBySubscriptionForTopicTypeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListRegionalBySubscriptionForTopicTypeOperationOptions() ListRegionalBySubscriptionForTopicTypeOperationOptions { + return ListRegionalBySubscriptionForTopicTypeOperationOptions{} +} + +func (o ListRegionalBySubscriptionForTopicTypeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListRegionalBySubscriptionForTopicTypeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListRegionalBySubscriptionForTopicTypeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListRegionalBySubscriptionForTopicType ... +func (c EventSubscriptionsClient) ListRegionalBySubscriptionForTopicType(ctx context.Context, id LocationTopicTypeId, options ListRegionalBySubscriptionForTopicTypeOperationOptions) (result ListRegionalBySubscriptionForTopicTypeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListRegionalBySubscriptionForTopicTypeComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) ListRegionalBySubscriptionForTopicTypeComplete(ctx context.Context, id LocationTopicTypeId, options ListRegionalBySubscriptionForTopicTypeOperationOptions) (ListRegionalBySubscriptionForTopicTypeCompleteResult, error) { + return c.ListRegionalBySubscriptionForTopicTypeCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// ListRegionalBySubscriptionForTopicTypeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) ListRegionalBySubscriptionForTopicTypeCompleteMatchingPredicate(ctx context.Context, id LocationTopicTypeId, options ListRegionalBySubscriptionForTopicTypeOperationOptions, predicate EventSubscriptionOperationPredicate) (result ListRegionalBySubscriptionForTopicTypeCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.ListRegionalBySubscriptionForTopicType(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListRegionalBySubscriptionForTopicTypeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionscreateorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionscreateorupdate.go new file mode 100644 index 00000000000..0b5821abd58 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionscreateorupdate.go @@ -0,0 +1,75 @@ +package eventsubscriptions + +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 NamespaceTopicEventSubscriptionsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Subscription +} + +// NamespaceTopicEventSubscriptionsCreateOrUpdate ... +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsCreateOrUpdate(ctx context.Context, id NamespaceTopicEventSubscriptionId, input Subscription) (result NamespaceTopicEventSubscriptionsCreateOrUpdateOperationResponse, 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 +} + +// NamespaceTopicEventSubscriptionsCreateOrUpdateThenPoll performs NamespaceTopicEventSubscriptionsCreateOrUpdate then polls until it's completed +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx context.Context, id NamespaceTopicEventSubscriptionId, input Subscription) error { + result, err := c.NamespaceTopicEventSubscriptionsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing NamespaceTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after NamespaceTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsdelete.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsdelete.go new file mode 100644 index 00000000000..72ed50159fb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsdelete.go @@ -0,0 +1,71 @@ +package eventsubscriptions + +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 NamespaceTopicEventSubscriptionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// NamespaceTopicEventSubscriptionsDelete ... +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsDelete(ctx context.Context, id NamespaceTopicEventSubscriptionId) (result NamespaceTopicEventSubscriptionsDeleteOperationResponse, 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 +} + +// NamespaceTopicEventSubscriptionsDeleteThenPoll performs NamespaceTopicEventSubscriptionsDelete then polls until it's completed +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsDeleteThenPoll(ctx context.Context, id NamespaceTopicEventSubscriptionId) error { + result, err := c.NamespaceTopicEventSubscriptionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing NamespaceTopicEventSubscriptionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after NamespaceTopicEventSubscriptionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsget.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsget.go new file mode 100644 index 00000000000..ceceb3c2649 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsget.go @@ -0,0 +1,54 @@ +package eventsubscriptions + +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 NamespaceTopicEventSubscriptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Subscription +} + +// NamespaceTopicEventSubscriptionsGet ... +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsGet(ctx context.Context, id NamespaceTopicEventSubscriptionId) (result NamespaceTopicEventSubscriptionsGetOperationResponse, 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 Subscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsgetdeliveryattributes.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsgetdeliveryattributes.go new file mode 100644 index 00000000000..ad55ef65336 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsgetdeliveryattributes.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 NamespaceTopicEventSubscriptionsGetDeliveryAttributesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeliveryAttributeListResult +} + +// NamespaceTopicEventSubscriptionsGetDeliveryAttributes ... +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsGetDeliveryAttributes(ctx context.Context, id NamespaceTopicEventSubscriptionId) (result NamespaceTopicEventSubscriptionsGetDeliveryAttributesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDeliveryAttributes", 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 DeliveryAttributeListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionslistbynamespacetopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionslistbynamespacetopic.go new file mode 100644 index 00000000000..1b3a58607f2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionslistbynamespacetopic.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Subscription +} + +type NamespaceTopicEventSubscriptionsListByNamespaceTopicCompleteResult struct { + LatestHttpResponse *http.Response + Items []Subscription +} + +type NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultNamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions() NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions { + return NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions{} +} + +func (o NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// NamespaceTopicEventSubscriptionsListByNamespaceTopic ... +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsListByNamespaceTopic(ctx context.Context, id NamespaceTopicId, options NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions) (result NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Subscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// NamespaceTopicEventSubscriptionsListByNamespaceTopicComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsListByNamespaceTopicComplete(ctx context.Context, id NamespaceTopicId, options NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions) (NamespaceTopicEventSubscriptionsListByNamespaceTopicCompleteResult, error) { + return c.NamespaceTopicEventSubscriptionsListByNamespaceTopicCompleteMatchingPredicate(ctx, id, options, SubscriptionOperationPredicate{}) +} + +// NamespaceTopicEventSubscriptionsListByNamespaceTopicCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsListByNamespaceTopicCompleteMatchingPredicate(ctx context.Context, id NamespaceTopicId, options NamespaceTopicEventSubscriptionsListByNamespaceTopicOperationOptions, predicate SubscriptionOperationPredicate) (result NamespaceTopicEventSubscriptionsListByNamespaceTopicCompleteResult, err error) { + items := make([]Subscription, 0) + + resp, err := c.NamespaceTopicEventSubscriptionsListByNamespaceTopic(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = NamespaceTopicEventSubscriptionsListByNamespaceTopicCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsupdate.go new file mode 100644 index 00000000000..bad76008a32 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_namespacetopiceventsubscriptionsupdate.go @@ -0,0 +1,75 @@ +package eventsubscriptions + +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 NamespaceTopicEventSubscriptionsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Subscription +} + +// NamespaceTopicEventSubscriptionsUpdate ... +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsUpdate(ctx context.Context, id NamespaceTopicEventSubscriptionId, input SubscriptionUpdateParameters) (result NamespaceTopicEventSubscriptionsUpdateOperationResponse, 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 +} + +// NamespaceTopicEventSubscriptionsUpdateThenPoll performs NamespaceTopicEventSubscriptionsUpdate then polls until it's completed +func (c EventSubscriptionsClient) NamespaceTopicEventSubscriptionsUpdateThenPoll(ctx context.Context, id NamespaceTopicEventSubscriptionId, input SubscriptionUpdateParameters) error { + result, err := c.NamespaceTopicEventSubscriptionsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing NamespaceTopicEventSubscriptionsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after NamespaceTopicEventSubscriptionsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionscreateorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionscreateorupdate.go new file mode 100644 index 00000000000..4600f00a512 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionscreateorupdate.go @@ -0,0 +1,75 @@ +package eventsubscriptions + +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 PartnerTopicEventSubscriptionsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// PartnerTopicEventSubscriptionsCreateOrUpdate ... +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsCreateOrUpdate(ctx context.Context, id PartnerTopicEventSubscriptionId, input EventSubscription) (result PartnerTopicEventSubscriptionsCreateOrUpdateOperationResponse, 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 +} + +// PartnerTopicEventSubscriptionsCreateOrUpdateThenPoll performs PartnerTopicEventSubscriptionsCreateOrUpdate then polls until it's completed +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx context.Context, id PartnerTopicEventSubscriptionId, input EventSubscription) error { + result, err := c.PartnerTopicEventSubscriptionsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PartnerTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PartnerTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsdelete.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsdelete.go new file mode 100644 index 00000000000..da99892d1a6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsdelete.go @@ -0,0 +1,71 @@ +package eventsubscriptions + +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 PartnerTopicEventSubscriptionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// PartnerTopicEventSubscriptionsDelete ... +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsDelete(ctx context.Context, id PartnerTopicEventSubscriptionId) (result PartnerTopicEventSubscriptionsDeleteOperationResponse, 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 +} + +// PartnerTopicEventSubscriptionsDeleteThenPoll performs PartnerTopicEventSubscriptionsDelete then polls until it's completed +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsDeleteThenPoll(ctx context.Context, id PartnerTopicEventSubscriptionId) error { + result, err := c.PartnerTopicEventSubscriptionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing PartnerTopicEventSubscriptionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PartnerTopicEventSubscriptionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsget.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsget.go new file mode 100644 index 00000000000..95a2272a743 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsget.go @@ -0,0 +1,54 @@ +package eventsubscriptions + +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 PartnerTopicEventSubscriptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// PartnerTopicEventSubscriptionsGet ... +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsGet(ctx context.Context, id PartnerTopicEventSubscriptionId) (result PartnerTopicEventSubscriptionsGetOperationResponse, 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 EventSubscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsgetdeliveryattributes.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsgetdeliveryattributes.go new file mode 100644 index 00000000000..735f29a1d7f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsgetdeliveryattributes.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 PartnerTopicEventSubscriptionsGetDeliveryAttributesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeliveryAttributeListResult +} + +// PartnerTopicEventSubscriptionsGetDeliveryAttributes ... +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsGetDeliveryAttributes(ctx context.Context, id PartnerTopicEventSubscriptionId) (result PartnerTopicEventSubscriptionsGetDeliveryAttributesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDeliveryAttributes", 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 DeliveryAttributeListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsgetfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsgetfullurl.go new file mode 100644 index 00000000000..2a7eaa97fb9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsgetfullurl.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 PartnerTopicEventSubscriptionsGetFullUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscriptionFullUrl +} + +// PartnerTopicEventSubscriptionsGetFullUrl ... +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsGetFullUrl(ctx context.Context, id PartnerTopicEventSubscriptionId) (result PartnerTopicEventSubscriptionsGetFullUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getFullUrl", 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 EventSubscriptionFullUrl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionslistbypartnertopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionslistbypartnertopic.go new file mode 100644 index 00000000000..4e326bf9ff6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionslistbypartnertopic.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 PartnerTopicEventSubscriptionsListByPartnerTopicOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type PartnerTopicEventSubscriptionsListByPartnerTopicCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultPartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions() PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions { + return PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions{} +} + +func (o PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// PartnerTopicEventSubscriptionsListByPartnerTopic ... +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsListByPartnerTopic(ctx context.Context, id PartnerTopicId, options PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions) (result PartnerTopicEventSubscriptionsListByPartnerTopicOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PartnerTopicEventSubscriptionsListByPartnerTopicComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsListByPartnerTopicComplete(ctx context.Context, id PartnerTopicId, options PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions) (PartnerTopicEventSubscriptionsListByPartnerTopicCompleteResult, error) { + return c.PartnerTopicEventSubscriptionsListByPartnerTopicCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// PartnerTopicEventSubscriptionsListByPartnerTopicCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsListByPartnerTopicCompleteMatchingPredicate(ctx context.Context, id PartnerTopicId, options PartnerTopicEventSubscriptionsListByPartnerTopicOperationOptions, predicate EventSubscriptionOperationPredicate) (result PartnerTopicEventSubscriptionsListByPartnerTopicCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.PartnerTopicEventSubscriptionsListByPartnerTopic(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = PartnerTopicEventSubscriptionsListByPartnerTopicCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsupdate.go new file mode 100644 index 00000000000..5430da22e95 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_partnertopiceventsubscriptionsupdate.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 PartnerTopicEventSubscriptionsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// PartnerTopicEventSubscriptionsUpdate ... +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsUpdate(ctx context.Context, id PartnerTopicEventSubscriptionId, input EventSubscriptionUpdateParameters) (result PartnerTopicEventSubscriptionsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 +} + +// PartnerTopicEventSubscriptionsUpdateThenPoll performs PartnerTopicEventSubscriptionsUpdate then polls until it's completed +func (c EventSubscriptionsClient) PartnerTopicEventSubscriptionsUpdateThenPoll(ctx context.Context, id PartnerTopicEventSubscriptionId, input EventSubscriptionUpdateParameters) error { + result, err := c.PartnerTopicEventSubscriptionsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PartnerTopicEventSubscriptionsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PartnerTopicEventSubscriptionsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionscreateorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionscreateorupdate.go new file mode 100644 index 00000000000..8e691657315 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionscreateorupdate.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 SystemTopicEventSubscriptionsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// SystemTopicEventSubscriptionsCreateOrUpdate ... +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsCreateOrUpdate(ctx context.Context, id SystemTopicEventSubscriptionId, input EventSubscription) (result SystemTopicEventSubscriptionsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SystemTopicEventSubscriptionsCreateOrUpdateThenPoll performs SystemTopicEventSubscriptionsCreateOrUpdate then polls until it's completed +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsCreateOrUpdateThenPoll(ctx context.Context, id SystemTopicEventSubscriptionId, input EventSubscription) error { + result, err := c.SystemTopicEventSubscriptionsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SystemTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SystemTopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsdelete.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsdelete.go new file mode 100644 index 00000000000..e2fe0a84d70 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsdelete.go @@ -0,0 +1,71 @@ +package eventsubscriptions + +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 SystemTopicEventSubscriptionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SystemTopicEventSubscriptionsDelete ... +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsDelete(ctx context.Context, id SystemTopicEventSubscriptionId) (result SystemTopicEventSubscriptionsDeleteOperationResponse, 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 +} + +// SystemTopicEventSubscriptionsDeleteThenPoll performs SystemTopicEventSubscriptionsDelete then polls until it's completed +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsDeleteThenPoll(ctx context.Context, id SystemTopicEventSubscriptionId) error { + result, err := c.SystemTopicEventSubscriptionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing SystemTopicEventSubscriptionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SystemTopicEventSubscriptionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsget.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsget.go new file mode 100644 index 00000000000..cdc5a2f4de7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsget.go @@ -0,0 +1,54 @@ +package eventsubscriptions + +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 SystemTopicEventSubscriptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// SystemTopicEventSubscriptionsGet ... +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsGet(ctx context.Context, id SystemTopicEventSubscriptionId) (result SystemTopicEventSubscriptionsGetOperationResponse, 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 EventSubscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsgetdeliveryattributes.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsgetdeliveryattributes.go new file mode 100644 index 00000000000..f2e0fd63275 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsgetdeliveryattributes.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 SystemTopicEventSubscriptionsGetDeliveryAttributesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeliveryAttributeListResult +} + +// SystemTopicEventSubscriptionsGetDeliveryAttributes ... +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsGetDeliveryAttributes(ctx context.Context, id SystemTopicEventSubscriptionId) (result SystemTopicEventSubscriptionsGetDeliveryAttributesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDeliveryAttributes", 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 DeliveryAttributeListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsgetfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsgetfullurl.go new file mode 100644 index 00000000000..2465d121fd2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsgetfullurl.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 SystemTopicEventSubscriptionsGetFullUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscriptionFullUrl +} + +// SystemTopicEventSubscriptionsGetFullUrl ... +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsGetFullUrl(ctx context.Context, id SystemTopicEventSubscriptionId) (result SystemTopicEventSubscriptionsGetFullUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getFullUrl", 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 EventSubscriptionFullUrl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionslistbysystemtopic.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionslistbysystemtopic.go new file mode 100644 index 00000000000..7ff5ad87e86 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionslistbysystemtopic.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 SystemTopicEventSubscriptionsListBySystemTopicOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type SystemTopicEventSubscriptionsListBySystemTopicCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type SystemTopicEventSubscriptionsListBySystemTopicOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultSystemTopicEventSubscriptionsListBySystemTopicOperationOptions() SystemTopicEventSubscriptionsListBySystemTopicOperationOptions { + return SystemTopicEventSubscriptionsListBySystemTopicOperationOptions{} +} + +func (o SystemTopicEventSubscriptionsListBySystemTopicOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SystemTopicEventSubscriptionsListBySystemTopicOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SystemTopicEventSubscriptionsListBySystemTopicOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// SystemTopicEventSubscriptionsListBySystemTopic ... +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsListBySystemTopic(ctx context.Context, id SystemTopicId, options SystemTopicEventSubscriptionsListBySystemTopicOperationOptions) (result SystemTopicEventSubscriptionsListBySystemTopicOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SystemTopicEventSubscriptionsListBySystemTopicComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsListBySystemTopicComplete(ctx context.Context, id SystemTopicId, options SystemTopicEventSubscriptionsListBySystemTopicOperationOptions) (SystemTopicEventSubscriptionsListBySystemTopicCompleteResult, error) { + return c.SystemTopicEventSubscriptionsListBySystemTopicCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// SystemTopicEventSubscriptionsListBySystemTopicCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsListBySystemTopicCompleteMatchingPredicate(ctx context.Context, id SystemTopicId, options SystemTopicEventSubscriptionsListBySystemTopicOperationOptions, predicate EventSubscriptionOperationPredicate) (result SystemTopicEventSubscriptionsListBySystemTopicCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.SystemTopicEventSubscriptionsListBySystemTopic(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SystemTopicEventSubscriptionsListBySystemTopicCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsupdate.go new file mode 100644 index 00000000000..7e82339b92a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_systemtopiceventsubscriptionsupdate.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 SystemTopicEventSubscriptionsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// SystemTopicEventSubscriptionsUpdate ... +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsUpdate(ctx context.Context, id SystemTopicEventSubscriptionId, input EventSubscriptionUpdateParameters) (result SystemTopicEventSubscriptionsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 +} + +// SystemTopicEventSubscriptionsUpdateThenPoll performs SystemTopicEventSubscriptionsUpdate then polls until it's completed +func (c EventSubscriptionsClient) SystemTopicEventSubscriptionsUpdateThenPoll(ctx context.Context, id SystemTopicEventSubscriptionId, input EventSubscriptionUpdateParameters) error { + result, err := c.SystemTopicEventSubscriptionsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SystemTopicEventSubscriptionsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SystemTopicEventSubscriptionsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionscreateorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionscreateorupdate.go new file mode 100644 index 00000000000..ada6bf74ae6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionscreateorupdate.go @@ -0,0 +1,75 @@ +package eventsubscriptions + +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 TopicEventSubscriptionsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// TopicEventSubscriptionsCreateOrUpdate ... +func (c EventSubscriptionsClient) TopicEventSubscriptionsCreateOrUpdate(ctx context.Context, id EventSubscriptionId, input EventSubscription) (result TopicEventSubscriptionsCreateOrUpdateOperationResponse, 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 +} + +// TopicEventSubscriptionsCreateOrUpdateThenPoll performs TopicEventSubscriptionsCreateOrUpdate then polls until it's completed +func (c EventSubscriptionsClient) TopicEventSubscriptionsCreateOrUpdateThenPoll(ctx context.Context, id EventSubscriptionId, input EventSubscription) error { + result, err := c.TopicEventSubscriptionsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TopicEventSubscriptionsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsdelete.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsdelete.go new file mode 100644 index 00000000000..d17dcd694f9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsdelete.go @@ -0,0 +1,71 @@ +package eventsubscriptions + +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 TopicEventSubscriptionsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// TopicEventSubscriptionsDelete ... +func (c EventSubscriptionsClient) TopicEventSubscriptionsDelete(ctx context.Context, id EventSubscriptionId) (result TopicEventSubscriptionsDeleteOperationResponse, 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 +} + +// TopicEventSubscriptionsDeleteThenPoll performs TopicEventSubscriptionsDelete then polls until it's completed +func (c EventSubscriptionsClient) TopicEventSubscriptionsDeleteThenPoll(ctx context.Context, id EventSubscriptionId) error { + result, err := c.TopicEventSubscriptionsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing TopicEventSubscriptionsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TopicEventSubscriptionsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsget.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsget.go new file mode 100644 index 00000000000..c3bd2e6b42d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsget.go @@ -0,0 +1,54 @@ +package eventsubscriptions + +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 TopicEventSubscriptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// TopicEventSubscriptionsGet ... +func (c EventSubscriptionsClient) TopicEventSubscriptionsGet(ctx context.Context, id EventSubscriptionId) (result TopicEventSubscriptionsGetOperationResponse, 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 EventSubscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsgetdeliveryattributes.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsgetdeliveryattributes.go new file mode 100644 index 00000000000..8e703714f9d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsgetdeliveryattributes.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 TopicEventSubscriptionsGetDeliveryAttributesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeliveryAttributeListResult +} + +// TopicEventSubscriptionsGetDeliveryAttributes ... +func (c EventSubscriptionsClient) TopicEventSubscriptionsGetDeliveryAttributes(ctx context.Context, id EventSubscriptionId) (result TopicEventSubscriptionsGetDeliveryAttributesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDeliveryAttributes", 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 DeliveryAttributeListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsgetfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsgetfullurl.go new file mode 100644 index 00000000000..ff481e4d08d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsgetfullurl.go @@ -0,0 +1,55 @@ +package eventsubscriptions + +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 TopicEventSubscriptionsGetFullUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscriptionFullUrl +} + +// TopicEventSubscriptionsGetFullUrl ... +func (c EventSubscriptionsClient) TopicEventSubscriptionsGetFullUrl(ctx context.Context, id EventSubscriptionId) (result TopicEventSubscriptionsGetFullUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getFullUrl", 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 EventSubscriptionFullUrl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionslist.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionslist.go new file mode 100644 index 00000000000..1802bb8ef34 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionslist.go @@ -0,0 +1,123 @@ +package eventsubscriptions + +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 TopicEventSubscriptionsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EventSubscription +} + +type TopicEventSubscriptionsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EventSubscription +} + +type TopicEventSubscriptionsListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultTopicEventSubscriptionsListOperationOptions() TopicEventSubscriptionsListOperationOptions { + return TopicEventSubscriptionsListOperationOptions{} +} + +func (o TopicEventSubscriptionsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o TopicEventSubscriptionsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o TopicEventSubscriptionsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// TopicEventSubscriptionsList ... +func (c EventSubscriptionsClient) TopicEventSubscriptionsList(ctx context.Context, id TopicId, options TopicEventSubscriptionsListOperationOptions) (result TopicEventSubscriptionsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventSubscriptions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EventSubscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// TopicEventSubscriptionsListComplete retrieves all the results into a single object +func (c EventSubscriptionsClient) TopicEventSubscriptionsListComplete(ctx context.Context, id TopicId, options TopicEventSubscriptionsListOperationOptions) (TopicEventSubscriptionsListCompleteResult, error) { + return c.TopicEventSubscriptionsListCompleteMatchingPredicate(ctx, id, options, EventSubscriptionOperationPredicate{}) +} + +// TopicEventSubscriptionsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EventSubscriptionsClient) TopicEventSubscriptionsListCompleteMatchingPredicate(ctx context.Context, id TopicId, options TopicEventSubscriptionsListOperationOptions, predicate EventSubscriptionOperationPredicate) (result TopicEventSubscriptionsListCompleteResult, err error) { + items := make([]EventSubscription, 0) + + resp, err := c.TopicEventSubscriptionsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = TopicEventSubscriptionsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsupdate.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsupdate.go new file mode 100644 index 00000000000..a27abf7fe72 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_topiceventsubscriptionsupdate.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 TopicEventSubscriptionsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EventSubscription +} + +// TopicEventSubscriptionsUpdate ... +func (c EventSubscriptionsClient) TopicEventSubscriptionsUpdate(ctx context.Context, id EventSubscriptionId, input EventSubscriptionUpdateParameters) (result TopicEventSubscriptionsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 +} + +// TopicEventSubscriptionsUpdateThenPoll performs TopicEventSubscriptionsUpdate then polls until it's completed +func (c EventSubscriptionsClient) TopicEventSubscriptionsUpdateThenPoll(ctx context.Context, id EventSubscriptionId, input EventSubscriptionUpdateParameters) error { + result, err := c.TopicEventSubscriptionsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TopicEventSubscriptionsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TopicEventSubscriptionsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_update.go new file mode 100644 index 00000000000..e0d9f627508 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/method_update.go @@ -0,0 +1,74 @@ +package eventsubscriptions + +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 *EventSubscription +} + +// Update ... +func (c EventSubscriptionsClient) Update(ctx context.Context, id ScopedEventSubscriptionId, input EventSubscriptionUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + 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 EventSubscriptionsClient) UpdateThenPoll(ctx context.Context, id ScopedEventSubscriptionId, input EventSubscriptionUpdateParameters) 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/eventgrid/2023-12-15-preview/eventsubscriptions/model_advancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_advancedfilter.go new file mode 100644 index 00000000000..9b667278529 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_advancedfilter.go @@ -0,0 +1,197 @@ +package eventsubscriptions + +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 AdvancedFilter interface { +} + +// RawAdvancedFilterImpl 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 RawAdvancedFilterImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAdvancedFilterImplementation(input []byte) (AdvancedFilter, 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 AdvancedFilter into map[string]interface: %+v", err) + } + + value, ok := temp["operatorType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "BoolEquals") { + var out BoolEqualsAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BoolEqualsAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IsNotNull") { + var out IsNotNullAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IsNotNullAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IsNullOrUndefined") { + var out IsNullOrUndefinedAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IsNullOrUndefinedAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberGreaterThan") { + var out NumberGreaterThanAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberGreaterThanAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberGreaterThanOrEquals") { + var out NumberGreaterThanOrEqualsAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberGreaterThanOrEqualsAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberIn") { + var out NumberInAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberInAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberInRange") { + var out NumberInRangeAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberInRangeAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberLessThan") { + var out NumberLessThanAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberLessThanAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberLessThanOrEquals") { + var out NumberLessThanOrEqualsAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberLessThanOrEqualsAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberNotIn") { + var out NumberNotInAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberNotInAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberNotInRange") { + var out NumberNotInRangeAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberNotInRangeAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringBeginsWith") { + var out StringBeginsWithAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringBeginsWithAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringContains") { + var out StringContainsAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringContainsAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringEndsWith") { + var out StringEndsWithAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringEndsWithAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringIn") { + var out StringInAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringInAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotBeginsWith") { + var out StringNotBeginsWithAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotBeginsWithAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotContains") { + var out StringNotContainsAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotContainsAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotEndsWith") { + var out StringNotEndsWithAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotEndsWithAdvancedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotIn") { + var out StringNotInAdvancedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotInAdvancedFilter: %+v", err) + } + return out, nil + } + + out := RawAdvancedFilterImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_azurefunctioneventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_azurefunctioneventsubscriptiondestination.go new file mode 100644 index 00000000000..d580a1e3722 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_azurefunctioneventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = AzureFunctionEventSubscriptionDestination{} + +type AzureFunctionEventSubscriptionDestination struct { + Properties *AzureFunctionEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = AzureFunctionEventSubscriptionDestination{} + +func (s AzureFunctionEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper AzureFunctionEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureFunctionEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureFunctionEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "AzureFunction" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureFunctionEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_azurefunctioneventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_azurefunctioneventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..38c0e10c193 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_azurefunctioneventsubscriptiondestinationproperties.go @@ -0,0 +1,53 @@ +package eventsubscriptions + +import ( + "encoding/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 AzureFunctionEventSubscriptionDestinationProperties struct { + DeliveryAttributeMappings *[]DeliveryAttributeMapping `json:"deliveryAttributeMappings,omitempty"` + MaxEventsPerBatch *int64 `json:"maxEventsPerBatch,omitempty"` + PreferredBatchSizeInKilobytes *int64 `json:"preferredBatchSizeInKilobytes,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} + +var _ json.Unmarshaler = &AzureFunctionEventSubscriptionDestinationProperties{} + +func (s *AzureFunctionEventSubscriptionDestinationProperties) UnmarshalJSON(bytes []byte) error { + type alias AzureFunctionEventSubscriptionDestinationProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AzureFunctionEventSubscriptionDestinationProperties: %+v", err) + } + + s.MaxEventsPerBatch = decoded.MaxEventsPerBatch + s.PreferredBatchSizeInKilobytes = decoded.PreferredBatchSizeInKilobytes + s.ResourceId = decoded.ResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureFunctionEventSubscriptionDestinationProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deliveryAttributeMappings"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DeliveryAttributeMappings into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryAttributeMapping, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryAttributeMappingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DeliveryAttributeMappings' for 'AzureFunctionEventSubscriptionDestinationProperties': %+v", i, err) + } + output = append(output, impl) + } + s.DeliveryAttributeMappings = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_boolequalsadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_boolequalsadvancedfilter.go new file mode 100644 index 00000000000..fc35dd630b7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_boolequalsadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = BoolEqualsAdvancedFilter{} + +type BoolEqualsAdvancedFilter struct { + Value *bool `json:"value,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = BoolEqualsAdvancedFilter{} + +func (s BoolEqualsAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper BoolEqualsAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BoolEqualsAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BoolEqualsAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "BoolEquals" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BoolEqualsAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_boolequalsfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_boolequalsfilter.go new file mode 100644 index 00000000000..81c4745a466 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_boolequalsfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = BoolEqualsFilter{} + +type BoolEqualsFilter struct { + Value *bool `json:"value,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = BoolEqualsFilter{} + +func (s BoolEqualsFilter) MarshalJSON() ([]byte, error) { + type wrapper BoolEqualsFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BoolEqualsFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BoolEqualsFilter: %+v", err) + } + decoded["operatorType"] = "BoolEquals" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BoolEqualsFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deadletterdestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deadletterdestination.go new file mode 100644 index 00000000000..b445f359655 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deadletterdestination.go @@ -0,0 +1,53 @@ +package eventsubscriptions + +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 DeadLetterDestination interface { +} + +// RawDeadLetterDestinationImpl 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 RawDeadLetterDestinationImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeadLetterDestinationImplementation(input []byte) (DeadLetterDestination, 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 DeadLetterDestination into map[string]interface: %+v", err) + } + + value, ok := temp["endpointType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "StorageBlob") { + var out StorageBlobDeadLetterDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StorageBlobDeadLetterDestination: %+v", err) + } + return out, nil + } + + out := RawDeadLetterDestinationImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deadletterwithresourceidentity.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deadletterwithresourceidentity.go new file mode 100644 index 00000000000..68884c87f6b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deadletterwithresourceidentity.go @@ -0,0 +1,40 @@ +package eventsubscriptions + +import ( + "encoding/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 DeadLetterWithResourceIdentity struct { + DeadLetterDestination DeadLetterDestination `json:"deadLetterDestination"` + Identity *EventSubscriptionIdentity `json:"identity,omitempty"` +} + +var _ json.Unmarshaler = &DeadLetterWithResourceIdentity{} + +func (s *DeadLetterWithResourceIdentity) UnmarshalJSON(bytes []byte) error { + type alias DeadLetterWithResourceIdentity + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DeadLetterWithResourceIdentity: %+v", err) + } + + s.Identity = decoded.Identity + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DeadLetterWithResourceIdentity into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deadLetterDestination"]; ok { + impl, err := unmarshalDeadLetterDestinationImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DeadLetterDestination' for 'DeadLetterWithResourceIdentity': %+v", err) + } + s.DeadLetterDestination = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryattributelistresult.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryattributelistresult.go new file mode 100644 index 00000000000..1fc05481f8c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryattributelistresult.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/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 DeliveryAttributeListResult struct { + Value *[]DeliveryAttributeMapping `json:"value,omitempty"` +} + +var _ json.Unmarshaler = &DeliveryAttributeListResult{} + +func (s *DeliveryAttributeListResult) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DeliveryAttributeListResult into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["value"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Value into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryAttributeMapping, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryAttributeMappingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Value' for 'DeliveryAttributeListResult': %+v", i, err) + } + output = append(output, impl) + } + s.Value = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryattributemapping.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryattributemapping.go new file mode 100644 index 00000000000..317188346aa --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryattributemapping.go @@ -0,0 +1,61 @@ +package eventsubscriptions + +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 DeliveryAttributeMapping interface { +} + +// RawDeliveryAttributeMappingImpl 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 RawDeliveryAttributeMappingImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDeliveryAttributeMappingImplementation(input []byte) (DeliveryAttributeMapping, 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 DeliveryAttributeMapping into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Dynamic") { + var out DynamicDeliveryAttributeMapping + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DynamicDeliveryAttributeMapping: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Static") { + var out StaticDeliveryAttributeMapping + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StaticDeliveryAttributeMapping: %+v", err) + } + return out, nil + } + + out := RawDeliveryAttributeMappingImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryconfiguration.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryconfiguration.go new file mode 100644 index 00000000000..3af812cac24 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliveryconfiguration.go @@ -0,0 +1,10 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeliveryConfiguration struct { + DeliveryMode *DeliveryMode `json:"deliveryMode,omitempty"` + Push *PushInfo `json:"push,omitempty"` + Queue *QueueInfo `json:"queue,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliverywithresourceidentity.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliverywithresourceidentity.go new file mode 100644 index 00000000000..23396094acd --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_deliverywithresourceidentity.go @@ -0,0 +1,40 @@ +package eventsubscriptions + +import ( + "encoding/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 DeliveryWithResourceIdentity struct { + Destination EventSubscriptionDestination `json:"destination"` + Identity *EventSubscriptionIdentity `json:"identity,omitempty"` +} + +var _ json.Unmarshaler = &DeliveryWithResourceIdentity{} + +func (s *DeliveryWithResourceIdentity) UnmarshalJSON(bytes []byte) error { + type alias DeliveryWithResourceIdentity + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into DeliveryWithResourceIdentity: %+v", err) + } + + s.Identity = decoded.Identity + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DeliveryWithResourceIdentity into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["destination"]; ok { + impl, err := unmarshalEventSubscriptionDestinationImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Destination' for 'DeliveryWithResourceIdentity': %+v", err) + } + s.Destination = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_dynamicdeliveryattributemapping.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_dynamicdeliveryattributemapping.go new file mode 100644 index 00000000000..d7af26c8335 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_dynamicdeliveryattributemapping.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryAttributeMapping = DynamicDeliveryAttributeMapping{} + +type DynamicDeliveryAttributeMapping struct { + Properties *DynamicDeliveryAttributeMappingProperties `json:"properties,omitempty"` + + // Fields inherited from DeliveryAttributeMapping + Name *string `json:"name,omitempty"` +} + +var _ json.Marshaler = DynamicDeliveryAttributeMapping{} + +func (s DynamicDeliveryAttributeMapping) MarshalJSON() ([]byte, error) { + type wrapper DynamicDeliveryAttributeMapping + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DynamicDeliveryAttributeMapping: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DynamicDeliveryAttributeMapping: %+v", err) + } + decoded["type"] = "Dynamic" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DynamicDeliveryAttributeMapping: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_dynamicdeliveryattributemappingproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_dynamicdeliveryattributemappingproperties.go new file mode 100644 index 00000000000..e9193382a9d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_dynamicdeliveryattributemappingproperties.go @@ -0,0 +1,8 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DynamicDeliveryAttributeMappingProperties struct { + SourceField *string `json:"sourceField,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventhubeventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventhubeventsubscriptiondestination.go new file mode 100644 index 00000000000..b1a7a97c128 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventhubeventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = EventHubEventSubscriptionDestination{} + +type EventHubEventSubscriptionDestination struct { + Properties *EventHubEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = EventHubEventSubscriptionDestination{} + +func (s EventHubEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper EventHubEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling EventHubEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling EventHubEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "EventHub" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling EventHubEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventhubeventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventhubeventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..57d8d816374 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventhubeventsubscriptiondestinationproperties.go @@ -0,0 +1,49 @@ +package eventsubscriptions + +import ( + "encoding/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 EventHubEventSubscriptionDestinationProperties struct { + DeliveryAttributeMappings *[]DeliveryAttributeMapping `json:"deliveryAttributeMappings,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} + +var _ json.Unmarshaler = &EventHubEventSubscriptionDestinationProperties{} + +func (s *EventHubEventSubscriptionDestinationProperties) UnmarshalJSON(bytes []byte) error { + type alias EventHubEventSubscriptionDestinationProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into EventHubEventSubscriptionDestinationProperties: %+v", err) + } + + s.ResourceId = decoded.ResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EventHubEventSubscriptionDestinationProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deliveryAttributeMappings"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DeliveryAttributeMappings into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryAttributeMapping, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryAttributeMappingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DeliveryAttributeMappings' for 'EventHubEventSubscriptionDestinationProperties': %+v", i, err) + } + output = append(output, impl) + } + s.DeliveryAttributeMappings = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscription.go new file mode 100644 index 00000000000..f8d4022b4fd --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscription.go @@ -0,0 +1,16 @@ +package eventsubscriptions + +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 EventSubscription struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EventSubscriptionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptiondestination.go new file mode 100644 index 00000000000..0e68677824b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptiondestination.go @@ -0,0 +1,125 @@ +package eventsubscriptions + +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 EventSubscriptionDestination interface { +} + +// RawEventSubscriptionDestinationImpl 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 RawEventSubscriptionDestinationImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalEventSubscriptionDestinationImplementation(input []byte) (EventSubscriptionDestination, 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 EventSubscriptionDestination into map[string]interface: %+v", err) + } + + value, ok := temp["endpointType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureFunction") { + var out AzureFunctionEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureFunctionEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "EventHub") { + var out EventHubEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into EventHubEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "HybridConnection") { + var out HybridConnectionEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HybridConnectionEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MonitorAlert") { + var out MonitorAlertEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MonitorAlertEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NamespaceTopic") { + var out NamespaceTopicEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NamespaceTopicEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "PartnerDestination") { + var out PartnerEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PartnerEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ServiceBusQueue") { + var out ServiceBusQueueEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ServiceBusQueueEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ServiceBusTopic") { + var out ServiceBusTopicEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ServiceBusTopicEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StorageQueue") { + var out StorageQueueEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StorageQueueEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "WebHook") { + var out WebHookEventSubscriptionDestination + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into WebHookEventSubscriptionDestination: %+v", err) + } + return out, nil + } + + out := RawEventSubscriptionDestinationImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionfilter.go new file mode 100644 index 00000000000..2bb6ec93a10 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionfilter.go @@ -0,0 +1,57 @@ +package eventsubscriptions + +import ( + "encoding/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 EventSubscriptionFilter struct { + AdvancedFilters *[]AdvancedFilter `json:"advancedFilters,omitempty"` + EnableAdvancedFilteringOnArrays *bool `json:"enableAdvancedFilteringOnArrays,omitempty"` + IncludedEventTypes *[]string `json:"includedEventTypes,omitempty"` + IsSubjectCaseSensitive *bool `json:"isSubjectCaseSensitive,omitempty"` + SubjectBeginsWith *string `json:"subjectBeginsWith,omitempty"` + SubjectEndsWith *string `json:"subjectEndsWith,omitempty"` +} + +var _ json.Unmarshaler = &EventSubscriptionFilter{} + +func (s *EventSubscriptionFilter) UnmarshalJSON(bytes []byte) error { + type alias EventSubscriptionFilter + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into EventSubscriptionFilter: %+v", err) + } + + s.EnableAdvancedFilteringOnArrays = decoded.EnableAdvancedFilteringOnArrays + s.IncludedEventTypes = decoded.IncludedEventTypes + s.IsSubjectCaseSensitive = decoded.IsSubjectCaseSensitive + s.SubjectBeginsWith = decoded.SubjectBeginsWith + s.SubjectEndsWith = decoded.SubjectEndsWith + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EventSubscriptionFilter into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["advancedFilters"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling AdvancedFilters into list []json.RawMessage: %+v", err) + } + + output := make([]AdvancedFilter, 0) + for i, val := range listTemp { + impl, err := unmarshalAdvancedFilterImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'AdvancedFilters' for 'EventSubscriptionFilter': %+v", i, err) + } + output = append(output, impl) + } + s.AdvancedFilters = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionfullurl.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionfullurl.go new file mode 100644 index 00000000000..2c155f5fe55 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionfullurl.go @@ -0,0 +1,8 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventSubscriptionFullUrl struct { + EndpointUrl *string `json:"endpointUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionidentity.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionidentity.go new file mode 100644 index 00000000000..d960aa4e36e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionidentity.go @@ -0,0 +1,9 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventSubscriptionIdentity struct { + Type *EventSubscriptionIdentityType `json:"type,omitempty"` + UserAssignedIdentity *string `json:"userAssignedIdentity,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionproperties.go new file mode 100644 index 00000000000..567ad97d79a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionproperties.go @@ -0,0 +1,80 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventSubscriptionProperties struct { + DeadLetterDestination DeadLetterDestination `json:"deadLetterDestination"` + DeadLetterWithResourceIdentity *DeadLetterWithResourceIdentity `json:"deadLetterWithResourceIdentity,omitempty"` + DeliveryWithResourceIdentity *DeliveryWithResourceIdentity `json:"deliveryWithResourceIdentity,omitempty"` + Destination EventSubscriptionDestination `json:"destination"` + EventDeliverySchema *EventDeliverySchema `json:"eventDeliverySchema,omitempty"` + ExpirationTimeUtc *string `json:"expirationTimeUtc,omitempty"` + Filter *EventSubscriptionFilter `json:"filter,omitempty"` + Labels *[]string `json:"labels,omitempty"` + ProvisioningState *EventSubscriptionProvisioningState `json:"provisioningState,omitempty"` + RetryPolicy *RetryPolicy `json:"retryPolicy,omitempty"` + Topic *string `json:"topic,omitempty"` +} + +func (o *EventSubscriptionProperties) GetExpirationTimeUtcAsTime() (*time.Time, error) { + if o.ExpirationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *EventSubscriptionProperties) SetExpirationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeUtc = &formatted +} + +var _ json.Unmarshaler = &EventSubscriptionProperties{} + +func (s *EventSubscriptionProperties) UnmarshalJSON(bytes []byte) error { + type alias EventSubscriptionProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into EventSubscriptionProperties: %+v", err) + } + + s.DeadLetterWithResourceIdentity = decoded.DeadLetterWithResourceIdentity + s.DeliveryWithResourceIdentity = decoded.DeliveryWithResourceIdentity + s.EventDeliverySchema = decoded.EventDeliverySchema + s.ExpirationTimeUtc = decoded.ExpirationTimeUtc + s.Filter = decoded.Filter + s.Labels = decoded.Labels + s.ProvisioningState = decoded.ProvisioningState + s.RetryPolicy = decoded.RetryPolicy + s.Topic = decoded.Topic + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EventSubscriptionProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deadLetterDestination"]; ok { + impl, err := unmarshalDeadLetterDestinationImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DeadLetterDestination' for 'EventSubscriptionProperties': %+v", err) + } + s.DeadLetterDestination = impl + } + + if v, ok := temp["destination"]; ok { + impl, err := unmarshalEventSubscriptionDestinationImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Destination' for 'EventSubscriptionProperties': %+v", err) + } + s.Destination = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionupdateparameters.go new file mode 100644 index 00000000000..72f70f8b4d9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_eventsubscriptionupdateparameters.go @@ -0,0 +1,76 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventSubscriptionUpdateParameters struct { + DeadLetterDestination DeadLetterDestination `json:"deadLetterDestination"` + DeadLetterWithResourceIdentity *DeadLetterWithResourceIdentity `json:"deadLetterWithResourceIdentity,omitempty"` + DeliveryWithResourceIdentity *DeliveryWithResourceIdentity `json:"deliveryWithResourceIdentity,omitempty"` + Destination EventSubscriptionDestination `json:"destination"` + EventDeliverySchema *EventDeliverySchema `json:"eventDeliverySchema,omitempty"` + ExpirationTimeUtc *string `json:"expirationTimeUtc,omitempty"` + Filter *EventSubscriptionFilter `json:"filter,omitempty"` + Labels *[]string `json:"labels,omitempty"` + RetryPolicy *RetryPolicy `json:"retryPolicy,omitempty"` +} + +func (o *EventSubscriptionUpdateParameters) GetExpirationTimeUtcAsTime() (*time.Time, error) { + if o.ExpirationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *EventSubscriptionUpdateParameters) SetExpirationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeUtc = &formatted +} + +var _ json.Unmarshaler = &EventSubscriptionUpdateParameters{} + +func (s *EventSubscriptionUpdateParameters) UnmarshalJSON(bytes []byte) error { + type alias EventSubscriptionUpdateParameters + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into EventSubscriptionUpdateParameters: %+v", err) + } + + s.DeadLetterWithResourceIdentity = decoded.DeadLetterWithResourceIdentity + s.DeliveryWithResourceIdentity = decoded.DeliveryWithResourceIdentity + s.EventDeliverySchema = decoded.EventDeliverySchema + s.ExpirationTimeUtc = decoded.ExpirationTimeUtc + s.Filter = decoded.Filter + s.Labels = decoded.Labels + s.RetryPolicy = decoded.RetryPolicy + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling EventSubscriptionUpdateParameters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deadLetterDestination"]; ok { + impl, err := unmarshalDeadLetterDestinationImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DeadLetterDestination' for 'EventSubscriptionUpdateParameters': %+v", err) + } + s.DeadLetterDestination = impl + } + + if v, ok := temp["destination"]; ok { + impl, err := unmarshalEventSubscriptionDestinationImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Destination' for 'EventSubscriptionUpdateParameters': %+v", err) + } + s.Destination = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_filter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_filter.go new file mode 100644 index 00000000000..e86ff888523 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_filter.go @@ -0,0 +1,197 @@ +package eventsubscriptions + +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 Filter interface { +} + +// RawFilterImpl 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 RawFilterImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalFilterImplementation(input []byte) (Filter, 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 Filter into map[string]interface: %+v", err) + } + + value, ok := temp["operatorType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "BoolEquals") { + var out BoolEqualsFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BoolEqualsFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IsNotNull") { + var out IsNotNullFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IsNotNullFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IsNullOrUndefined") { + var out IsNullOrUndefinedFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IsNullOrUndefinedFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberGreaterThan") { + var out NumberGreaterThanFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberGreaterThanFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberGreaterThanOrEquals") { + var out NumberGreaterThanOrEqualsFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberGreaterThanOrEqualsFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberIn") { + var out NumberInFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberInFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberInRange") { + var out NumberInRangeFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberInRangeFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberLessThan") { + var out NumberLessThanFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberLessThanFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberLessThanOrEquals") { + var out NumberLessThanOrEqualsFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberLessThanOrEqualsFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberNotIn") { + var out NumberNotInFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberNotInFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "NumberNotInRange") { + var out NumberNotInRangeFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into NumberNotInRangeFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringBeginsWith") { + var out StringBeginsWithFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringBeginsWithFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringContains") { + var out StringContainsFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringContainsFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringEndsWith") { + var out StringEndsWithFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringEndsWithFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringIn") { + var out StringInFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringInFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotBeginsWith") { + var out StringNotBeginsWithFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotBeginsWithFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotContains") { + var out StringNotContainsFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotContainsFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotEndsWith") { + var out StringNotEndsWithFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotEndsWithFilter: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "StringNotIn") { + var out StringNotInFilter + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StringNotInFilter: %+v", err) + } + return out, nil + } + + out := RawFilterImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_filtersconfiguration.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_filtersconfiguration.go new file mode 100644 index 00000000000..8bc271cdb45 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_filtersconfiguration.go @@ -0,0 +1,49 @@ +package eventsubscriptions + +import ( + "encoding/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 FiltersConfiguration struct { + Filters *[]Filter `json:"filters,omitempty"` + IncludedEventTypes *[]string `json:"includedEventTypes,omitempty"` +} + +var _ json.Unmarshaler = &FiltersConfiguration{} + +func (s *FiltersConfiguration) UnmarshalJSON(bytes []byte) error { + type alias FiltersConfiguration + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into FiltersConfiguration: %+v", err) + } + + s.IncludedEventTypes = decoded.IncludedEventTypes + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling FiltersConfiguration into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["filters"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Filters into list []json.RawMessage: %+v", err) + } + + output := make([]Filter, 0) + for i, val := range listTemp { + impl, err := unmarshalFilterImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Filters' for 'FiltersConfiguration': %+v", i, err) + } + output = append(output, impl) + } + s.Filters = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_hybridconnectioneventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_hybridconnectioneventsubscriptiondestination.go new file mode 100644 index 00000000000..53f4b550d28 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_hybridconnectioneventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = HybridConnectionEventSubscriptionDestination{} + +type HybridConnectionEventSubscriptionDestination struct { + Properties *HybridConnectionEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = HybridConnectionEventSubscriptionDestination{} + +func (s HybridConnectionEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper HybridConnectionEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HybridConnectionEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HybridConnectionEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "HybridConnection" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HybridConnectionEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_hybridconnectioneventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_hybridconnectioneventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..246fe52a443 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_hybridconnectioneventsubscriptiondestinationproperties.go @@ -0,0 +1,49 @@ +package eventsubscriptions + +import ( + "encoding/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 HybridConnectionEventSubscriptionDestinationProperties struct { + DeliveryAttributeMappings *[]DeliveryAttributeMapping `json:"deliveryAttributeMappings,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} + +var _ json.Unmarshaler = &HybridConnectionEventSubscriptionDestinationProperties{} + +func (s *HybridConnectionEventSubscriptionDestinationProperties) UnmarshalJSON(bytes []byte) error { + type alias HybridConnectionEventSubscriptionDestinationProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into HybridConnectionEventSubscriptionDestinationProperties: %+v", err) + } + + s.ResourceId = decoded.ResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling HybridConnectionEventSubscriptionDestinationProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deliveryAttributeMappings"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DeliveryAttributeMappings into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryAttributeMapping, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryAttributeMappingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DeliveryAttributeMappings' for 'HybridConnectionEventSubscriptionDestinationProperties': %+v", i, err) + } + output = append(output, impl) + } + s.DeliveryAttributeMappings = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnotnulladvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnotnulladvancedfilter.go new file mode 100644 index 00000000000..46438113a68 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnotnulladvancedfilter.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = IsNotNullAdvancedFilter{} + +type IsNotNullAdvancedFilter struct { + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = IsNotNullAdvancedFilter{} + +func (s IsNotNullAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper IsNotNullAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IsNotNullAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IsNotNullAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "IsNotNull" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IsNotNullAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnotnullfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnotnullfilter.go new file mode 100644 index 00000000000..6fc33d51178 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnotnullfilter.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = IsNotNullFilter{} + +type IsNotNullFilter struct { + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = IsNotNullFilter{} + +func (s IsNotNullFilter) MarshalJSON() ([]byte, error) { + type wrapper IsNotNullFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IsNotNullFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IsNotNullFilter: %+v", err) + } + decoded["operatorType"] = "IsNotNull" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IsNotNullFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnullorundefinedadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnullorundefinedadvancedfilter.go new file mode 100644 index 00000000000..bd5ffc5807b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnullorundefinedadvancedfilter.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = IsNullOrUndefinedAdvancedFilter{} + +type IsNullOrUndefinedAdvancedFilter struct { + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = IsNullOrUndefinedAdvancedFilter{} + +func (s IsNullOrUndefinedAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper IsNullOrUndefinedAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IsNullOrUndefinedAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IsNullOrUndefinedAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "IsNullOrUndefined" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IsNullOrUndefinedAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnullorundefinedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnullorundefinedfilter.go new file mode 100644 index 00000000000..7f6f64bce45 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_isnullorundefinedfilter.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = IsNullOrUndefinedFilter{} + +type IsNullOrUndefinedFilter struct { + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = IsNullOrUndefinedFilter{} + +func (s IsNullOrUndefinedFilter) MarshalJSON() ([]byte, error) { + type wrapper IsNullOrUndefinedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IsNullOrUndefinedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IsNullOrUndefinedFilter: %+v", err) + } + decoded["operatorType"] = "IsNullOrUndefined" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IsNullOrUndefinedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_monitoralerteventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_monitoralerteventsubscriptiondestination.go new file mode 100644 index 00000000000..80a73b1e6b0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_monitoralerteventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = MonitorAlertEventSubscriptionDestination{} + +type MonitorAlertEventSubscriptionDestination struct { + Properties *MonitorAlertEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = MonitorAlertEventSubscriptionDestination{} + +func (s MonitorAlertEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper MonitorAlertEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MonitorAlertEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MonitorAlertEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "MonitorAlert" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MonitorAlertEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_monitoralerteventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_monitoralerteventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..cbdb87f7e1f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_monitoralerteventsubscriptiondestinationproperties.go @@ -0,0 +1,10 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorAlertEventSubscriptionDestinationProperties struct { + ActionGroups *[]string `json:"actionGroups,omitempty"` + Description *string `json:"description,omitempty"` + Severity *MonitorAlertSeverity `json:"severity,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_namespacetopiceventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_namespacetopiceventsubscriptiondestination.go new file mode 100644 index 00000000000..9d619dbec18 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_namespacetopiceventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = NamespaceTopicEventSubscriptionDestination{} + +type NamespaceTopicEventSubscriptionDestination struct { + Properties *NamespaceTopicEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = NamespaceTopicEventSubscriptionDestination{} + +func (s NamespaceTopicEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper NamespaceTopicEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NamespaceTopicEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NamespaceTopicEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "NamespaceTopic" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NamespaceTopicEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_namespacetopiceventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_namespacetopiceventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..f6a4d4eaf11 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_namespacetopiceventsubscriptiondestinationproperties.go @@ -0,0 +1,8 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceTopicEventSubscriptionDestinationProperties struct { + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanadvancedfilter.go new file mode 100644 index 00000000000..84909978854 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberGreaterThanAdvancedFilter{} + +type NumberGreaterThanAdvancedFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberGreaterThanAdvancedFilter{} + +func (s NumberGreaterThanAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberGreaterThanAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberGreaterThanAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberGreaterThanAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberGreaterThan" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberGreaterThanAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanfilter.go new file mode 100644 index 00000000000..dcba1e688f0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberGreaterThanFilter{} + +type NumberGreaterThanFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberGreaterThanFilter{} + +func (s NumberGreaterThanFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberGreaterThanFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberGreaterThanFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberGreaterThanFilter: %+v", err) + } + decoded["operatorType"] = "NumberGreaterThan" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberGreaterThanFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanorequalsadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanorequalsadvancedfilter.go new file mode 100644 index 00000000000..65713cba2eb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanorequalsadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberGreaterThanOrEqualsAdvancedFilter{} + +type NumberGreaterThanOrEqualsAdvancedFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberGreaterThanOrEqualsAdvancedFilter{} + +func (s NumberGreaterThanOrEqualsAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberGreaterThanOrEqualsAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberGreaterThanOrEqualsAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberGreaterThanOrEqualsAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberGreaterThanOrEquals" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberGreaterThanOrEqualsAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanorequalsfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanorequalsfilter.go new file mode 100644 index 00000000000..5ab37ee6507 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbergreaterthanorequalsfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberGreaterThanOrEqualsFilter{} + +type NumberGreaterThanOrEqualsFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberGreaterThanOrEqualsFilter{} + +func (s NumberGreaterThanOrEqualsFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberGreaterThanOrEqualsFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberGreaterThanOrEqualsFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberGreaterThanOrEqualsFilter: %+v", err) + } + decoded["operatorType"] = "NumberGreaterThanOrEquals" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberGreaterThanOrEqualsFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinadvancedfilter.go new file mode 100644 index 00000000000..211f9800a91 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberInAdvancedFilter{} + +type NumberInAdvancedFilter struct { + Values *[]float64 `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberInAdvancedFilter{} + +func (s NumberInAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberInAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberInAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberInAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberInAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinfilter.go new file mode 100644 index 00000000000..04c614c9dd4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberInFilter{} + +type NumberInFilter struct { + Values *[]float64 `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberInFilter{} + +func (s NumberInFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberInFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberInFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberInFilter: %+v", err) + } + decoded["operatorType"] = "NumberIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberInFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinrangeadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinrangeadvancedfilter.go new file mode 100644 index 00000000000..1d3a5ea9774 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinrangeadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberInRangeAdvancedFilter{} + +type NumberInRangeAdvancedFilter struct { + Values *[][]float64 `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberInRangeAdvancedFilter{} + +func (s NumberInRangeAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberInRangeAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberInRangeAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberInRangeAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberInRange" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberInRangeAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinrangefilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinrangefilter.go new file mode 100644 index 00000000000..1d19f6b645f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberinrangefilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberInRangeFilter{} + +type NumberInRangeFilter struct { + Values *[][]float64 `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberInRangeFilter{} + +func (s NumberInRangeFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberInRangeFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberInRangeFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberInRangeFilter: %+v", err) + } + decoded["operatorType"] = "NumberInRange" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberInRangeFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanadvancedfilter.go new file mode 100644 index 00000000000..1cb7714062a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberLessThanAdvancedFilter{} + +type NumberLessThanAdvancedFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberLessThanAdvancedFilter{} + +func (s NumberLessThanAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberLessThanAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberLessThanAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberLessThanAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberLessThan" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberLessThanAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanfilter.go new file mode 100644 index 00000000000..356bbd64ceb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberLessThanFilter{} + +type NumberLessThanFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberLessThanFilter{} + +func (s NumberLessThanFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberLessThanFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberLessThanFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberLessThanFilter: %+v", err) + } + decoded["operatorType"] = "NumberLessThan" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberLessThanFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanorequalsadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanorequalsadvancedfilter.go new file mode 100644 index 00000000000..3863059df16 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanorequalsadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberLessThanOrEqualsAdvancedFilter{} + +type NumberLessThanOrEqualsAdvancedFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberLessThanOrEqualsAdvancedFilter{} + +func (s NumberLessThanOrEqualsAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberLessThanOrEqualsAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberLessThanOrEqualsAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberLessThanOrEqualsAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberLessThanOrEquals" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberLessThanOrEqualsAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanorequalsfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanorequalsfilter.go new file mode 100644 index 00000000000..299e0d5aba6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numberlessthanorequalsfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberLessThanOrEqualsFilter{} + +type NumberLessThanOrEqualsFilter struct { + Value *float64 `json:"value,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberLessThanOrEqualsFilter{} + +func (s NumberLessThanOrEqualsFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberLessThanOrEqualsFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberLessThanOrEqualsFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberLessThanOrEqualsFilter: %+v", err) + } + decoded["operatorType"] = "NumberLessThanOrEquals" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberLessThanOrEqualsFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinadvancedfilter.go new file mode 100644 index 00000000000..495b6bbeae4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberNotInAdvancedFilter{} + +type NumberNotInAdvancedFilter struct { + Values *[]float64 `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberNotInAdvancedFilter{} + +func (s NumberNotInAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberNotInAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberNotInAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberNotInAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberNotIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberNotInAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinfilter.go new file mode 100644 index 00000000000..193872f33ab --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberNotInFilter{} + +type NumberNotInFilter struct { + Values *[]float64 `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberNotInFilter{} + +func (s NumberNotInFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberNotInFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberNotInFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberNotInFilter: %+v", err) + } + decoded["operatorType"] = "NumberNotIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberNotInFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinrangeadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinrangeadvancedfilter.go new file mode 100644 index 00000000000..943c558903f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinrangeadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = NumberNotInRangeAdvancedFilter{} + +type NumberNotInRangeAdvancedFilter struct { + Values *[][]float64 `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberNotInRangeAdvancedFilter{} + +func (s NumberNotInRangeAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberNotInRangeAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberNotInRangeAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberNotInRangeAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "NumberNotInRange" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberNotInRangeAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinrangefilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinrangefilter.go new file mode 100644 index 00000000000..9fb5d996c49 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_numbernotinrangefilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = NumberNotInRangeFilter{} + +type NumberNotInRangeFilter struct { + Values *[][]float64 `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = NumberNotInRangeFilter{} + +func (s NumberNotInRangeFilter) MarshalJSON() ([]byte, error) { + type wrapper NumberNotInRangeFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling NumberNotInRangeFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling NumberNotInRangeFilter: %+v", err) + } + decoded["operatorType"] = "NumberNotInRange" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling NumberNotInRangeFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_partnereventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_partnereventsubscriptiondestination.go new file mode 100644 index 00000000000..1dafb8e110c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_partnereventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = PartnerEventSubscriptionDestination{} + +type PartnerEventSubscriptionDestination struct { + Properties *PartnerEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = PartnerEventSubscriptionDestination{} + +func (s PartnerEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper PartnerEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PartnerEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PartnerEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "PartnerDestination" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PartnerEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_partnereventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_partnereventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..ebb0bd9c977 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_partnereventsubscriptiondestinationproperties.go @@ -0,0 +1,8 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerEventSubscriptionDestinationProperties struct { + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_pushinfo.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_pushinfo.go new file mode 100644 index 00000000000..07b5e16f4bc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_pushinfo.go @@ -0,0 +1,11 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PushInfo struct { + DeadLetterDestinationWithResourceIdentity *DeadLetterWithResourceIdentity `json:"deadLetterDestinationWithResourceIdentity,omitempty"` + DeliveryWithResourceIdentity *DeliveryWithResourceIdentity `json:"deliveryWithResourceIdentity,omitempty"` + EventTimeToLive *string `json:"eventTimeToLive,omitempty"` + MaxDeliveryCount *int64 `json:"maxDeliveryCount,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_queueinfo.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_queueinfo.go new file mode 100644 index 00000000000..05177111b27 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_queueinfo.go @@ -0,0 +1,11 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueueInfo struct { + DeadLetterDestinationWithResourceIdentity *DeadLetterWithResourceIdentity `json:"deadLetterDestinationWithResourceIdentity,omitempty"` + EventTimeToLive *string `json:"eventTimeToLive,omitempty"` + MaxDeliveryCount *int64 `json:"maxDeliveryCount,omitempty"` + ReceiveLockDurationInSeconds *int64 `json:"receiveLockDurationInSeconds,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_retrypolicy.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_retrypolicy.go new file mode 100644 index 00000000000..65ee20a8f01 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_retrypolicy.go @@ -0,0 +1,9 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetryPolicy struct { + EventTimeToLiveInMinutes *int64 `json:"eventTimeToLiveInMinutes,omitempty"` + MaxDeliveryAttempts *int64 `json:"maxDeliveryAttempts,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebusqueueeventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebusqueueeventsubscriptiondestination.go new file mode 100644 index 00000000000..8b63b749850 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebusqueueeventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = ServiceBusQueueEventSubscriptionDestination{} + +type ServiceBusQueueEventSubscriptionDestination struct { + Properties *ServiceBusQueueEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = ServiceBusQueueEventSubscriptionDestination{} + +func (s ServiceBusQueueEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper ServiceBusQueueEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ServiceBusQueueEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ServiceBusQueueEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "ServiceBusQueue" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ServiceBusQueueEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebusqueueeventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebusqueueeventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..abb0204b430 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebusqueueeventsubscriptiondestinationproperties.go @@ -0,0 +1,49 @@ +package eventsubscriptions + +import ( + "encoding/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 ServiceBusQueueEventSubscriptionDestinationProperties struct { + DeliveryAttributeMappings *[]DeliveryAttributeMapping `json:"deliveryAttributeMappings,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} + +var _ json.Unmarshaler = &ServiceBusQueueEventSubscriptionDestinationProperties{} + +func (s *ServiceBusQueueEventSubscriptionDestinationProperties) UnmarshalJSON(bytes []byte) error { + type alias ServiceBusQueueEventSubscriptionDestinationProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ServiceBusQueueEventSubscriptionDestinationProperties: %+v", err) + } + + s.ResourceId = decoded.ResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ServiceBusQueueEventSubscriptionDestinationProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deliveryAttributeMappings"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DeliveryAttributeMappings into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryAttributeMapping, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryAttributeMappingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DeliveryAttributeMappings' for 'ServiceBusQueueEventSubscriptionDestinationProperties': %+v", i, err) + } + output = append(output, impl) + } + s.DeliveryAttributeMappings = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebustopiceventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebustopiceventsubscriptiondestination.go new file mode 100644 index 00000000000..a3b47d8a5b5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebustopiceventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = ServiceBusTopicEventSubscriptionDestination{} + +type ServiceBusTopicEventSubscriptionDestination struct { + Properties *ServiceBusTopicEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = ServiceBusTopicEventSubscriptionDestination{} + +func (s ServiceBusTopicEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper ServiceBusTopicEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ServiceBusTopicEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ServiceBusTopicEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "ServiceBusTopic" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ServiceBusTopicEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebustopiceventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebustopiceventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..30e8fa6cb26 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_servicebustopiceventsubscriptiondestinationproperties.go @@ -0,0 +1,49 @@ +package eventsubscriptions + +import ( + "encoding/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 ServiceBusTopicEventSubscriptionDestinationProperties struct { + DeliveryAttributeMappings *[]DeliveryAttributeMapping `json:"deliveryAttributeMappings,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} + +var _ json.Unmarshaler = &ServiceBusTopicEventSubscriptionDestinationProperties{} + +func (s *ServiceBusTopicEventSubscriptionDestinationProperties) UnmarshalJSON(bytes []byte) error { + type alias ServiceBusTopicEventSubscriptionDestinationProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into ServiceBusTopicEventSubscriptionDestinationProperties: %+v", err) + } + + s.ResourceId = decoded.ResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ServiceBusTopicEventSubscriptionDestinationProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deliveryAttributeMappings"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DeliveryAttributeMappings into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryAttributeMapping, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryAttributeMappingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DeliveryAttributeMappings' for 'ServiceBusTopicEventSubscriptionDestinationProperties': %+v", i, err) + } + output = append(output, impl) + } + s.DeliveryAttributeMappings = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_staticdeliveryattributemapping.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_staticdeliveryattributemapping.go new file mode 100644 index 00000000000..efc11b99fa1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_staticdeliveryattributemapping.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeliveryAttributeMapping = StaticDeliveryAttributeMapping{} + +type StaticDeliveryAttributeMapping struct { + Properties *StaticDeliveryAttributeMappingProperties `json:"properties,omitempty"` + + // Fields inherited from DeliveryAttributeMapping + Name *string `json:"name,omitempty"` +} + +var _ json.Marshaler = StaticDeliveryAttributeMapping{} + +func (s StaticDeliveryAttributeMapping) MarshalJSON() ([]byte, error) { + type wrapper StaticDeliveryAttributeMapping + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StaticDeliveryAttributeMapping: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StaticDeliveryAttributeMapping: %+v", err) + } + decoded["type"] = "Static" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StaticDeliveryAttributeMapping: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_staticdeliveryattributemappingproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_staticdeliveryattributemappingproperties.go new file mode 100644 index 00000000000..349c78faaa9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_staticdeliveryattributemappingproperties.go @@ -0,0 +1,9 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StaticDeliveryAttributeMappingProperties struct { + IsSecret *bool `json:"isSecret,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storageblobdeadletterdestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storageblobdeadletterdestination.go new file mode 100644 index 00000000000..7c184d520ac --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storageblobdeadletterdestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeadLetterDestination = StorageBlobDeadLetterDestination{} + +type StorageBlobDeadLetterDestination struct { + Properties *StorageBlobDeadLetterDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from DeadLetterDestination +} + +var _ json.Marshaler = StorageBlobDeadLetterDestination{} + +func (s StorageBlobDeadLetterDestination) MarshalJSON() ([]byte, error) { + type wrapper StorageBlobDeadLetterDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StorageBlobDeadLetterDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StorageBlobDeadLetterDestination: %+v", err) + } + decoded["endpointType"] = "StorageBlob" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StorageBlobDeadLetterDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storageblobdeadletterdestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storageblobdeadletterdestinationproperties.go new file mode 100644 index 00000000000..9a9bd41a196 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storageblobdeadletterdestinationproperties.go @@ -0,0 +1,9 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageBlobDeadLetterDestinationProperties struct { + BlobContainerName *string `json:"blobContainerName,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storagequeueeventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storagequeueeventsubscriptiondestination.go new file mode 100644 index 00000000000..6c86f8a335b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storagequeueeventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = StorageQueueEventSubscriptionDestination{} + +type StorageQueueEventSubscriptionDestination struct { + Properties *StorageQueueEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = StorageQueueEventSubscriptionDestination{} + +func (s StorageQueueEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper StorageQueueEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StorageQueueEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StorageQueueEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "StorageQueue" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StorageQueueEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storagequeueeventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storagequeueeventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..59c0233be77 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_storagequeueeventsubscriptiondestinationproperties.go @@ -0,0 +1,10 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageQueueEventSubscriptionDestinationProperties struct { + QueueMessageTimeToLiveInSeconds *int64 `json:"queueMessageTimeToLiveInSeconds,omitempty"` + QueueName *string `json:"queueName,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringbeginswithadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringbeginswithadvancedfilter.go new file mode 100644 index 00000000000..cafeef39433 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringbeginswithadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringBeginsWithAdvancedFilter{} + +type StringBeginsWithAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringBeginsWithAdvancedFilter{} + +func (s StringBeginsWithAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringBeginsWithAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringBeginsWithAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringBeginsWithAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringBeginsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringBeginsWithAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringbeginswithfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringbeginswithfilter.go new file mode 100644 index 00000000000..0c967fd5e9b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringbeginswithfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringBeginsWithFilter{} + +type StringBeginsWithFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringBeginsWithFilter{} + +func (s StringBeginsWithFilter) MarshalJSON() ([]byte, error) { + type wrapper StringBeginsWithFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringBeginsWithFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringBeginsWithFilter: %+v", err) + } + decoded["operatorType"] = "StringBeginsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringBeginsWithFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringcontainsadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringcontainsadvancedfilter.go new file mode 100644 index 00000000000..3a3d2697939 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringcontainsadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringContainsAdvancedFilter{} + +type StringContainsAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringContainsAdvancedFilter{} + +func (s StringContainsAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringContainsAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringContainsAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringContainsAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringContains" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringContainsAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringcontainsfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringcontainsfilter.go new file mode 100644 index 00000000000..3140c6e2a42 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringcontainsfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringContainsFilter{} + +type StringContainsFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringContainsFilter{} + +func (s StringContainsFilter) MarshalJSON() ([]byte, error) { + type wrapper StringContainsFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringContainsFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringContainsFilter: %+v", err) + } + decoded["operatorType"] = "StringContains" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringContainsFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringendswithadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringendswithadvancedfilter.go new file mode 100644 index 00000000000..aedb41f4e0d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringendswithadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringEndsWithAdvancedFilter{} + +type StringEndsWithAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringEndsWithAdvancedFilter{} + +func (s StringEndsWithAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringEndsWithAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringEndsWithAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringEndsWithAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringEndsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringEndsWithAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringendswithfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringendswithfilter.go new file mode 100644 index 00000000000..89b3923e85d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringendswithfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringEndsWithFilter{} + +type StringEndsWithFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringEndsWithFilter{} + +func (s StringEndsWithFilter) MarshalJSON() ([]byte, error) { + type wrapper StringEndsWithFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringEndsWithFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringEndsWithFilter: %+v", err) + } + decoded["operatorType"] = "StringEndsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringEndsWithFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringinadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringinadvancedfilter.go new file mode 100644 index 00000000000..d0fd2071fff --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringinadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringInAdvancedFilter{} + +type StringInAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringInAdvancedFilter{} + +func (s StringInAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringInAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringInAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringInAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringInAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringinfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringinfilter.go new file mode 100644 index 00000000000..d8d2a7b5386 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringinfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringInFilter{} + +type StringInFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringInFilter{} + +func (s StringInFilter) MarshalJSON() ([]byte, error) { + type wrapper StringInFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringInFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringInFilter: %+v", err) + } + decoded["operatorType"] = "StringIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringInFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotbeginswithadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotbeginswithadvancedfilter.go new file mode 100644 index 00000000000..cbc797c37f3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotbeginswithadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringNotBeginsWithAdvancedFilter{} + +type StringNotBeginsWithAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotBeginsWithAdvancedFilter{} + +func (s StringNotBeginsWithAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotBeginsWithAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotBeginsWithAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotBeginsWithAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringNotBeginsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotBeginsWithAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotbeginswithfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotbeginswithfilter.go new file mode 100644 index 00000000000..2fc2d2b7130 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotbeginswithfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringNotBeginsWithFilter{} + +type StringNotBeginsWithFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotBeginsWithFilter{} + +func (s StringNotBeginsWithFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotBeginsWithFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotBeginsWithFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotBeginsWithFilter: %+v", err) + } + decoded["operatorType"] = "StringNotBeginsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotBeginsWithFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotcontainsadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotcontainsadvancedfilter.go new file mode 100644 index 00000000000..8a20e0daf71 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotcontainsadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringNotContainsAdvancedFilter{} + +type StringNotContainsAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotContainsAdvancedFilter{} + +func (s StringNotContainsAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotContainsAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotContainsAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotContainsAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringNotContains" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotContainsAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotcontainsfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotcontainsfilter.go new file mode 100644 index 00000000000..c73f42c48a2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotcontainsfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringNotContainsFilter{} + +type StringNotContainsFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotContainsFilter{} + +func (s StringNotContainsFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotContainsFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotContainsFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotContainsFilter: %+v", err) + } + decoded["operatorType"] = "StringNotContains" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotContainsFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotendswithadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotendswithadvancedfilter.go new file mode 100644 index 00000000000..c892f63ac36 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotendswithadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringNotEndsWithAdvancedFilter{} + +type StringNotEndsWithAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotEndsWithAdvancedFilter{} + +func (s StringNotEndsWithAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotEndsWithAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotEndsWithAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotEndsWithAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringNotEndsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotEndsWithAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotendswithfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotendswithfilter.go new file mode 100644 index 00000000000..e334f308789 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotendswithfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringNotEndsWithFilter{} + +type StringNotEndsWithFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotEndsWithFilter{} + +func (s StringNotEndsWithFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotEndsWithFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotEndsWithFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotEndsWithFilter: %+v", err) + } + decoded["operatorType"] = "StringNotEndsWith" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotEndsWithFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotinadvancedfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotinadvancedfilter.go new file mode 100644 index 00000000000..da8aeb09107 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotinadvancedfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AdvancedFilter = StringNotInAdvancedFilter{} + +type StringNotInAdvancedFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from AdvancedFilter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotInAdvancedFilter{} + +func (s StringNotInAdvancedFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotInAdvancedFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotInAdvancedFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotInAdvancedFilter: %+v", err) + } + decoded["operatorType"] = "StringNotIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotInAdvancedFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotinfilter.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotinfilter.go new file mode 100644 index 00000000000..b811d3c8f9b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_stringnotinfilter.go @@ -0,0 +1,42 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Filter = StringNotInFilter{} + +type StringNotInFilter struct { + Values *[]string `json:"values,omitempty"` + + // Fields inherited from Filter + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StringNotInFilter{} + +func (s StringNotInFilter) MarshalJSON() ([]byte, error) { + type wrapper StringNotInFilter + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StringNotInFilter: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StringNotInFilter: %+v", err) + } + decoded["operatorType"] = "StringNotIn" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StringNotInFilter: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscription.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscription.go new file mode 100644 index 00000000000..33624e4bfd0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscription.go @@ -0,0 +1,16 @@ +package eventsubscriptions + +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 Subscription struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionproperties.go new file mode 100644 index 00000000000..411019d22fb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionproperties.go @@ -0,0 +1,11 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionProperties struct { + DeliveryConfiguration *DeliveryConfiguration `json:"deliveryConfiguration,omitempty"` + EventDeliverySchema *DeliverySchema `json:"eventDeliverySchema,omitempty"` + FiltersConfiguration *FiltersConfiguration `json:"filtersConfiguration,omitempty"` + ProvisioningState *SubscriptionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionupdateparameters.go new file mode 100644 index 00000000000..76774cacb1f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionupdateparameters.go @@ -0,0 +1,8 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionUpdateParameters struct { + Properties *SubscriptionUpdateParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionupdateparametersproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionupdateparametersproperties.go new file mode 100644 index 00000000000..eb0122ae444 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_subscriptionupdateparametersproperties.go @@ -0,0 +1,10 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionUpdateParametersProperties struct { + DeliveryConfiguration *DeliveryConfiguration `json:"deliveryConfiguration,omitempty"` + EventDeliverySchema *DeliverySchema `json:"eventDeliverySchema,omitempty"` + FiltersConfiguration *FiltersConfiguration `json:"filtersConfiguration,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_webhookeventsubscriptiondestination.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_webhookeventsubscriptiondestination.go new file mode 100644 index 00000000000..a64dd7ca0b4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_webhookeventsubscriptiondestination.go @@ -0,0 +1,41 @@ +package eventsubscriptions + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ EventSubscriptionDestination = WebHookEventSubscriptionDestination{} + +type WebHookEventSubscriptionDestination struct { + Properties *WebHookEventSubscriptionDestinationProperties `json:"properties,omitempty"` + + // Fields inherited from EventSubscriptionDestination +} + +var _ json.Marshaler = WebHookEventSubscriptionDestination{} + +func (s WebHookEventSubscriptionDestination) MarshalJSON() ([]byte, error) { + type wrapper WebHookEventSubscriptionDestination + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling WebHookEventSubscriptionDestination: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling WebHookEventSubscriptionDestination: %+v", err) + } + decoded["endpointType"] = "WebHook" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling WebHookEventSubscriptionDestination: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_webhookeventsubscriptiondestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_webhookeventsubscriptiondestinationproperties.go new file mode 100644 index 00000000000..e5ec10da4ab --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/model_webhookeventsubscriptiondestinationproperties.go @@ -0,0 +1,61 @@ +package eventsubscriptions + +import ( + "encoding/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 WebHookEventSubscriptionDestinationProperties struct { + AzureActiveDirectoryApplicationIdOrUri *string `json:"azureActiveDirectoryApplicationIdOrUri,omitempty"` + AzureActiveDirectoryTenantId *string `json:"azureActiveDirectoryTenantId,omitempty"` + DeliveryAttributeMappings *[]DeliveryAttributeMapping `json:"deliveryAttributeMappings,omitempty"` + EndpointBaseUrl *string `json:"endpointBaseUrl,omitempty"` + EndpointUrl *string `json:"endpointUrl,omitempty"` + MaxEventsPerBatch *int64 `json:"maxEventsPerBatch,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PreferredBatchSizeInKilobytes *int64 `json:"preferredBatchSizeInKilobytes,omitempty"` +} + +var _ json.Unmarshaler = &WebHookEventSubscriptionDestinationProperties{} + +func (s *WebHookEventSubscriptionDestinationProperties) UnmarshalJSON(bytes []byte) error { + type alias WebHookEventSubscriptionDestinationProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into WebHookEventSubscriptionDestinationProperties: %+v", err) + } + + s.AzureActiveDirectoryApplicationIdOrUri = decoded.AzureActiveDirectoryApplicationIdOrUri + s.AzureActiveDirectoryTenantId = decoded.AzureActiveDirectoryTenantId + s.EndpointBaseUrl = decoded.EndpointBaseUrl + s.EndpointUrl = decoded.EndpointUrl + s.MaxEventsPerBatch = decoded.MaxEventsPerBatch + s.MinimumTlsVersionAllowed = decoded.MinimumTlsVersionAllowed + s.PreferredBatchSizeInKilobytes = decoded.PreferredBatchSizeInKilobytes + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling WebHookEventSubscriptionDestinationProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deliveryAttributeMappings"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DeliveryAttributeMappings into list []json.RawMessage: %+v", err) + } + + output := make([]DeliveryAttributeMapping, 0) + for i, val := range listTemp { + impl, err := unmarshalDeliveryAttributeMappingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DeliveryAttributeMappings' for 'WebHookEventSubscriptionDestinationProperties': %+v", i, err) + } + output = append(output, impl) + } + s.DeliveryAttributeMappings = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/predicates.go new file mode 100644 index 00000000000..ae061d3003d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/predicates.go @@ -0,0 +1,50 @@ +package eventsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventSubscriptionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p EventSubscriptionOperationPredicate) Matches(input EventSubscription) 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 SubscriptionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SubscriptionOperationPredicate) Matches(input Subscription) 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/eventgrid/2023-12-15-preview/eventsubscriptions/version.go b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/version.go new file mode 100644 index 00000000000..d6ffac6b5ca --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/eventsubscriptions/version.go @@ -0,0 +1,12 @@ +package eventsubscriptions + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/eventsubscriptions/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/README.md b/resource-manager/eventgrid/2023-12-15-preview/namespaces/README.md new file mode 100644 index 00000000000..534dfb9ce80 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/README.md @@ -0,0 +1,150 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/namespaces` Documentation + +The `namespaces` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/namespaces" +``` + + +### Client Initialization + +```go +client := namespaces.NewNamespacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NamespacesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := namespaces.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +payload := namespaces.Namespace{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamespacesClient.Delete` + +```go +ctx := context.TODO() +id := namespaces.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamespacesClient.Get` + +```go +ctx := context.TODO() +id := namespaces.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +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: `NamespacesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, namespaces.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, namespaces.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NamespacesClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, namespaces.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, namespaces.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NamespacesClient.ListSharedAccessKeys` + +```go +ctx := context.TODO() +id := namespaces.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +read, err := client.ListSharedAccessKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamespacesClient.RegenerateKey` + +```go +ctx := context.TODO() +id := namespaces.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +payload := namespaces.NamespaceRegenerateKeyRequest{ + // ... +} + + +if err := client.RegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamespacesClient.Update` + +```go +ctx := context.TODO() +id := namespaces.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +payload := namespaces.NamespaceUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/client.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/client.go new file mode 100644 index 00000000000..c0bca4870e1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/client.go @@ -0,0 +1,26 @@ +package namespaces + +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 NamespacesClient struct { + Client *resourcemanager.Client +} + +func NewNamespacesClientWithBaseURI(sdkApi sdkEnv.Api) (*NamespacesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "namespaces", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NamespacesClient: %+v", err) + } + + return &NamespacesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/constants.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/constants.go new file mode 100644 index 00000000000..615d8104f78 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/constants.go @@ -0,0 +1,512 @@ +package namespaces + +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 AlternativeAuthenticationNameSource string + +const ( + AlternativeAuthenticationNameSourceClientCertificateDns AlternativeAuthenticationNameSource = "ClientCertificateDns" + AlternativeAuthenticationNameSourceClientCertificateEmail AlternativeAuthenticationNameSource = "ClientCertificateEmail" + AlternativeAuthenticationNameSourceClientCertificateIP AlternativeAuthenticationNameSource = "ClientCertificateIp" + AlternativeAuthenticationNameSourceClientCertificateSubject AlternativeAuthenticationNameSource = "ClientCertificateSubject" + AlternativeAuthenticationNameSourceClientCertificateUri AlternativeAuthenticationNameSource = "ClientCertificateUri" +) + +func PossibleValuesForAlternativeAuthenticationNameSource() []string { + return []string{ + string(AlternativeAuthenticationNameSourceClientCertificateDns), + string(AlternativeAuthenticationNameSourceClientCertificateEmail), + string(AlternativeAuthenticationNameSourceClientCertificateIP), + string(AlternativeAuthenticationNameSourceClientCertificateSubject), + string(AlternativeAuthenticationNameSourceClientCertificateUri), + } +} + +func (s *AlternativeAuthenticationNameSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlternativeAuthenticationNameSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlternativeAuthenticationNameSource(input string) (*AlternativeAuthenticationNameSource, error) { + vals := map[string]AlternativeAuthenticationNameSource{ + "clientcertificatedns": AlternativeAuthenticationNameSourceClientCertificateDns, + "clientcertificateemail": AlternativeAuthenticationNameSourceClientCertificateEmail, + "clientcertificateip": AlternativeAuthenticationNameSourceClientCertificateIP, + "clientcertificatesubject": AlternativeAuthenticationNameSourceClientCertificateSubject, + "clientcertificateuri": AlternativeAuthenticationNameSourceClientCertificateUri, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlternativeAuthenticationNameSource(input) + return &out, nil +} + +type IPActionType string + +const ( + IPActionTypeAllow IPActionType = "Allow" +) + +func PossibleValuesForIPActionType() []string { + return []string{ + string(IPActionTypeAllow), + } +} + +func (s *IPActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIPActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIPActionType(input string) (*IPActionType, error) { + vals := map[string]IPActionType{ + "allow": IPActionTypeAllow, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPActionType(input) + return &out, nil +} + +type NamespaceProvisioningState string + +const ( + NamespaceProvisioningStateCanceled NamespaceProvisioningState = "Canceled" + NamespaceProvisioningStateCreateFailed NamespaceProvisioningState = "CreateFailed" + NamespaceProvisioningStateCreating NamespaceProvisioningState = "Creating" + NamespaceProvisioningStateDeleteFailed NamespaceProvisioningState = "DeleteFailed" + NamespaceProvisioningStateDeleted NamespaceProvisioningState = "Deleted" + NamespaceProvisioningStateDeleting NamespaceProvisioningState = "Deleting" + NamespaceProvisioningStateFailed NamespaceProvisioningState = "Failed" + NamespaceProvisioningStateSucceeded NamespaceProvisioningState = "Succeeded" + NamespaceProvisioningStateUpdatedFailed NamespaceProvisioningState = "UpdatedFailed" + NamespaceProvisioningStateUpdating NamespaceProvisioningState = "Updating" +) + +func PossibleValuesForNamespaceProvisioningState() []string { + return []string{ + string(NamespaceProvisioningStateCanceled), + string(NamespaceProvisioningStateCreateFailed), + string(NamespaceProvisioningStateCreating), + string(NamespaceProvisioningStateDeleteFailed), + string(NamespaceProvisioningStateDeleted), + string(NamespaceProvisioningStateDeleting), + string(NamespaceProvisioningStateFailed), + string(NamespaceProvisioningStateSucceeded), + string(NamespaceProvisioningStateUpdatedFailed), + string(NamespaceProvisioningStateUpdating), + } +} + +func (s *NamespaceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNamespaceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNamespaceProvisioningState(input string) (*NamespaceProvisioningState, error) { + vals := map[string]NamespaceProvisioningState{ + "canceled": NamespaceProvisioningStateCanceled, + "createfailed": NamespaceProvisioningStateCreateFailed, + "creating": NamespaceProvisioningStateCreating, + "deletefailed": NamespaceProvisioningStateDeleteFailed, + "deleted": NamespaceProvisioningStateDeleted, + "deleting": NamespaceProvisioningStateDeleting, + "failed": NamespaceProvisioningStateFailed, + "succeeded": NamespaceProvisioningStateSucceeded, + "updatedfailed": NamespaceProvisioningStateUpdatedFailed, + "updating": NamespaceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NamespaceProvisioningState(input) + return &out, nil +} + +type PersistedConnectionStatus string + +const ( + PersistedConnectionStatusApproved PersistedConnectionStatus = "Approved" + PersistedConnectionStatusDisconnected PersistedConnectionStatus = "Disconnected" + PersistedConnectionStatusPending PersistedConnectionStatus = "Pending" + PersistedConnectionStatusRejected PersistedConnectionStatus = "Rejected" +) + +func PossibleValuesForPersistedConnectionStatus() []string { + return []string{ + string(PersistedConnectionStatusApproved), + string(PersistedConnectionStatusDisconnected), + string(PersistedConnectionStatusPending), + string(PersistedConnectionStatusRejected), + } +} + +func (s *PersistedConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePersistedConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePersistedConnectionStatus(input string) (*PersistedConnectionStatus, error) { + vals := map[string]PersistedConnectionStatus{ + "approved": PersistedConnectionStatusApproved, + "disconnected": PersistedConnectionStatusDisconnected, + "pending": PersistedConnectionStatusPending, + "rejected": PersistedConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersistedConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" + PublicNetworkAccessSecuredByPerimeter PublicNetworkAccess = "SecuredByPerimeter" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + string(PublicNetworkAccessSecuredByPerimeter), + } +} + +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, + "securedbyperimeter": PublicNetworkAccessSecuredByPerimeter, + } + 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 ResourceProvisioningState string + +const ( + ResourceProvisioningStateCanceled ResourceProvisioningState = "Canceled" + ResourceProvisioningStateCreating ResourceProvisioningState = "Creating" + ResourceProvisioningStateDeleting ResourceProvisioningState = "Deleting" + ResourceProvisioningStateFailed ResourceProvisioningState = "Failed" + ResourceProvisioningStateSucceeded ResourceProvisioningState = "Succeeded" + ResourceProvisioningStateUpdating ResourceProvisioningState = "Updating" +) + +func PossibleValuesForResourceProvisioningState() []string { + return []string{ + string(ResourceProvisioningStateCanceled), + string(ResourceProvisioningStateCreating), + string(ResourceProvisioningStateDeleting), + string(ResourceProvisioningStateFailed), + string(ResourceProvisioningStateSucceeded), + string(ResourceProvisioningStateUpdating), + } +} + +func (s *ResourceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceProvisioningState(input string) (*ResourceProvisioningState, error) { + vals := map[string]ResourceProvisioningState{ + "canceled": ResourceProvisioningStateCanceled, + "creating": ResourceProvisioningStateCreating, + "deleting": ResourceProvisioningStateDeleting, + "failed": ResourceProvisioningStateFailed, + "succeeded": ResourceProvisioningStateSucceeded, + "updating": ResourceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceProvisioningState(input) + return &out, nil +} + +type RoutingIdentityType string + +const ( + RoutingIdentityTypeNone RoutingIdentityType = "None" + RoutingIdentityTypeSystemAssigned RoutingIdentityType = "SystemAssigned" + RoutingIdentityTypeUserAssigned RoutingIdentityType = "UserAssigned" +) + +func PossibleValuesForRoutingIdentityType() []string { + return []string{ + string(RoutingIdentityTypeNone), + string(RoutingIdentityTypeSystemAssigned), + string(RoutingIdentityTypeUserAssigned), + } +} + +func (s *RoutingIdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRoutingIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRoutingIdentityType(input string) (*RoutingIdentityType, error) { + vals := map[string]RoutingIdentityType{ + "none": RoutingIdentityTypeNone, + "systemassigned": RoutingIdentityTypeSystemAssigned, + "userassigned": RoutingIdentityTypeUserAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RoutingIdentityType(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameStandard SkuName = "Standard" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameStandard), + } +} + +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{ + "standard": SkuNameStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuName(input) + return &out, nil +} + +type StaticRoutingEnrichmentType string + +const ( + StaticRoutingEnrichmentTypeString StaticRoutingEnrichmentType = "String" +) + +func PossibleValuesForStaticRoutingEnrichmentType() []string { + return []string{ + string(StaticRoutingEnrichmentTypeString), + } +} + +func (s *StaticRoutingEnrichmentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStaticRoutingEnrichmentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStaticRoutingEnrichmentType(input string) (*StaticRoutingEnrichmentType, error) { + vals := map[string]StaticRoutingEnrichmentType{ + "string": StaticRoutingEnrichmentTypeString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StaticRoutingEnrichmentType(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} + +type TopicSpacesConfigurationState string + +const ( + TopicSpacesConfigurationStateDisabled TopicSpacesConfigurationState = "Disabled" + TopicSpacesConfigurationStateEnabled TopicSpacesConfigurationState = "Enabled" +) + +func PossibleValuesForTopicSpacesConfigurationState() []string { + return []string{ + string(TopicSpacesConfigurationStateDisabled), + string(TopicSpacesConfigurationStateEnabled), + } +} + +func (s *TopicSpacesConfigurationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTopicSpacesConfigurationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTopicSpacesConfigurationState(input string) (*TopicSpacesConfigurationState, error) { + vals := map[string]TopicSpacesConfigurationState{ + "disabled": TopicSpacesConfigurationStateDisabled, + "enabled": TopicSpacesConfigurationStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TopicSpacesConfigurationState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/id_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/id_namespace.go new file mode 100644 index 00000000000..15bdffa78fe --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/id_namespace.go @@ -0,0 +1,125 @@ +package namespaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceId{} + +// NamespaceId is a struct representing the Resource ID for a Namespace +type NamespaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string +} + +// NewNamespaceID returns a new NamespaceId struct +func NewNamespaceID(subscriptionId string, resourceGroupName string, namespaceName string) NamespaceId { + return NamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + } +} + +// ParseNamespaceID parses 'input' into a NamespaceId +func ParseNamespaceID(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceIDInsensitively parses 'input' case-insensitively into a NamespaceId +// note: this method should only be used for API response data and not user input +func ParseNamespaceIDInsensitively(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + return nil +} + +// ValidateNamespaceID checks that 'input' can be parsed as a Namespace ID +func ValidateNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace ID +func (id NamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace ID +func (id NamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + } +} + +// String returns a human-readable description of this Namespace ID +func (id NamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + } + return fmt.Sprintf("Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/id_namespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/id_namespace_test.go new file mode 100644 index 00000000000..8c659d1179b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/id_namespace_test.go @@ -0,0 +1,282 @@ +package namespaces + +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 = &NamespaceId{} + +func TestNewNamespaceID(t *testing.T) { + id := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } +} + +func TestFormatNamespaceID(t *testing.T) { + actual := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestParseNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestSegmentsForNamespaceId(t *testing.T) { + segments := NamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_createorupdate.go new file mode 100644 index 00000000000..8224336d8fc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_createorupdate.go @@ -0,0 +1,75 @@ +package namespaces + +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 *Namespace +} + +// CreateOrUpdate ... +func (c NamespacesClient) CreateOrUpdate(ctx context.Context, id NamespaceId, input Namespace) (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 NamespacesClient) CreateOrUpdateThenPoll(ctx context.Context, id NamespaceId, input Namespace) 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/eventgrid/2023-12-15-preview/namespaces/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_delete.go new file mode 100644 index 00000000000..e78bdc02c31 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_delete.go @@ -0,0 +1,71 @@ +package namespaces + +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 NamespacesClient) Delete(ctx context.Context, id NamespaceId) (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 NamespacesClient) DeleteThenPoll(ctx context.Context, id NamespaceId) 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/eventgrid/2023-12-15-preview/namespaces/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_get.go new file mode 100644 index 00000000000..c12b7a70469 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_get.go @@ -0,0 +1,54 @@ +package namespaces + +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 *Namespace +} + +// Get ... +func (c NamespacesClient) Get(ctx context.Context, id NamespaceId) (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 Namespace + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listbyresourcegroup.go new file mode 100644 index 00000000000..1c49f747439 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package namespaces + +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 *[]Namespace +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Namespace +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c NamespacesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/namespaces", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Namespace `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 NamespacesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, NamespaceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NamespacesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate NamespaceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Namespace, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listbysubscription.go new file mode 100644 index 00000000000..73f53658076 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listbysubscription.go @@ -0,0 +1,124 @@ +package namespaces + +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 *[]Namespace +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Namespace +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c NamespacesClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/namespaces", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Namespace `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 NamespacesClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, NamespaceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NamespacesClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate NamespaceOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Namespace, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listsharedaccesskeys.go new file mode 100644 index 00000000000..8748c6f414b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_listsharedaccesskeys.go @@ -0,0 +1,55 @@ +package namespaces + +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 ListSharedAccessKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NamespaceSharedAccessKeys +} + +// ListSharedAccessKeys ... +func (c NamespacesClient) ListSharedAccessKeys(ctx context.Context, id NamespaceId) (result ListSharedAccessKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model NamespaceSharedAccessKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_regeneratekey.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_regeneratekey.go new file mode 100644 index 00000000000..b0af2732a92 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_regeneratekey.go @@ -0,0 +1,75 @@ +package namespaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NamespaceSharedAccessKeys +} + +// RegenerateKey ... +func (c NamespacesClient) RegenerateKey(ctx context.Context, id NamespaceId, input NamespaceRegenerateKeyRequest) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RegenerateKeyThenPoll performs RegenerateKey then polls until it's completed +func (c NamespacesClient) RegenerateKeyThenPoll(ctx context.Context, id NamespaceId, input NamespaceRegenerateKeyRequest) error { + result, err := c.RegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_update.go new file mode 100644 index 00000000000..fe9a7d7f5fe --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/method_update.go @@ -0,0 +1,75 @@ +package namespaces + +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 *Namespace +} + +// Update ... +func (c NamespacesClient) Update(ctx context.Context, id NamespaceId, input NamespaceUpdateParameters) (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 NamespacesClient) UpdateThenPoll(ctx context.Context, id NamespaceId, input NamespaceUpdateParameters) 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/eventgrid/2023-12-15-preview/namespaces/model_clientauthenticationsettings.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_clientauthenticationsettings.go new file mode 100644 index 00000000000..f929380ecf8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_clientauthenticationsettings.go @@ -0,0 +1,8 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientAuthenticationSettings struct { + AlternativeAuthenticationNameSources *[]AlternativeAuthenticationNameSource `json:"alternativeAuthenticationNameSources,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_connectionstate.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_connectionstate.go new file mode 100644 index 00000000000..0a835866792 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_connectionstate.go @@ -0,0 +1,10 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PersistedConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_dynamicroutingenrichment.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_dynamicroutingenrichment.go new file mode 100644 index 00000000000..a6512573a41 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_dynamicroutingenrichment.go @@ -0,0 +1,9 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DynamicRoutingEnrichment struct { + Key *string `json:"key,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_inboundiprule.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_inboundiprule.go new file mode 100644 index 00000000000..000c22ece06 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_inboundiprule.go @@ -0,0 +1,9 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InboundIPRule struct { + Action *IPActionType `json:"action,omitempty"` + IPMask *string `json:"ipMask,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespace.go new file mode 100644 index 00000000000..e56e72f80f4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespace.go @@ -0,0 +1,21 @@ +package namespaces + +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 Namespace struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *NamespaceProperties `json:"properties,omitempty"` + Sku *NamespaceSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceproperties.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceproperties.go new file mode 100644 index 00000000000..7a19c77f5a4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceproperties.go @@ -0,0 +1,15 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceProperties struct { + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + IsZoneRedundant *bool `json:"isZoneRedundant,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *NamespaceProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + TopicSpacesConfiguration *TopicSpacesConfiguration `json:"topicSpacesConfiguration,omitempty"` + TopicsConfiguration *TopicsConfiguration `json:"topicsConfiguration,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceregeneratekeyrequest.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceregeneratekeyrequest.go new file mode 100644 index 00000000000..25deb817255 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceregeneratekeyrequest.go @@ -0,0 +1,8 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceRegenerateKeyRequest struct { + KeyName string `json:"keyName"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespacesharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespacesharedaccesskeys.go new file mode 100644 index 00000000000..87905b10a37 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespacesharedaccesskeys.go @@ -0,0 +1,9 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceSharedAccessKeys struct { + Key1 *string `json:"key1,omitempty"` + Key2 *string `json:"key2,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespacesku.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespacesku.go new file mode 100644 index 00000000000..9fc2fd3dea3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespacesku.go @@ -0,0 +1,9 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceSku struct { + Capacity *int64 `json:"capacity,omitempty"` + Name *SkuName `json:"name,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceupdateparameterproperties.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceupdateparameterproperties.go new file mode 100644 index 00000000000..04d5057699f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceupdateparameterproperties.go @@ -0,0 +1,10 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceUpdateParameterProperties struct { + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + TopicSpacesConfiguration *UpdateTopicSpacesConfigurationInfo `json:"topicSpacesConfiguration,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceupdateparameters.go new file mode 100644 index 00000000000..01f44a6c1c3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_namespaceupdateparameters.go @@ -0,0 +1,15 @@ +package namespaces + +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 NamespaceUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *NamespaceUpdateParameterProperties `json:"properties,omitempty"` + Sku *NamespaceSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpoint.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpoint.go new file mode 100644 index 00000000000..3dec0387e5f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpoint.go @@ -0,0 +1,8 @@ +package namespaces + +// 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/eventgrid/2023-12-15-preview/namespaces/model_privateendpointconnection.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpointconnection.go new file mode 100644 index 00000000000..f4e365dfe17 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpointconnectionproperties.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..f17c6b6f00b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package namespaces + +// 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 *ConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ResourceProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_routingenrichments.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_routingenrichments.go new file mode 100644 index 00000000000..e9c2ef191f5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_routingenrichments.go @@ -0,0 +1,49 @@ +package namespaces + +import ( + "encoding/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 RoutingEnrichments struct { + Dynamic *[]DynamicRoutingEnrichment `json:"dynamic,omitempty"` + Static *[]StaticRoutingEnrichment `json:"static,omitempty"` +} + +var _ json.Unmarshaler = &RoutingEnrichments{} + +func (s *RoutingEnrichments) UnmarshalJSON(bytes []byte) error { + type alias RoutingEnrichments + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into RoutingEnrichments: %+v", err) + } + + s.Dynamic = decoded.Dynamic + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RoutingEnrichments into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["static"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Static into list []json.RawMessage: %+v", err) + } + + output := make([]StaticRoutingEnrichment, 0) + for i, val := range listTemp { + impl, err := unmarshalStaticRoutingEnrichmentImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Static' for 'RoutingEnrichments': %+v", i, err) + } + output = append(output, impl) + } + s.Static = &output + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_routingidentityinfo.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_routingidentityinfo.go new file mode 100644 index 00000000000..e6611f3c03a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_routingidentityinfo.go @@ -0,0 +1,9 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RoutingIdentityInfo struct { + Type *RoutingIdentityType `json:"type,omitempty"` + UserAssignedIdentity *string `json:"userAssignedIdentity,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_staticroutingenrichment.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_staticroutingenrichment.go new file mode 100644 index 00000000000..a561b88fc59 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_staticroutingenrichment.go @@ -0,0 +1,53 @@ +package namespaces + +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 StaticRoutingEnrichment interface { +} + +// RawStaticRoutingEnrichmentImpl 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 RawStaticRoutingEnrichmentImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalStaticRoutingEnrichmentImplementation(input []byte) (StaticRoutingEnrichment, 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 StaticRoutingEnrichment into map[string]interface: %+v", err) + } + + value, ok := temp["valueType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "String") { + var out StaticStringRoutingEnrichment + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into StaticStringRoutingEnrichment: %+v", err) + } + return out, nil + } + + out := RawStaticRoutingEnrichmentImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_staticstringroutingenrichment.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_staticstringroutingenrichment.go new file mode 100644 index 00000000000..027f3483693 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_staticstringroutingenrichment.go @@ -0,0 +1,42 @@ +package namespaces + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ StaticRoutingEnrichment = StaticStringRoutingEnrichment{} + +type StaticStringRoutingEnrichment struct { + Value *string `json:"value,omitempty"` + + // Fields inherited from StaticRoutingEnrichment + Key *string `json:"key,omitempty"` +} + +var _ json.Marshaler = StaticStringRoutingEnrichment{} + +func (s StaticStringRoutingEnrichment) MarshalJSON() ([]byte, error) { + type wrapper StaticStringRoutingEnrichment + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling StaticStringRoutingEnrichment: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling StaticStringRoutingEnrichment: %+v", err) + } + decoded["valueType"] = "String" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling StaticStringRoutingEnrichment: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_topicsconfiguration.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_topicsconfiguration.go new file mode 100644 index 00000000000..1a0e1ddaef9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_topicsconfiguration.go @@ -0,0 +1,8 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicsConfiguration struct { + Hostname *string `json:"hostname,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_topicspacesconfiguration.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_topicspacesconfiguration.go new file mode 100644 index 00000000000..edf20989f9f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_topicspacesconfiguration.go @@ -0,0 +1,15 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicSpacesConfiguration struct { + ClientAuthentication *ClientAuthenticationSettings `json:"clientAuthentication,omitempty"` + Hostname *string `json:"hostname,omitempty"` + MaximumClientSessionsPerAuthenticationName *int64 `json:"maximumClientSessionsPerAuthenticationName,omitempty"` + MaximumSessionExpiryInHours *int64 `json:"maximumSessionExpiryInHours,omitempty"` + RouteTopicResourceId *string `json:"routeTopicResourceId,omitempty"` + RoutingEnrichments *RoutingEnrichments `json:"routingEnrichments,omitempty"` + RoutingIdentityInfo *RoutingIdentityInfo `json:"routingIdentityInfo,omitempty"` + State *TopicSpacesConfigurationState `json:"state,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_updatetopicspacesconfigurationinfo.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_updatetopicspacesconfigurationinfo.go new file mode 100644 index 00000000000..162dfe5dc1b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/model_updatetopicspacesconfigurationinfo.go @@ -0,0 +1,14 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateTopicSpacesConfigurationInfo struct { + ClientAuthentication *ClientAuthenticationSettings `json:"clientAuthentication,omitempty"` + MaximumClientSessionsPerAuthenticationName *int64 `json:"maximumClientSessionsPerAuthenticationName,omitempty"` + MaximumSessionExpiryInHours *int64 `json:"maximumSessionExpiryInHours,omitempty"` + RouteTopicResourceId *string `json:"routeTopicResourceId,omitempty"` + RoutingEnrichments *RoutingEnrichments `json:"routingEnrichments,omitempty"` + RoutingIdentityInfo *RoutingIdentityInfo `json:"routingIdentityInfo,omitempty"` + State *TopicSpacesConfigurationState `json:"state,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespaces/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/predicates.go new file mode 100644 index 00000000000..16fd3a29338 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/predicates.go @@ -0,0 +1,32 @@ +package namespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NamespaceOperationPredicate) Matches(input Namespace) 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/eventgrid/2023-12-15-preview/namespaces/version.go b/resource-manager/eventgrid/2023-12-15-preview/namespaces/version.go new file mode 100644 index 00000000000..7cde66ef00a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespaces/version.go @@ -0,0 +1,12 @@ +package namespaces + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/namespaces/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/README.md b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/README.md new file mode 100644 index 00000000000..647e9c02159 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/README.md @@ -0,0 +1,132 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/namespacetopics` Documentation + +The `namespacetopics` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/namespacetopics" +``` + + +### Client Initialization + +```go +client := namespacetopics.NewNamespaceTopicsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NamespaceTopicsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := namespacetopics.NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + +payload := namespacetopics.NamespaceTopic{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamespaceTopicsClient.Delete` + +```go +ctx := context.TODO() +id := namespacetopics.NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamespaceTopicsClient.Get` + +```go +ctx := context.TODO() +id := namespacetopics.NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + +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: `NamespaceTopicsClient.ListByNamespace` + +```go +ctx := context.TODO() +id := namespacetopics.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +// alternatively `client.ListByNamespace(ctx, id, namespacetopics.DefaultListByNamespaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByNamespaceComplete(ctx, id, namespacetopics.DefaultListByNamespaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NamespaceTopicsClient.ListSharedAccessKeys` + +```go +ctx := context.TODO() +id := namespacetopics.NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + +read, err := client.ListSharedAccessKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamespaceTopicsClient.RegenerateKey` + +```go +ctx := context.TODO() +id := namespacetopics.NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + +payload := namespacetopics.TopicRegenerateKeyRequest{ + // ... +} + + +if err := client.RegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamespaceTopicsClient.Update` + +```go +ctx := context.TODO() +id := namespacetopics.NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + +payload := namespacetopics.NamespaceTopicUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/client.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/client.go new file mode 100644 index 00000000000..8fba19ade42 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/client.go @@ -0,0 +1,26 @@ +package namespacetopics + +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 NamespaceTopicsClient struct { + Client *resourcemanager.Client +} + +func NewNamespaceTopicsClientWithBaseURI(sdkApi sdkEnv.Api) (*NamespaceTopicsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "namespacetopics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NamespaceTopicsClient: %+v", err) + } + + return &NamespaceTopicsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/constants.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/constants.go new file mode 100644 index 00000000000..6da4ee9733d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/constants.go @@ -0,0 +1,151 @@ +package namespacetopics + +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 EventInputSchema string + +const ( + EventInputSchemaCloudEventSchemaVOneZero EventInputSchema = "CloudEventSchemaV1_0" +) + +func PossibleValuesForEventInputSchema() []string { + return []string{ + string(EventInputSchemaCloudEventSchemaVOneZero), + } +} + +func (s *EventInputSchema) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventInputSchema(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventInputSchema(input string) (*EventInputSchema, error) { + vals := map[string]EventInputSchema{ + "cloudeventschemav1_0": EventInputSchemaCloudEventSchemaVOneZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventInputSchema(input) + return &out, nil +} + +type NamespaceTopicProvisioningState string + +const ( + NamespaceTopicProvisioningStateCanceled NamespaceTopicProvisioningState = "Canceled" + NamespaceTopicProvisioningStateCreateFailed NamespaceTopicProvisioningState = "CreateFailed" + NamespaceTopicProvisioningStateCreating NamespaceTopicProvisioningState = "Creating" + NamespaceTopicProvisioningStateDeleteFailed NamespaceTopicProvisioningState = "DeleteFailed" + NamespaceTopicProvisioningStateDeleted NamespaceTopicProvisioningState = "Deleted" + NamespaceTopicProvisioningStateDeleting NamespaceTopicProvisioningState = "Deleting" + NamespaceTopicProvisioningStateFailed NamespaceTopicProvisioningState = "Failed" + NamespaceTopicProvisioningStateSucceeded NamespaceTopicProvisioningState = "Succeeded" + NamespaceTopicProvisioningStateUpdatedFailed NamespaceTopicProvisioningState = "UpdatedFailed" + NamespaceTopicProvisioningStateUpdating NamespaceTopicProvisioningState = "Updating" +) + +func PossibleValuesForNamespaceTopicProvisioningState() []string { + return []string{ + string(NamespaceTopicProvisioningStateCanceled), + string(NamespaceTopicProvisioningStateCreateFailed), + string(NamespaceTopicProvisioningStateCreating), + string(NamespaceTopicProvisioningStateDeleteFailed), + string(NamespaceTopicProvisioningStateDeleted), + string(NamespaceTopicProvisioningStateDeleting), + string(NamespaceTopicProvisioningStateFailed), + string(NamespaceTopicProvisioningStateSucceeded), + string(NamespaceTopicProvisioningStateUpdatedFailed), + string(NamespaceTopicProvisioningStateUpdating), + } +} + +func (s *NamespaceTopicProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNamespaceTopicProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNamespaceTopicProvisioningState(input string) (*NamespaceTopicProvisioningState, error) { + vals := map[string]NamespaceTopicProvisioningState{ + "canceled": NamespaceTopicProvisioningStateCanceled, + "createfailed": NamespaceTopicProvisioningStateCreateFailed, + "creating": NamespaceTopicProvisioningStateCreating, + "deletefailed": NamespaceTopicProvisioningStateDeleteFailed, + "deleted": NamespaceTopicProvisioningStateDeleted, + "deleting": NamespaceTopicProvisioningStateDeleting, + "failed": NamespaceTopicProvisioningStateFailed, + "succeeded": NamespaceTopicProvisioningStateSucceeded, + "updatedfailed": NamespaceTopicProvisioningStateUpdatedFailed, + "updating": NamespaceTopicProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NamespaceTopicProvisioningState(input) + return &out, nil +} + +type PublisherType string + +const ( + PublisherTypeCustom PublisherType = "Custom" +) + +func PossibleValuesForPublisherType() []string { + return []string{ + string(PublisherTypeCustom), + } +} + +func (s *PublisherType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublisherType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublisherType(input string) (*PublisherType, error) { + vals := map[string]PublisherType{ + "custom": PublisherTypeCustom, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublisherType(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespace.go new file mode 100644 index 00000000000..7aadf6387d7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespace.go @@ -0,0 +1,125 @@ +package namespacetopics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceId{} + +// NamespaceId is a struct representing the Resource ID for a Namespace +type NamespaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string +} + +// NewNamespaceID returns a new NamespaceId struct +func NewNamespaceID(subscriptionId string, resourceGroupName string, namespaceName string) NamespaceId { + return NamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + } +} + +// ParseNamespaceID parses 'input' into a NamespaceId +func ParseNamespaceID(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceIDInsensitively parses 'input' case-insensitively into a NamespaceId +// note: this method should only be used for API response data and not user input +func ParseNamespaceIDInsensitively(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + return nil +} + +// ValidateNamespaceID checks that 'input' can be parsed as a Namespace ID +func ValidateNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace ID +func (id NamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace ID +func (id NamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + } +} + +// String returns a human-readable description of this Namespace ID +func (id NamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + } + return fmt.Sprintf("Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespace_test.go new file mode 100644 index 00000000000..9de295edd43 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespace_test.go @@ -0,0 +1,282 @@ +package namespacetopics + +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 = &NamespaceId{} + +func TestNewNamespaceID(t *testing.T) { + id := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } +} + +func TestFormatNamespaceID(t *testing.T) { + actual := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestParseNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestSegmentsForNamespaceId(t *testing.T) { + segments := NamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespacetopic.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespacetopic.go new file mode 100644 index 00000000000..c32d53b8494 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespacetopic.go @@ -0,0 +1,134 @@ +package namespacetopics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceTopicId{} + +// NamespaceTopicId is a struct representing the Resource ID for a Namespace Topic +type NamespaceTopicId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + TopicName string +} + +// NewNamespaceTopicID returns a new NamespaceTopicId struct +func NewNamespaceTopicID(subscriptionId string, resourceGroupName string, namespaceName string, topicName string) NamespaceTopicId { + return NamespaceTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + TopicName: topicName, + } +} + +// ParseNamespaceTopicID parses 'input' into a NamespaceTopicId +func ParseNamespaceTopicID(input string) (*NamespaceTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceTopicIDInsensitively parses 'input' case-insensitively into a NamespaceTopicId +// note: this method should only be used for API response data and not user input +func ParseNamespaceTopicIDInsensitively(input string) (*NamespaceTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceTopicId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + return nil +} + +// ValidateNamespaceTopicID checks that 'input' can be parsed as a Namespace Topic ID +func ValidateNamespaceTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace Topic ID +func (id NamespaceTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/topics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.TopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace Topic ID +func (id NamespaceTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + } +} + +// String returns a human-readable description of this Namespace Topic ID +func (id NamespaceTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + } + return fmt.Sprintf("Namespace Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespacetopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespacetopic_test.go new file mode 100644 index 00000000000..cfe412bc497 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/id_namespacetopic_test.go @@ -0,0 +1,327 @@ +package namespacetopics + +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 = &NamespaceTopicId{} + +func TestNewNamespaceTopicID(t *testing.T) { + id := NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } +} + +func TestFormatNamespaceTopicID(t *testing.T) { + actual := NewNamespaceTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue", + Expected: &NamespaceTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestParseNamespaceTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue", + Expected: &NamespaceTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topics/topicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE", + Expected: &NamespaceTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + TopicName: "tOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcS/tOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestSegmentsForNamespaceTopicId(t *testing.T) { + segments := NamespaceTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_createorupdate.go new file mode 100644 index 00000000000..b35c70daf34 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_createorupdate.go @@ -0,0 +1,75 @@ +package namespacetopics + +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 *NamespaceTopic +} + +// CreateOrUpdate ... +func (c NamespaceTopicsClient) CreateOrUpdate(ctx context.Context, id NamespaceTopicId, input NamespaceTopic) (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 NamespaceTopicsClient) CreateOrUpdateThenPoll(ctx context.Context, id NamespaceTopicId, input NamespaceTopic) 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/eventgrid/2023-12-15-preview/namespacetopics/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_delete.go new file mode 100644 index 00000000000..0d85b5ad715 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_delete.go @@ -0,0 +1,71 @@ +package namespacetopics + +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 NamespaceTopicsClient) Delete(ctx context.Context, id NamespaceTopicId) (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 NamespaceTopicsClient) DeleteThenPoll(ctx context.Context, id NamespaceTopicId) 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/eventgrid/2023-12-15-preview/namespacetopics/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_get.go new file mode 100644 index 00000000000..79cc4f41d0f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_get.go @@ -0,0 +1,54 @@ +package namespacetopics + +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 *NamespaceTopic +} + +// Get ... +func (c NamespaceTopicsClient) Get(ctx context.Context, id NamespaceTopicId) (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 NamespaceTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_listbynamespace.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_listbynamespace.go new file mode 100644 index 00000000000..5b9ff7db742 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_listbynamespace.go @@ -0,0 +1,123 @@ +package namespacetopics + +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 ListByNamespaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NamespaceTopic +} + +type ListByNamespaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []NamespaceTopic +} + +type ListByNamespaceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByNamespaceOperationOptions() ListByNamespaceOperationOptions { + return ListByNamespaceOperationOptions{} +} + +func (o ListByNamespaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByNamespaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByNamespaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByNamespace ... +func (c NamespaceTopicsClient) ListByNamespace(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (result ListByNamespaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/topics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]NamespaceTopic `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNamespaceComplete retrieves all the results into a single object +func (c NamespaceTopicsClient) ListByNamespaceComplete(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (ListByNamespaceCompleteResult, error) { + return c.ListByNamespaceCompleteMatchingPredicate(ctx, id, options, NamespaceTopicOperationPredicate{}) +} + +// ListByNamespaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NamespaceTopicsClient) ListByNamespaceCompleteMatchingPredicate(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions, predicate NamespaceTopicOperationPredicate) (result ListByNamespaceCompleteResult, err error) { + items := make([]NamespaceTopic, 0) + + resp, err := c.ListByNamespace(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNamespaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_listsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_listsharedaccesskeys.go new file mode 100644 index 00000000000..86d6b0ce8e8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_listsharedaccesskeys.go @@ -0,0 +1,55 @@ +package namespacetopics + +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 ListSharedAccessKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TopicSharedAccessKeys +} + +// ListSharedAccessKeys ... +func (c NamespaceTopicsClient) ListSharedAccessKeys(ctx context.Context, id NamespaceTopicId) (result ListSharedAccessKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TopicSharedAccessKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_regeneratekey.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_regeneratekey.go new file mode 100644 index 00000000000..f4a998c0f82 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_regeneratekey.go @@ -0,0 +1,75 @@ +package namespacetopics + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TopicSharedAccessKeys +} + +// RegenerateKey ... +func (c NamespaceTopicsClient) RegenerateKey(ctx context.Context, id NamespaceTopicId, input TopicRegenerateKeyRequest) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RegenerateKeyThenPoll performs RegenerateKey then polls until it's completed +func (c NamespaceTopicsClient) RegenerateKeyThenPoll(ctx context.Context, id NamespaceTopicId, input TopicRegenerateKeyRequest) error { + result, err := c.RegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_update.go new file mode 100644 index 00000000000..3b72821af5c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/method_update.go @@ -0,0 +1,75 @@ +package namespacetopics + +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 *NamespaceTopic +} + +// Update ... +func (c NamespaceTopicsClient) Update(ctx context.Context, id NamespaceTopicId, input NamespaceTopicUpdateParameters) (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 NamespaceTopicsClient) UpdateThenPoll(ctx context.Context, id NamespaceTopicId, input NamespaceTopicUpdateParameters) 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/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopic.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopic.go new file mode 100644 index 00000000000..1dccdc43f24 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopic.go @@ -0,0 +1,16 @@ +package namespacetopics + +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 NamespaceTopic struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NamespaceTopicProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicproperties.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicproperties.go new file mode 100644 index 00000000000..b37e01c1a8c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicproperties.go @@ -0,0 +1,11 @@ +package namespacetopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceTopicProperties struct { + EventRetentionInDays *int64 `json:"eventRetentionInDays,omitempty"` + InputSchema *EventInputSchema `json:"inputSchema,omitempty"` + ProvisioningState *NamespaceTopicProvisioningState `json:"provisioningState,omitempty"` + PublisherType *PublisherType `json:"publisherType,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicupdateparameterproperties.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicupdateparameterproperties.go new file mode 100644 index 00000000000..e2ff04da7e4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicupdateparameterproperties.go @@ -0,0 +1,8 @@ +package namespacetopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceTopicUpdateParameterProperties struct { + EventRetentionInDays *int64 `json:"eventRetentionInDays,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicupdateparameters.go new file mode 100644 index 00000000000..520c08e31ba --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_namespacetopicupdateparameters.go @@ -0,0 +1,8 @@ +package namespacetopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceTopicUpdateParameters struct { + Properties *NamespaceTopicUpdateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_topicregeneratekeyrequest.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_topicregeneratekeyrequest.go new file mode 100644 index 00000000000..2f4db5cc2b3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_topicregeneratekeyrequest.go @@ -0,0 +1,8 @@ +package namespacetopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicRegenerateKeyRequest struct { + KeyName string `json:"keyName"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_topicsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_topicsharedaccesskeys.go new file mode 100644 index 00000000000..5f3a72b8506 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/model_topicsharedaccesskeys.go @@ -0,0 +1,9 @@ +package namespacetopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicSharedAccessKeys struct { + Key1 *string `json:"key1,omitempty"` + Key2 *string `json:"key2,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/predicates.go new file mode 100644 index 00000000000..3c6a5cbed3a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/predicates.go @@ -0,0 +1,27 @@ +package namespacetopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespaceTopicOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p NamespaceTopicOperationPredicate) Matches(input NamespaceTopic) 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/eventgrid/2023-12-15-preview/namespacetopics/version.go b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/version.go new file mode 100644 index 00000000000..8a6c4dd0d62 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/namespacetopics/version.go @@ -0,0 +1,12 @@ +package namespacetopics + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/namespacetopics/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/README.md b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/README.md new file mode 100644 index 00000000000..9f6485a12b8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/README.md @@ -0,0 +1,159 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations` Documentation + +The `partnerconfigurations` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/partnerconfigurations" +``` + + +### Client Initialization + +```go +client := partnerconfigurations.NewPartnerConfigurationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PartnerConfigurationsClient.AuthorizePartner` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := partnerconfigurations.Partner{ + // ... +} + + +read, err := client.AuthorizePartner(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerConfigurationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := partnerconfigurations.PartnerConfiguration{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerConfigurationsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerConfigurationsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +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: `PartnerConfigurationsClient.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: `PartnerConfigurationsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, partnerconfigurations.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, partnerconfigurations.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerConfigurationsClient.UnauthorizePartner` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := partnerconfigurations.Partner{ + // ... +} + + +read, err := client.UnauthorizePartner(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerConfigurationsClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := partnerconfigurations.PartnerConfigurationUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/client.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/client.go new file mode 100644 index 00000000000..db4c4a6d68c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/client.go @@ -0,0 +1,26 @@ +package partnerconfigurations + +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 PartnerConfigurationsClient struct { + Client *resourcemanager.Client +} + +func NewPartnerConfigurationsClientWithBaseURI(sdkApi sdkEnv.Api) (*PartnerConfigurationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "partnerconfigurations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PartnerConfigurationsClient: %+v", err) + } + + return &PartnerConfigurationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/constants.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/constants.go new file mode 100644 index 00000000000..73edcfa9ffc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/constants.go @@ -0,0 +1,63 @@ +package partnerconfigurations + +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 PartnerConfigurationProvisioningState string + +const ( + PartnerConfigurationProvisioningStateCanceled PartnerConfigurationProvisioningState = "Canceled" + PartnerConfigurationProvisioningStateCreating PartnerConfigurationProvisioningState = "Creating" + PartnerConfigurationProvisioningStateDeleting PartnerConfigurationProvisioningState = "Deleting" + PartnerConfigurationProvisioningStateFailed PartnerConfigurationProvisioningState = "Failed" + PartnerConfigurationProvisioningStateSucceeded PartnerConfigurationProvisioningState = "Succeeded" + PartnerConfigurationProvisioningStateUpdating PartnerConfigurationProvisioningState = "Updating" +) + +func PossibleValuesForPartnerConfigurationProvisioningState() []string { + return []string{ + string(PartnerConfigurationProvisioningStateCanceled), + string(PartnerConfigurationProvisioningStateCreating), + string(PartnerConfigurationProvisioningStateDeleting), + string(PartnerConfigurationProvisioningStateFailed), + string(PartnerConfigurationProvisioningStateSucceeded), + string(PartnerConfigurationProvisioningStateUpdating), + } +} + +func (s *PartnerConfigurationProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerConfigurationProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerConfigurationProvisioningState(input string) (*PartnerConfigurationProvisioningState, error) { + vals := map[string]PartnerConfigurationProvisioningState{ + "canceled": PartnerConfigurationProvisioningStateCanceled, + "creating": PartnerConfigurationProvisioningStateCreating, + "deleting": PartnerConfigurationProvisioningStateDeleting, + "failed": PartnerConfigurationProvisioningStateFailed, + "succeeded": PartnerConfigurationProvisioningStateSucceeded, + "updating": PartnerConfigurationProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerConfigurationProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_authorizepartner.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_authorizepartner.go new file mode 100644 index 00000000000..8510613024a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_authorizepartner.go @@ -0,0 +1,60 @@ +package partnerconfigurations + +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 AuthorizePartnerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerConfiguration +} + +// AuthorizePartner ... +func (c PartnerConfigurationsClient) AuthorizePartner(ctx context.Context, id commonids.ResourceGroupId, input Partner) (result AuthorizePartnerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations/default/authorizePartner", 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 PartnerConfiguration + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_createorupdate.go new file mode 100644 index 00000000000..bb3a3889641 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_createorupdate.go @@ -0,0 +1,76 @@ +package partnerconfigurations + +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 CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PartnerConfiguration +} + +// CreateOrUpdate ... +func (c PartnerConfigurationsClient) CreateOrUpdate(ctx context.Context, id commonids.ResourceGroupId, input PartnerConfiguration) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations/default", 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 PartnerConfigurationsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.ResourceGroupId, input PartnerConfiguration) 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/eventgrid/2023-12-15-preview/partnerconfigurations/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_delete.go new file mode 100644 index 00000000000..c284df06e87 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_delete.go @@ -0,0 +1,72 @@ +package partnerconfigurations + +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 DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PartnerConfigurationsClient) Delete(ctx context.Context, id commonids.ResourceGroupId) (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: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations/default", 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 PartnerConfigurationsClient) DeleteThenPoll(ctx context.Context, id commonids.ResourceGroupId) 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/eventgrid/2023-12-15-preview/partnerconfigurations/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_get.go new file mode 100644 index 00000000000..e890871327e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_get.go @@ -0,0 +1,56 @@ +package partnerconfigurations + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerConfiguration +} + +// Get ... +func (c PartnerConfigurationsClient) Get(ctx context.Context, id commonids.ResourceGroupId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations/default", 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 PartnerConfiguration + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_listbyresourcegroup.go new file mode 100644 index 00000000000..69561cae793 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package partnerconfigurations + +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 *[]PartnerConfiguration +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerConfiguration +} + +// ListByResourceGroup ... +func (c PartnerConfigurationsClient) 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, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations", 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 *[]PartnerConfiguration `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 PartnerConfigurationsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, PartnerConfigurationOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerConfigurationsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate PartnerConfigurationOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]PartnerConfiguration, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_listbysubscription.go new file mode 100644 index 00000000000..c723e494c50 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_listbysubscription.go @@ -0,0 +1,124 @@ +package partnerconfigurations + +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 *[]PartnerConfiguration +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerConfiguration +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c PartnerConfigurationsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerConfiguration `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 PartnerConfigurationsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, PartnerConfigurationOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerConfigurationsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate PartnerConfigurationOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]PartnerConfiguration, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_unauthorizepartner.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_unauthorizepartner.go new file mode 100644 index 00000000000..b026a3ff31a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_unauthorizepartner.go @@ -0,0 +1,60 @@ +package partnerconfigurations + +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 UnauthorizePartnerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerConfiguration +} + +// UnauthorizePartner ... +func (c PartnerConfigurationsClient) UnauthorizePartner(ctx context.Context, id commonids.ResourceGroupId, input Partner) (result UnauthorizePartnerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations/default/unauthorizePartner", 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 PartnerConfiguration + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_update.go new file mode 100644 index 00000000000..c4939698f18 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/method_update.go @@ -0,0 +1,76 @@ +package partnerconfigurations + +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 UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PartnerConfiguration +} + +// Update ... +func (c PartnerConfigurationsClient) Update(ctx context.Context, id commonids.ResourceGroupId, input PartnerConfigurationUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerConfigurations/default", 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 PartnerConfigurationsClient) UpdateThenPoll(ctx context.Context, id commonids.ResourceGroupId, input PartnerConfigurationUpdateParameters) 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/eventgrid/2023-12-15-preview/partnerconfigurations/model_partner.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partner.go new file mode 100644 index 00000000000..cda99c5f6fc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partner.go @@ -0,0 +1,28 @@ +package partnerconfigurations + +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 Partner struct { + AuthorizationExpirationTimeInUtc *string `json:"authorizationExpirationTimeInUtc,omitempty"` + PartnerName *string `json:"partnerName,omitempty"` + PartnerRegistrationImmutableId *string `json:"partnerRegistrationImmutableId,omitempty"` +} + +func (o *Partner) GetAuthorizationExpirationTimeInUtcAsTime() (*time.Time, error) { + if o.AuthorizationExpirationTimeInUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AuthorizationExpirationTimeInUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *Partner) SetAuthorizationExpirationTimeInUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AuthorizationExpirationTimeInUtc = &formatted +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerauthorization.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerauthorization.go new file mode 100644 index 00000000000..609689eb503 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerauthorization.go @@ -0,0 +1,9 @@ +package partnerconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerAuthorization struct { + AuthorizedPartnersList *[]Partner `json:"authorizedPartnersList,omitempty"` + DefaultMaximumExpirationTimeInDays *int64 `json:"defaultMaximumExpirationTimeInDays,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfiguration.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfiguration.go new file mode 100644 index 00000000000..5bbf0526586 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfiguration.go @@ -0,0 +1,18 @@ +package partnerconfigurations + +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 PartnerConfiguration struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PartnerConfigurationProperties `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/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationproperties.go new file mode 100644 index 00000000000..e6e2688be42 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationproperties.go @@ -0,0 +1,9 @@ +package partnerconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerConfigurationProperties struct { + PartnerAuthorization *PartnerAuthorization `json:"partnerAuthorization,omitempty"` + ProvisioningState *PartnerConfigurationProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationupdateparameterproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationupdateparameterproperties.go new file mode 100644 index 00000000000..a0a2f179b9f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationupdateparameterproperties.go @@ -0,0 +1,8 @@ +package partnerconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerConfigurationUpdateParameterProperties struct { + DefaultMaximumExpirationTimeInDays *int64 `json:"defaultMaximumExpirationTimeInDays,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationupdateparameters.go new file mode 100644 index 00000000000..4e859c5e009 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/model_partnerconfigurationupdateparameters.go @@ -0,0 +1,9 @@ +package partnerconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerConfigurationUpdateParameters struct { + Properties *PartnerConfigurationUpdateParameterProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/predicates.go new file mode 100644 index 00000000000..2c6e9adda78 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/predicates.go @@ -0,0 +1,32 @@ +package partnerconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerConfigurationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PartnerConfigurationOperationPredicate) Matches(input PartnerConfiguration) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/version.go b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/version.go new file mode 100644 index 00000000000..d460a22891d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerconfigurations/version.go @@ -0,0 +1,12 @@ +package partnerconfigurations + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/partnerconfigurations/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/README.md b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/README.md new file mode 100644 index 00000000000..9780b0dbb8f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/README.md @@ -0,0 +1,133 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations` Documentation + +The `partnerdestinations` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/partnerdestinations" +``` + + +### Client Initialization + +```go +client := partnerdestinations.NewPartnerDestinationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PartnerDestinationsClient.Activate` + +```go +ctx := context.TODO() +id := partnerdestinations.NewPartnerDestinationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerDestinationValue") + +read, err := client.Activate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerDestinationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := partnerdestinations.NewPartnerDestinationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerDestinationValue") + +payload := partnerdestinations.PartnerDestination{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerDestinationsClient.Delete` + +```go +ctx := context.TODO() +id := partnerdestinations.NewPartnerDestinationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerDestinationValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerDestinationsClient.Get` + +```go +ctx := context.TODO() +id := partnerdestinations.NewPartnerDestinationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerDestinationValue") + +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: `PartnerDestinationsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, partnerdestinations.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, partnerdestinations.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerDestinationsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, partnerdestinations.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, partnerdestinations.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerDestinationsClient.Update` + +```go +ctx := context.TODO() +id := partnerdestinations.NewPartnerDestinationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerDestinationValue") + +payload := partnerdestinations.PartnerDestinationUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/client.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/client.go new file mode 100644 index 00000000000..562f42dc10e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/client.go @@ -0,0 +1,26 @@ +package partnerdestinations + +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 PartnerDestinationsClient struct { + Client *resourcemanager.Client +} + +func NewPartnerDestinationsClientWithBaseURI(sdkApi sdkEnv.Api) (*PartnerDestinationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "partnerdestinations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PartnerDestinationsClient: %+v", err) + } + + return &PartnerDestinationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/constants.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/constants.go new file mode 100644 index 00000000000..32bbc7fc54f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/constants.go @@ -0,0 +1,107 @@ +package partnerdestinations + +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 PartnerDestinationActivationState string + +const ( + PartnerDestinationActivationStateActivated PartnerDestinationActivationState = "Activated" + PartnerDestinationActivationStateNeverActivated PartnerDestinationActivationState = "NeverActivated" +) + +func PossibleValuesForPartnerDestinationActivationState() []string { + return []string{ + string(PartnerDestinationActivationStateActivated), + string(PartnerDestinationActivationStateNeverActivated), + } +} + +func (s *PartnerDestinationActivationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerDestinationActivationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerDestinationActivationState(input string) (*PartnerDestinationActivationState, error) { + vals := map[string]PartnerDestinationActivationState{ + "activated": PartnerDestinationActivationStateActivated, + "neveractivated": PartnerDestinationActivationStateNeverActivated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerDestinationActivationState(input) + return &out, nil +} + +type PartnerDestinationProvisioningState string + +const ( + PartnerDestinationProvisioningStateCanceled PartnerDestinationProvisioningState = "Canceled" + PartnerDestinationProvisioningStateCreating PartnerDestinationProvisioningState = "Creating" + PartnerDestinationProvisioningStateDeleting PartnerDestinationProvisioningState = "Deleting" + PartnerDestinationProvisioningStateFailed PartnerDestinationProvisioningState = "Failed" + PartnerDestinationProvisioningStateIdleDueToMirroredChannelResourceDeletion PartnerDestinationProvisioningState = "IdleDueToMirroredChannelResourceDeletion" + PartnerDestinationProvisioningStateSucceeded PartnerDestinationProvisioningState = "Succeeded" + PartnerDestinationProvisioningStateUpdating PartnerDestinationProvisioningState = "Updating" +) + +func PossibleValuesForPartnerDestinationProvisioningState() []string { + return []string{ + string(PartnerDestinationProvisioningStateCanceled), + string(PartnerDestinationProvisioningStateCreating), + string(PartnerDestinationProvisioningStateDeleting), + string(PartnerDestinationProvisioningStateFailed), + string(PartnerDestinationProvisioningStateIdleDueToMirroredChannelResourceDeletion), + string(PartnerDestinationProvisioningStateSucceeded), + string(PartnerDestinationProvisioningStateUpdating), + } +} + +func (s *PartnerDestinationProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerDestinationProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerDestinationProvisioningState(input string) (*PartnerDestinationProvisioningState, error) { + vals := map[string]PartnerDestinationProvisioningState{ + "canceled": PartnerDestinationProvisioningStateCanceled, + "creating": PartnerDestinationProvisioningStateCreating, + "deleting": PartnerDestinationProvisioningStateDeleting, + "failed": PartnerDestinationProvisioningStateFailed, + "idleduetomirroredchannelresourcedeletion": PartnerDestinationProvisioningStateIdleDueToMirroredChannelResourceDeletion, + "succeeded": PartnerDestinationProvisioningStateSucceeded, + "updating": PartnerDestinationProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerDestinationProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/id_partnerdestination.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/id_partnerdestination.go new file mode 100644 index 00000000000..d610b9cdb6e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/id_partnerdestination.go @@ -0,0 +1,125 @@ +package partnerdestinations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PartnerDestinationId{} + +// PartnerDestinationId is a struct representing the Resource ID for a Partner Destination +type PartnerDestinationId struct { + SubscriptionId string + ResourceGroupName string + PartnerDestinationName string +} + +// NewPartnerDestinationID returns a new PartnerDestinationId struct +func NewPartnerDestinationID(subscriptionId string, resourceGroupName string, partnerDestinationName string) PartnerDestinationId { + return PartnerDestinationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerDestinationName: partnerDestinationName, + } +} + +// ParsePartnerDestinationID parses 'input' into a PartnerDestinationId +func ParsePartnerDestinationID(input string) (*PartnerDestinationId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerDestinationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerDestinationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePartnerDestinationIDInsensitively parses 'input' case-insensitively into a PartnerDestinationId +// note: this method should only be used for API response data and not user input +func ParsePartnerDestinationIDInsensitively(input string) (*PartnerDestinationId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerDestinationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerDestinationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PartnerDestinationId) 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.PartnerDestinationName, ok = input.Parsed["partnerDestinationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerDestinationName", input) + } + + return nil +} + +// ValidatePartnerDestinationID checks that 'input' can be parsed as a Partner Destination ID +func ValidatePartnerDestinationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePartnerDestinationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Partner Destination ID +func (id PartnerDestinationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerDestinations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerDestinationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Partner Destination ID +func (id PartnerDestinationId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerDestinations", "partnerDestinations", "partnerDestinations"), + resourceids.UserSpecifiedSegment("partnerDestinationName", "partnerDestinationValue"), + } +} + +// String returns a human-readable description of this Partner Destination ID +func (id PartnerDestinationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Destination Name: %q", id.PartnerDestinationName), + } + return fmt.Sprintf("Partner Destination (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/id_partnerdestination_test.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/id_partnerdestination_test.go new file mode 100644 index 00000000000..8792b47a2a1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/id_partnerdestination_test.go @@ -0,0 +1,282 @@ +package partnerdestinations + +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 = &PartnerDestinationId{} + +func TestNewPartnerDestinationID(t *testing.T) { + id := NewPartnerDestinationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerDestinationValue") + + if id.SubscriptionId != "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.PartnerDestinationName != "partnerDestinationValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerDestinationName'", id.PartnerDestinationName, "partnerDestinationValue") + } +} + +func TestFormatPartnerDestinationID(t *testing.T) { + actual := NewPartnerDestinationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerDestinationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerDestinations/partnerDestinationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePartnerDestinationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerDestinationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerDestinations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerDestinations/partnerDestinationValue", + Expected: &PartnerDestinationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerDestinationName: "partnerDestinationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerDestinations/partnerDestinationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerDestinationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerDestinationName != v.Expected.PartnerDestinationName { + t.Fatalf("Expected %q but got %q for PartnerDestinationName", v.Expected.PartnerDestinationName, actual.PartnerDestinationName) + } + + } +} + +func TestParsePartnerDestinationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerDestinationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerDestinations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErDeStInAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerDestinations/partnerDestinationValue", + Expected: &PartnerDestinationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerDestinationName: "partnerDestinationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerDestinations/partnerDestinationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErDeStInAtIoNs/pArTnErDeStInAtIoNvAlUe", + Expected: &PartnerDestinationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerDestinationName: "pArTnErDeStInAtIoNvAlUe", + }, + }, + { + // 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.eVeNtGrId/pArTnErDeStInAtIoNs/pArTnErDeStInAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerDestinationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerDestinationName != v.Expected.PartnerDestinationName { + t.Fatalf("Expected %q but got %q for PartnerDestinationName", v.Expected.PartnerDestinationName, actual.PartnerDestinationName) + } + + } +} + +func TestSegmentsForPartnerDestinationId(t *testing.T) { + segments := PartnerDestinationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PartnerDestinationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_activate.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_activate.go new file mode 100644 index 00000000000..e1e1a3a30c5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_activate.go @@ -0,0 +1,55 @@ +package partnerdestinations + +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 ActivateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerDestination +} + +// Activate ... +func (c PartnerDestinationsClient) Activate(ctx context.Context, id PartnerDestinationId) (result ActivateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/activate", 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 PartnerDestination + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_createorupdate.go new file mode 100644 index 00000000000..4f48e279813 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_createorupdate.go @@ -0,0 +1,75 @@ +package partnerdestinations + +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 *PartnerDestination +} + +// CreateOrUpdate ... +func (c PartnerDestinationsClient) CreateOrUpdate(ctx context.Context, id PartnerDestinationId, input PartnerDestination) (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 PartnerDestinationsClient) CreateOrUpdateThenPoll(ctx context.Context, id PartnerDestinationId, input PartnerDestination) 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/eventgrid/2023-12-15-preview/partnerdestinations/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_delete.go new file mode 100644 index 00000000000..c9d52561913 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_delete.go @@ -0,0 +1,71 @@ +package partnerdestinations + +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 PartnerDestinationsClient) Delete(ctx context.Context, id PartnerDestinationId) (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 PartnerDestinationsClient) DeleteThenPoll(ctx context.Context, id PartnerDestinationId) 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/eventgrid/2023-12-15-preview/partnerdestinations/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_get.go new file mode 100644 index 00000000000..9e7efeea9d8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_get.go @@ -0,0 +1,54 @@ +package partnerdestinations + +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 *PartnerDestination +} + +// Get ... +func (c PartnerDestinationsClient) Get(ctx context.Context, id PartnerDestinationId) (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 PartnerDestination + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_listbyresourcegroup.go new file mode 100644 index 00000000000..ffc364ba935 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package partnerdestinations + +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 *[]PartnerDestination +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerDestination +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c PartnerDestinationsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerDestinations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerDestination `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 PartnerDestinationsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, PartnerDestinationOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerDestinationsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate PartnerDestinationOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]PartnerDestination, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_listbysubscription.go new file mode 100644 index 00000000000..250652b7607 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_listbysubscription.go @@ -0,0 +1,124 @@ +package partnerdestinations + +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 *[]PartnerDestination +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerDestination +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c PartnerDestinationsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerDestinations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerDestination `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 PartnerDestinationsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, PartnerDestinationOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerDestinationsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate PartnerDestinationOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]PartnerDestination, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_update.go new file mode 100644 index 00000000000..498f63fa60f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/method_update.go @@ -0,0 +1,76 @@ +package partnerdestinations + +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 *PartnerDestination +} + +// Update ... +func (c PartnerDestinationsClient) Update(ctx context.Context, id PartnerDestinationId, input PartnerDestinationUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + 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 PartnerDestinationsClient) UpdateThenPoll(ctx context.Context, id PartnerDestinationId, input PartnerDestinationUpdateParameters) 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/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestination.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestination.go new file mode 100644 index 00000000000..0703fb11329 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestination.go @@ -0,0 +1,18 @@ +package partnerdestinations + +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 PartnerDestination struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *PartnerDestinationProperties `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/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestinationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestinationproperties.go new file mode 100644 index 00000000000..4caf77cb674 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestinationproperties.go @@ -0,0 +1,32 @@ +package partnerdestinations + +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 PartnerDestinationProperties struct { + ActivationState *PartnerDestinationActivationState `json:"activationState,omitempty"` + EndpointBaseUrl *string `json:"endpointBaseUrl,omitempty"` + EndpointServiceContext *string `json:"endpointServiceContext,omitempty"` + ExpirationTimeIfNotActivatedUtc *string `json:"expirationTimeIfNotActivatedUtc,omitempty"` + MessageForActivation *string `json:"messageForActivation,omitempty"` + PartnerRegistrationImmutableId *string `json:"partnerRegistrationImmutableId,omitempty"` + ProvisioningState *PartnerDestinationProvisioningState `json:"provisioningState,omitempty"` +} + +func (o *PartnerDestinationProperties) GetExpirationTimeIfNotActivatedUtcAsTime() (*time.Time, error) { + if o.ExpirationTimeIfNotActivatedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeIfNotActivatedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *PartnerDestinationProperties) SetExpirationTimeIfNotActivatedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeIfNotActivatedUtc = &formatted +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestinationupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestinationupdateparameters.go new file mode 100644 index 00000000000..75a3c69a0c2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/model_partnerdestinationupdateparameters.go @@ -0,0 +1,8 @@ +package partnerdestinations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerDestinationUpdateParameters struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/predicates.go new file mode 100644 index 00000000000..ed206654315 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/predicates.go @@ -0,0 +1,32 @@ +package partnerdestinations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerDestinationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PartnerDestinationOperationPredicate) Matches(input PartnerDestination) 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/eventgrid/2023-12-15-preview/partnerdestinations/version.go b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/version.go new file mode 100644 index 00000000000..6df4351d355 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerdestinations/version.go @@ -0,0 +1,12 @@ +package partnerdestinations + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/partnerdestinations/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/README.md b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/README.md new file mode 100644 index 00000000000..984a7c58dcd --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/README.md @@ -0,0 +1,154 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces` Documentation + +The `partnernamespaces` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/partnernamespaces" +``` + + +### Client Initialization + +```go +client := partnernamespaces.NewPartnerNamespacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PartnerNamespacesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := partnernamespaces.NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + +payload := partnernamespaces.PartnerNamespace{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerNamespacesClient.Delete` + +```go +ctx := context.TODO() +id := partnernamespaces.NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerNamespacesClient.Get` + +```go +ctx := context.TODO() +id := partnernamespaces.NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + +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: `PartnerNamespacesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, partnernamespaces.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, partnernamespaces.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerNamespacesClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, partnernamespaces.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, partnernamespaces.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerNamespacesClient.ListSharedAccessKeys` + +```go +ctx := context.TODO() +id := partnernamespaces.NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + +read, err := client.ListSharedAccessKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerNamespacesClient.RegenerateKey` + +```go +ctx := context.TODO() +id := partnernamespaces.NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + +payload := partnernamespaces.PartnerNamespaceRegenerateKeyRequest{ + // ... +} + + +read, err := client.RegenerateKey(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerNamespacesClient.Update` + +```go +ctx := context.TODO() +id := partnernamespaces.NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + +payload := partnernamespaces.PartnerNamespaceUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/client.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/client.go new file mode 100644 index 00000000000..68a21b05d23 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/client.go @@ -0,0 +1,26 @@ +package partnernamespaces + +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 PartnerNamespacesClient struct { + Client *resourcemanager.Client +} + +func NewPartnerNamespacesClientWithBaseURI(sdkApi sdkEnv.Api) (*PartnerNamespacesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "partnernamespaces", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PartnerNamespacesClient: %+v", err) + } + + return &PartnerNamespacesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/constants.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/constants.go new file mode 100644 index 00000000000..5fb095eaa8b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/constants.go @@ -0,0 +1,330 @@ +package partnernamespaces + +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 IPActionType string + +const ( + IPActionTypeAllow IPActionType = "Allow" +) + +func PossibleValuesForIPActionType() []string { + return []string{ + string(IPActionTypeAllow), + } +} + +func (s *IPActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIPActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIPActionType(input string) (*IPActionType, error) { + vals := map[string]IPActionType{ + "allow": IPActionTypeAllow, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPActionType(input) + return &out, nil +} + +type PartnerNamespaceProvisioningState string + +const ( + PartnerNamespaceProvisioningStateCanceled PartnerNamespaceProvisioningState = "Canceled" + PartnerNamespaceProvisioningStateCreating PartnerNamespaceProvisioningState = "Creating" + PartnerNamespaceProvisioningStateDeleting PartnerNamespaceProvisioningState = "Deleting" + PartnerNamespaceProvisioningStateFailed PartnerNamespaceProvisioningState = "Failed" + PartnerNamespaceProvisioningStateSucceeded PartnerNamespaceProvisioningState = "Succeeded" + PartnerNamespaceProvisioningStateUpdating PartnerNamespaceProvisioningState = "Updating" +) + +func PossibleValuesForPartnerNamespaceProvisioningState() []string { + return []string{ + string(PartnerNamespaceProvisioningStateCanceled), + string(PartnerNamespaceProvisioningStateCreating), + string(PartnerNamespaceProvisioningStateDeleting), + string(PartnerNamespaceProvisioningStateFailed), + string(PartnerNamespaceProvisioningStateSucceeded), + string(PartnerNamespaceProvisioningStateUpdating), + } +} + +func (s *PartnerNamespaceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerNamespaceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerNamespaceProvisioningState(input string) (*PartnerNamespaceProvisioningState, error) { + vals := map[string]PartnerNamespaceProvisioningState{ + "canceled": PartnerNamespaceProvisioningStateCanceled, + "creating": PartnerNamespaceProvisioningStateCreating, + "deleting": PartnerNamespaceProvisioningStateDeleting, + "failed": PartnerNamespaceProvisioningStateFailed, + "succeeded": PartnerNamespaceProvisioningStateSucceeded, + "updating": PartnerNamespaceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerNamespaceProvisioningState(input) + return &out, nil +} + +type PartnerTopicRoutingMode string + +const ( + PartnerTopicRoutingModeChannelNameHeader PartnerTopicRoutingMode = "ChannelNameHeader" + PartnerTopicRoutingModeSourceEventAttribute PartnerTopicRoutingMode = "SourceEventAttribute" +) + +func PossibleValuesForPartnerTopicRoutingMode() []string { + return []string{ + string(PartnerTopicRoutingModeChannelNameHeader), + string(PartnerTopicRoutingModeSourceEventAttribute), + } +} + +func (s *PartnerTopicRoutingMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerTopicRoutingMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerTopicRoutingMode(input string) (*PartnerTopicRoutingMode, error) { + vals := map[string]PartnerTopicRoutingMode{ + "channelnameheader": PartnerTopicRoutingModeChannelNameHeader, + "sourceeventattribute": PartnerTopicRoutingModeSourceEventAttribute, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerTopicRoutingMode(input) + return &out, nil +} + +type PersistedConnectionStatus string + +const ( + PersistedConnectionStatusApproved PersistedConnectionStatus = "Approved" + PersistedConnectionStatusDisconnected PersistedConnectionStatus = "Disconnected" + PersistedConnectionStatusPending PersistedConnectionStatus = "Pending" + PersistedConnectionStatusRejected PersistedConnectionStatus = "Rejected" +) + +func PossibleValuesForPersistedConnectionStatus() []string { + return []string{ + string(PersistedConnectionStatusApproved), + string(PersistedConnectionStatusDisconnected), + string(PersistedConnectionStatusPending), + string(PersistedConnectionStatusRejected), + } +} + +func (s *PersistedConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePersistedConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePersistedConnectionStatus(input string) (*PersistedConnectionStatus, error) { + vals := map[string]PersistedConnectionStatus{ + "approved": PersistedConnectionStatusApproved, + "disconnected": PersistedConnectionStatusDisconnected, + "pending": PersistedConnectionStatusPending, + "rejected": PersistedConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersistedConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" + PublicNetworkAccessSecuredByPerimeter PublicNetworkAccess = "SecuredByPerimeter" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + string(PublicNetworkAccessSecuredByPerimeter), + } +} + +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, + "securedbyperimeter": PublicNetworkAccessSecuredByPerimeter, + } + 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 ResourceProvisioningState string + +const ( + ResourceProvisioningStateCanceled ResourceProvisioningState = "Canceled" + ResourceProvisioningStateCreating ResourceProvisioningState = "Creating" + ResourceProvisioningStateDeleting ResourceProvisioningState = "Deleting" + ResourceProvisioningStateFailed ResourceProvisioningState = "Failed" + ResourceProvisioningStateSucceeded ResourceProvisioningState = "Succeeded" + ResourceProvisioningStateUpdating ResourceProvisioningState = "Updating" +) + +func PossibleValuesForResourceProvisioningState() []string { + return []string{ + string(ResourceProvisioningStateCanceled), + string(ResourceProvisioningStateCreating), + string(ResourceProvisioningStateDeleting), + string(ResourceProvisioningStateFailed), + string(ResourceProvisioningStateSucceeded), + string(ResourceProvisioningStateUpdating), + } +} + +func (s *ResourceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceProvisioningState(input string) (*ResourceProvisioningState, error) { + vals := map[string]ResourceProvisioningState{ + "canceled": ResourceProvisioningStateCanceled, + "creating": ResourceProvisioningStateCreating, + "deleting": ResourceProvisioningStateDeleting, + "failed": ResourceProvisioningStateFailed, + "succeeded": ResourceProvisioningStateSucceeded, + "updating": ResourceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceProvisioningState(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/id_partnernamespace.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/id_partnernamespace.go new file mode 100644 index 00000000000..42d87dbc59c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/id_partnernamespace.go @@ -0,0 +1,125 @@ +package partnernamespaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PartnerNamespaceId{} + +// PartnerNamespaceId is a struct representing the Resource ID for a Partner Namespace +type PartnerNamespaceId struct { + SubscriptionId string + ResourceGroupName string + PartnerNamespaceName string +} + +// NewPartnerNamespaceID returns a new PartnerNamespaceId struct +func NewPartnerNamespaceID(subscriptionId string, resourceGroupName string, partnerNamespaceName string) PartnerNamespaceId { + return PartnerNamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerNamespaceName: partnerNamespaceName, + } +} + +// ParsePartnerNamespaceID parses 'input' into a PartnerNamespaceId +func ParsePartnerNamespaceID(input string) (*PartnerNamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerNamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerNamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePartnerNamespaceIDInsensitively parses 'input' case-insensitively into a PartnerNamespaceId +// note: this method should only be used for API response data and not user input +func ParsePartnerNamespaceIDInsensitively(input string) (*PartnerNamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerNamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerNamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PartnerNamespaceId) 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.PartnerNamespaceName, ok = input.Parsed["partnerNamespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerNamespaceName", input) + } + + return nil +} + +// ValidatePartnerNamespaceID checks that 'input' can be parsed as a Partner Namespace ID +func ValidatePartnerNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePartnerNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Partner Namespace ID +func (id PartnerNamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerNamespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerNamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Partner Namespace ID +func (id PartnerNamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerNamespaces", "partnerNamespaces", "partnerNamespaces"), + resourceids.UserSpecifiedSegment("partnerNamespaceName", "partnerNamespaceValue"), + } +} + +// String returns a human-readable description of this Partner Namespace ID +func (id PartnerNamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Namespace Name: %q", id.PartnerNamespaceName), + } + return fmt.Sprintf("Partner Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/id_partnernamespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/id_partnernamespace_test.go new file mode 100644 index 00000000000..469a8d1757b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/id_partnernamespace_test.go @@ -0,0 +1,282 @@ +package partnernamespaces + +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 = &PartnerNamespaceId{} + +func TestNewPartnerNamespaceID(t *testing.T) { + id := NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue") + + if id.SubscriptionId != "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.PartnerNamespaceName != "partnerNamespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerNamespaceName'", id.PartnerNamespaceName, "partnerNamespaceValue") + } +} + +func TestFormatPartnerNamespaceID(t *testing.T) { + actual := NewPartnerNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerNamespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePartnerNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerNamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue", + Expected: &PartnerNamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerNamespaceName: "partnerNamespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerNamespaceName != v.Expected.PartnerNamespaceName { + t.Fatalf("Expected %q but got %q for PartnerNamespaceName", v.Expected.PartnerNamespaceName, actual.PartnerNamespaceName) + } + + } +} + +func TestParsePartnerNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerNamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue", + Expected: &PartnerNamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerNamespaceName: "partnerNamespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerNamespaces/partnerNamespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe", + Expected: &PartnerNamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerNamespaceName: "pArTnErNaMeSpAcEvAlUe", + }, + }, + { + // 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.eVeNtGrId/pArTnErNaMeSpAcEs/pArTnErNaMeSpAcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerNamespaceName != v.Expected.PartnerNamespaceName { + t.Fatalf("Expected %q but got %q for PartnerNamespaceName", v.Expected.PartnerNamespaceName, actual.PartnerNamespaceName) + } + + } +} + +func TestSegmentsForPartnerNamespaceId(t *testing.T) { + segments := PartnerNamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PartnerNamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_createorupdate.go new file mode 100644 index 00000000000..d014d021771 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_createorupdate.go @@ -0,0 +1,74 @@ +package partnernamespaces + +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 *PartnerNamespace +} + +// CreateOrUpdate ... +func (c PartnerNamespacesClient) CreateOrUpdate(ctx context.Context, id PartnerNamespaceId, input PartnerNamespace) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PartnerNamespacesClient) CreateOrUpdateThenPoll(ctx context.Context, id PartnerNamespaceId, input PartnerNamespace) 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/eventgrid/2023-12-15-preview/partnernamespaces/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_delete.go new file mode 100644 index 00000000000..9970cbe32df --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_delete.go @@ -0,0 +1,71 @@ +package partnernamespaces + +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 PartnerNamespacesClient) Delete(ctx context.Context, id PartnerNamespaceId) (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 PartnerNamespacesClient) DeleteThenPoll(ctx context.Context, id PartnerNamespaceId) 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/eventgrid/2023-12-15-preview/partnernamespaces/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_get.go new file mode 100644 index 00000000000..56f09544bb3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_get.go @@ -0,0 +1,54 @@ +package partnernamespaces + +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 *PartnerNamespace +} + +// Get ... +func (c PartnerNamespacesClient) Get(ctx context.Context, id PartnerNamespaceId) (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 PartnerNamespace + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listbyresourcegroup.go new file mode 100644 index 00000000000..289c9216654 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package partnernamespaces + +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 *[]PartnerNamespace +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerNamespace +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c PartnerNamespacesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerNamespaces", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerNamespace `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 PartnerNamespacesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, PartnerNamespaceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerNamespacesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate PartnerNamespaceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]PartnerNamespace, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listbysubscription.go new file mode 100644 index 00000000000..70a4128d87c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listbysubscription.go @@ -0,0 +1,124 @@ +package partnernamespaces + +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 *[]PartnerNamespace +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerNamespace +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c PartnerNamespacesClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerNamespaces", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerNamespace `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 PartnerNamespacesClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, PartnerNamespaceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerNamespacesClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate PartnerNamespaceOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]PartnerNamespace, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listsharedaccesskeys.go new file mode 100644 index 00000000000..3680bb6ae51 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_listsharedaccesskeys.go @@ -0,0 +1,55 @@ +package partnernamespaces + +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 ListSharedAccessKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerNamespaceSharedAccessKeys +} + +// ListSharedAccessKeys ... +func (c PartnerNamespacesClient) ListSharedAccessKeys(ctx context.Context, id PartnerNamespaceId) (result ListSharedAccessKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PartnerNamespaceSharedAccessKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_regeneratekey.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_regeneratekey.go new file mode 100644 index 00000000000..13f92c98250 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_regeneratekey.go @@ -0,0 +1,59 @@ +package partnernamespaces + +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 RegenerateKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerNamespaceSharedAccessKeys +} + +// RegenerateKey ... +func (c PartnerNamespacesClient) RegenerateKey(ctx context.Context, id PartnerNamespaceId, input PartnerNamespaceRegenerateKeyRequest) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PartnerNamespaceSharedAccessKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_update.go new file mode 100644 index 00000000000..324e192562c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/method_update.go @@ -0,0 +1,75 @@ +package partnernamespaces + +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 *PartnerNamespace +} + +// Update ... +func (c PartnerNamespacesClient) Update(ctx context.Context, id PartnerNamespaceId, input PartnerNamespaceUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + 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 PartnerNamespacesClient) UpdateThenPoll(ctx context.Context, id PartnerNamespaceId, input PartnerNamespaceUpdateParameters) 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/eventgrid/2023-12-15-preview/partnernamespaces/model_connectionstate.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_connectionstate.go new file mode 100644 index 00000000000..8f6a78ec88f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_connectionstate.go @@ -0,0 +1,10 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PersistedConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_inboundiprule.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_inboundiprule.go new file mode 100644 index 00000000000..9d9c2e109f4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_inboundiprule.go @@ -0,0 +1,9 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InboundIPRule struct { + Action *IPActionType `json:"action,omitempty"` + IPMask *string `json:"ipMask,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespace.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespace.go new file mode 100644 index 00000000000..95f54b95122 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespace.go @@ -0,0 +1,18 @@ +package partnernamespaces + +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 PartnerNamespace struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *PartnerNamespaceProperties `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/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceproperties.go new file mode 100644 index 00000000000..e1b1a1659dd --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceproperties.go @@ -0,0 +1,16 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerNamespaceProperties struct { + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + Endpoint *string `json:"endpoint,omitempty"` + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PartnerRegistrationFullyQualifiedId *string `json:"partnerRegistrationFullyQualifiedId,omitempty"` + PartnerTopicRoutingMode *PartnerTopicRoutingMode `json:"partnerTopicRoutingMode,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *PartnerNamespaceProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceregeneratekeyrequest.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceregeneratekeyrequest.go new file mode 100644 index 00000000000..0e27cc635e4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceregeneratekeyrequest.go @@ -0,0 +1,8 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerNamespaceRegenerateKeyRequest struct { + KeyName string `json:"keyName"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespacesharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespacesharedaccesskeys.go new file mode 100644 index 00000000000..b8d577330be --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespacesharedaccesskeys.go @@ -0,0 +1,9 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerNamespaceSharedAccessKeys struct { + Key1 *string `json:"key1,omitempty"` + Key2 *string `json:"key2,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceupdateparameterproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceupdateparameterproperties.go new file mode 100644 index 00000000000..b2d330a7d36 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceupdateparameterproperties.go @@ -0,0 +1,11 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerNamespaceUpdateParameterProperties struct { + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceupdateparameters.go new file mode 100644 index 00000000000..76183addcc5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_partnernamespaceupdateparameters.go @@ -0,0 +1,9 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerNamespaceUpdateParameters struct { + Properties *PartnerNamespaceUpdateParameterProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpoint.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpoint.go new file mode 100644 index 00000000000..9dbd16c0999 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpoint.go @@ -0,0 +1,8 @@ +package partnernamespaces + +// 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/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpointconnection.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpointconnection.go new file mode 100644 index 00000000000..62de6a8e374 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpointconnectionproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..68b325b9a81 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package partnernamespaces + +// 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 *ConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ResourceProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/predicates.go new file mode 100644 index 00000000000..9cc1daca56b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/predicates.go @@ -0,0 +1,32 @@ +package partnernamespaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerNamespaceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PartnerNamespaceOperationPredicate) Matches(input PartnerNamespace) 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/eventgrid/2023-12-15-preview/partnernamespaces/version.go b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/version.go new file mode 100644 index 00000000000..668f95e9fb5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnernamespaces/version.go @@ -0,0 +1,12 @@ +package partnernamespaces + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/partnernamespaces/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/README.md b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/README.md new file mode 100644 index 00000000000..bbe76d3de25 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations` Documentation + +The `partnerregistrations` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/partnerregistrations" +``` + + +### Client Initialization + +```go +client := partnerregistrations.NewPartnerRegistrationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PartnerRegistrationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := partnerregistrations.NewPartnerRegistrationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerRegistrationValue") + +payload := partnerregistrations.PartnerRegistration{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerRegistrationsClient.Delete` + +```go +ctx := context.TODO() +id := partnerregistrations.NewPartnerRegistrationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerRegistrationValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerRegistrationsClient.Get` + +```go +ctx := context.TODO() +id := partnerregistrations.NewPartnerRegistrationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerRegistrationValue") + +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: `PartnerRegistrationsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, partnerregistrations.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, partnerregistrations.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerRegistrationsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, partnerregistrations.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, partnerregistrations.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerRegistrationsClient.Update` + +```go +ctx := context.TODO() +id := partnerregistrations.NewPartnerRegistrationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerRegistrationValue") + +payload := partnerregistrations.PartnerRegistrationUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/client.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/client.go new file mode 100644 index 00000000000..470bfd1ed46 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/client.go @@ -0,0 +1,26 @@ +package partnerregistrations + +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 PartnerRegistrationsClient struct { + Client *resourcemanager.Client +} + +func NewPartnerRegistrationsClientWithBaseURI(sdkApi sdkEnv.Api) (*PartnerRegistrationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "partnerregistrations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PartnerRegistrationsClient: %+v", err) + } + + return &PartnerRegistrationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/constants.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/constants.go new file mode 100644 index 00000000000..0ac241ea7af --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/constants.go @@ -0,0 +1,63 @@ +package partnerregistrations + +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 PartnerRegistrationProvisioningState string + +const ( + PartnerRegistrationProvisioningStateCanceled PartnerRegistrationProvisioningState = "Canceled" + PartnerRegistrationProvisioningStateCreating PartnerRegistrationProvisioningState = "Creating" + PartnerRegistrationProvisioningStateDeleting PartnerRegistrationProvisioningState = "Deleting" + PartnerRegistrationProvisioningStateFailed PartnerRegistrationProvisioningState = "Failed" + PartnerRegistrationProvisioningStateSucceeded PartnerRegistrationProvisioningState = "Succeeded" + PartnerRegistrationProvisioningStateUpdating PartnerRegistrationProvisioningState = "Updating" +) + +func PossibleValuesForPartnerRegistrationProvisioningState() []string { + return []string{ + string(PartnerRegistrationProvisioningStateCanceled), + string(PartnerRegistrationProvisioningStateCreating), + string(PartnerRegistrationProvisioningStateDeleting), + string(PartnerRegistrationProvisioningStateFailed), + string(PartnerRegistrationProvisioningStateSucceeded), + string(PartnerRegistrationProvisioningStateUpdating), + } +} + +func (s *PartnerRegistrationProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerRegistrationProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerRegistrationProvisioningState(input string) (*PartnerRegistrationProvisioningState, error) { + vals := map[string]PartnerRegistrationProvisioningState{ + "canceled": PartnerRegistrationProvisioningStateCanceled, + "creating": PartnerRegistrationProvisioningStateCreating, + "deleting": PartnerRegistrationProvisioningStateDeleting, + "failed": PartnerRegistrationProvisioningStateFailed, + "succeeded": PartnerRegistrationProvisioningStateSucceeded, + "updating": PartnerRegistrationProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerRegistrationProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/id_partnerregistration.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/id_partnerregistration.go new file mode 100644 index 00000000000..56035c358c8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/id_partnerregistration.go @@ -0,0 +1,125 @@ +package partnerregistrations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PartnerRegistrationId{} + +// PartnerRegistrationId is a struct representing the Resource ID for a Partner Registration +type PartnerRegistrationId struct { + SubscriptionId string + ResourceGroupName string + PartnerRegistrationName string +} + +// NewPartnerRegistrationID returns a new PartnerRegistrationId struct +func NewPartnerRegistrationID(subscriptionId string, resourceGroupName string, partnerRegistrationName string) PartnerRegistrationId { + return PartnerRegistrationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerRegistrationName: partnerRegistrationName, + } +} + +// ParsePartnerRegistrationID parses 'input' into a PartnerRegistrationId +func ParsePartnerRegistrationID(input string) (*PartnerRegistrationId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerRegistrationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerRegistrationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePartnerRegistrationIDInsensitively parses 'input' case-insensitively into a PartnerRegistrationId +// note: this method should only be used for API response data and not user input +func ParsePartnerRegistrationIDInsensitively(input string) (*PartnerRegistrationId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerRegistrationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerRegistrationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PartnerRegistrationId) 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.PartnerRegistrationName, ok = input.Parsed["partnerRegistrationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerRegistrationName", input) + } + + return nil +} + +// ValidatePartnerRegistrationID checks that 'input' can be parsed as a Partner Registration ID +func ValidatePartnerRegistrationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePartnerRegistrationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Partner Registration ID +func (id PartnerRegistrationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerRegistrations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerRegistrationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Partner Registration ID +func (id PartnerRegistrationId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerRegistrations", "partnerRegistrations", "partnerRegistrations"), + resourceids.UserSpecifiedSegment("partnerRegistrationName", "partnerRegistrationValue"), + } +} + +// String returns a human-readable description of this Partner Registration ID +func (id PartnerRegistrationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Registration Name: %q", id.PartnerRegistrationName), + } + return fmt.Sprintf("Partner Registration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/id_partnerregistration_test.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/id_partnerregistration_test.go new file mode 100644 index 00000000000..7ea2f505af7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/id_partnerregistration_test.go @@ -0,0 +1,282 @@ +package partnerregistrations + +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 = &PartnerRegistrationId{} + +func TestNewPartnerRegistrationID(t *testing.T) { + id := NewPartnerRegistrationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerRegistrationValue") + + if id.SubscriptionId != "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.PartnerRegistrationName != "partnerRegistrationValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerRegistrationName'", id.PartnerRegistrationName, "partnerRegistrationValue") + } +} + +func TestFormatPartnerRegistrationID(t *testing.T) { + actual := NewPartnerRegistrationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerRegistrationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerRegistrations/partnerRegistrationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePartnerRegistrationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerRegistrationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerRegistrations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerRegistrations/partnerRegistrationValue", + Expected: &PartnerRegistrationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerRegistrationName: "partnerRegistrationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerRegistrations/partnerRegistrationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerRegistrationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerRegistrationName != v.Expected.PartnerRegistrationName { + t.Fatalf("Expected %q but got %q for PartnerRegistrationName", v.Expected.PartnerRegistrationName, actual.PartnerRegistrationName) + } + + } +} + +func TestParsePartnerRegistrationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerRegistrationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerRegistrations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErReGiStRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerRegistrations/partnerRegistrationValue", + Expected: &PartnerRegistrationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerRegistrationName: "partnerRegistrationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerRegistrations/partnerRegistrationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErReGiStRaTiOnS/pArTnErReGiStRaTiOnVaLuE", + Expected: &PartnerRegistrationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerRegistrationName: "pArTnErReGiStRaTiOnVaLuE", + }, + }, + { + // 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.eVeNtGrId/pArTnErReGiStRaTiOnS/pArTnErReGiStRaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerRegistrationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerRegistrationName != v.Expected.PartnerRegistrationName { + t.Fatalf("Expected %q but got %q for PartnerRegistrationName", v.Expected.PartnerRegistrationName, actual.PartnerRegistrationName) + } + + } +} + +func TestSegmentsForPartnerRegistrationId(t *testing.T) { + segments := PartnerRegistrationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PartnerRegistrationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_createorupdate.go new file mode 100644 index 00000000000..d07756b5a1b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_createorupdate.go @@ -0,0 +1,75 @@ +package partnerregistrations + +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 *PartnerRegistration +} + +// CreateOrUpdate ... +func (c PartnerRegistrationsClient) CreateOrUpdate(ctx context.Context, id PartnerRegistrationId, input PartnerRegistration) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 PartnerRegistrationsClient) CreateOrUpdateThenPoll(ctx context.Context, id PartnerRegistrationId, input PartnerRegistration) 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/eventgrid/2023-12-15-preview/partnerregistrations/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_delete.go new file mode 100644 index 00000000000..e5f684e2482 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_delete.go @@ -0,0 +1,71 @@ +package partnerregistrations + +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 PartnerRegistrationsClient) Delete(ctx context.Context, id PartnerRegistrationId) (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 PartnerRegistrationsClient) DeleteThenPoll(ctx context.Context, id PartnerRegistrationId) 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/eventgrid/2023-12-15-preview/partnerregistrations/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_get.go new file mode 100644 index 00000000000..a309e2f0ed6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_get.go @@ -0,0 +1,54 @@ +package partnerregistrations + +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 *PartnerRegistration +} + +// Get ... +func (c PartnerRegistrationsClient) Get(ctx context.Context, id PartnerRegistrationId) (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 PartnerRegistration + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_listbyresourcegroup.go new file mode 100644 index 00000000000..fef03b9382e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package partnerregistrations + +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 *[]PartnerRegistration +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerRegistration +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c PartnerRegistrationsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerRegistrations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerRegistration `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 PartnerRegistrationsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, PartnerRegistrationOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerRegistrationsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate PartnerRegistrationOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]PartnerRegistration, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_listbysubscription.go new file mode 100644 index 00000000000..c65842be24d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_listbysubscription.go @@ -0,0 +1,124 @@ +package partnerregistrations + +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 *[]PartnerRegistration +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerRegistration +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c PartnerRegistrationsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerRegistrations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerRegistration `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 PartnerRegistrationsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, PartnerRegistrationOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerRegistrationsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate PartnerRegistrationOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]PartnerRegistration, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_update.go new file mode 100644 index 00000000000..bdd494de028 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/method_update.go @@ -0,0 +1,75 @@ +package partnerregistrations + +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 *PartnerRegistration +} + +// Update ... +func (c PartnerRegistrationsClient) Update(ctx context.Context, id PartnerRegistrationId, input PartnerRegistrationUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + 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 PartnerRegistrationsClient) UpdateThenPoll(ctx context.Context, id PartnerRegistrationId, input PartnerRegistrationUpdateParameters) 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/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistration.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistration.go new file mode 100644 index 00000000000..6c367c2ecb6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistration.go @@ -0,0 +1,18 @@ +package partnerregistrations + +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 PartnerRegistration struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *PartnerRegistrationProperties `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/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistrationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistrationproperties.go new file mode 100644 index 00000000000..dcbdb77de64 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistrationproperties.go @@ -0,0 +1,9 @@ +package partnerregistrations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerRegistrationProperties struct { + PartnerRegistrationImmutableId *string `json:"partnerRegistrationImmutableId,omitempty"` + ProvisioningState *PartnerRegistrationProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistrationupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistrationupdateparameters.go new file mode 100644 index 00000000000..03add3e3186 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/model_partnerregistrationupdateparameters.go @@ -0,0 +1,8 @@ +package partnerregistrations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerRegistrationUpdateParameters struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/predicates.go new file mode 100644 index 00000000000..f3faf094ded --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/predicates.go @@ -0,0 +1,32 @@ +package partnerregistrations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerRegistrationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PartnerRegistrationOperationPredicate) Matches(input PartnerRegistration) 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/eventgrid/2023-12-15-preview/partnerregistrations/version.go b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/version.go new file mode 100644 index 00000000000..d39a97732b9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnerregistrations/version.go @@ -0,0 +1,12 @@ +package partnerregistrations + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/partnerregistrations/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/README.md b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/README.md new file mode 100644 index 00000000000..2752490e7f2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/README.md @@ -0,0 +1,157 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/partnertopics` Documentation + +The `partnertopics` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/partnertopics" +``` + + +### Client Initialization + +```go +client := partnertopics.NewPartnerTopicsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PartnerTopicsClient.Activate` + +```go +ctx := context.TODO() +id := partnertopics.NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + +read, err := client.Activate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerTopicsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := partnertopics.NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + +payload := partnertopics.PartnerTopic{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerTopicsClient.Deactivate` + +```go +ctx := context.TODO() +id := partnertopics.NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + +read, err := client.Deactivate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PartnerTopicsClient.Delete` + +```go +ctx := context.TODO() +id := partnertopics.NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PartnerTopicsClient.Get` + +```go +ctx := context.TODO() +id := partnertopics.NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + +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: `PartnerTopicsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, partnertopics.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, partnertopics.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerTopicsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, partnertopics.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, partnertopics.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PartnerTopicsClient.Update` + +```go +ctx := context.TODO() +id := partnertopics.NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + +payload := partnertopics.PartnerTopicUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/client.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/client.go new file mode 100644 index 00000000000..d2c0336576d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/client.go @@ -0,0 +1,26 @@ +package partnertopics + +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 PartnerTopicsClient struct { + Client *resourcemanager.Client +} + +func NewPartnerTopicsClientWithBaseURI(sdkApi sdkEnv.Api) (*PartnerTopicsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "partnertopics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PartnerTopicsClient: %+v", err) + } + + return &PartnerTopicsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/constants.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/constants.go new file mode 100644 index 00000000000..fc30a800550 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/constants.go @@ -0,0 +1,148 @@ +package partnertopics + +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 EventDefinitionKind string + +const ( + EventDefinitionKindInline EventDefinitionKind = "Inline" +) + +func PossibleValuesForEventDefinitionKind() []string { + return []string{ + string(EventDefinitionKindInline), + } +} + +func (s *EventDefinitionKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventDefinitionKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventDefinitionKind(input string) (*EventDefinitionKind, error) { + vals := map[string]EventDefinitionKind{ + "inline": EventDefinitionKindInline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventDefinitionKind(input) + return &out, nil +} + +type PartnerTopicActivationState string + +const ( + PartnerTopicActivationStateActivated PartnerTopicActivationState = "Activated" + PartnerTopicActivationStateDeactivated PartnerTopicActivationState = "Deactivated" + PartnerTopicActivationStateNeverActivated PartnerTopicActivationState = "NeverActivated" +) + +func PossibleValuesForPartnerTopicActivationState() []string { + return []string{ + string(PartnerTopicActivationStateActivated), + string(PartnerTopicActivationStateDeactivated), + string(PartnerTopicActivationStateNeverActivated), + } +} + +func (s *PartnerTopicActivationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerTopicActivationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerTopicActivationState(input string) (*PartnerTopicActivationState, error) { + vals := map[string]PartnerTopicActivationState{ + "activated": PartnerTopicActivationStateActivated, + "deactivated": PartnerTopicActivationStateDeactivated, + "neveractivated": PartnerTopicActivationStateNeverActivated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerTopicActivationState(input) + return &out, nil +} + +type PartnerTopicProvisioningState string + +const ( + PartnerTopicProvisioningStateCanceled PartnerTopicProvisioningState = "Canceled" + PartnerTopicProvisioningStateCreating PartnerTopicProvisioningState = "Creating" + PartnerTopicProvisioningStateDeleting PartnerTopicProvisioningState = "Deleting" + PartnerTopicProvisioningStateFailed PartnerTopicProvisioningState = "Failed" + PartnerTopicProvisioningStateIdleDueToMirroredChannelResourceDeletion PartnerTopicProvisioningState = "IdleDueToMirroredChannelResourceDeletion" + PartnerTopicProvisioningStateSucceeded PartnerTopicProvisioningState = "Succeeded" + PartnerTopicProvisioningStateUpdating PartnerTopicProvisioningState = "Updating" +) + +func PossibleValuesForPartnerTopicProvisioningState() []string { + return []string{ + string(PartnerTopicProvisioningStateCanceled), + string(PartnerTopicProvisioningStateCreating), + string(PartnerTopicProvisioningStateDeleting), + string(PartnerTopicProvisioningStateFailed), + string(PartnerTopicProvisioningStateIdleDueToMirroredChannelResourceDeletion), + string(PartnerTopicProvisioningStateSucceeded), + string(PartnerTopicProvisioningStateUpdating), + } +} + +func (s *PartnerTopicProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePartnerTopicProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePartnerTopicProvisioningState(input string) (*PartnerTopicProvisioningState, error) { + vals := map[string]PartnerTopicProvisioningState{ + "canceled": PartnerTopicProvisioningStateCanceled, + "creating": PartnerTopicProvisioningStateCreating, + "deleting": PartnerTopicProvisioningStateDeleting, + "failed": PartnerTopicProvisioningStateFailed, + "idleduetomirroredchannelresourcedeletion": PartnerTopicProvisioningStateIdleDueToMirroredChannelResourceDeletion, + "succeeded": PartnerTopicProvisioningStateSucceeded, + "updating": PartnerTopicProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PartnerTopicProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/id_partnertopic.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/id_partnertopic.go new file mode 100644 index 00000000000..be3b1419455 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/id_partnertopic.go @@ -0,0 +1,125 @@ +package partnertopics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PartnerTopicId{} + +// PartnerTopicId is a struct representing the Resource ID for a Partner Topic +type PartnerTopicId struct { + SubscriptionId string + ResourceGroupName string + PartnerTopicName string +} + +// NewPartnerTopicID returns a new PartnerTopicId struct +func NewPartnerTopicID(subscriptionId string, resourceGroupName string, partnerTopicName string) PartnerTopicId { + return PartnerTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PartnerTopicName: partnerTopicName, + } +} + +// ParsePartnerTopicID parses 'input' into a PartnerTopicId +func ParsePartnerTopicID(input string) (*PartnerTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePartnerTopicIDInsensitively parses 'input' case-insensitively into a PartnerTopicId +// note: this method should only be used for API response data and not user input +func ParsePartnerTopicIDInsensitively(input string) (*PartnerTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&PartnerTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PartnerTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PartnerTopicId) 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.PartnerTopicName, ok = input.Parsed["partnerTopicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "partnerTopicName", input) + } + + return nil +} + +// ValidatePartnerTopicID checks that 'input' can be parsed as a Partner Topic ID +func ValidatePartnerTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePartnerTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Partner Topic ID +func (id PartnerTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/partnerTopics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PartnerTopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Partner Topic ID +func (id PartnerTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticPartnerTopics", "partnerTopics", "partnerTopics"), + resourceids.UserSpecifiedSegment("partnerTopicName", "partnerTopicValue"), + } +} + +// String returns a human-readable description of this Partner Topic ID +func (id PartnerTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Partner Topic Name: %q", id.PartnerTopicName), + } + return fmt.Sprintf("Partner Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/id_partnertopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/id_partnertopic_test.go new file mode 100644 index 00000000000..539c6b9e3e7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/id_partnertopic_test.go @@ -0,0 +1,282 @@ +package partnertopics + +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 = &PartnerTopicId{} + +func TestNewPartnerTopicID(t *testing.T) { + id := NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue") + + if id.SubscriptionId != "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.PartnerTopicName != "partnerTopicValue" { + t.Fatalf("Expected %q but got %q for Segment 'PartnerTopicName'", id.PartnerTopicName, "partnerTopicValue") + } +} + +func TestFormatPartnerTopicID(t *testing.T) { + actual := NewPartnerTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "partnerTopicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePartnerTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue", + Expected: &PartnerTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerTopicName: "partnerTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerTopicName != v.Expected.PartnerTopicName { + t.Fatalf("Expected %q but got %q for PartnerTopicName", v.Expected.PartnerTopicName, actual.PartnerTopicName) + } + + } +} + +func TestParsePartnerTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PartnerTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue", + Expected: &PartnerTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PartnerTopicName: "partnerTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/partnerTopics/partnerTopicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe", + Expected: &PartnerTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PartnerTopicName: "pArTnErToPiCvAlUe", + }, + }, + { + // 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.eVeNtGrId/pArTnErToPiCs/pArTnErToPiCvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePartnerTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PartnerTopicName != v.Expected.PartnerTopicName { + t.Fatalf("Expected %q but got %q for PartnerTopicName", v.Expected.PartnerTopicName, actual.PartnerTopicName) + } + + } +} + +func TestSegmentsForPartnerTopicId(t *testing.T) { + segments := PartnerTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PartnerTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_activate.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_activate.go new file mode 100644 index 00000000000..d99c89ffc49 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_activate.go @@ -0,0 +1,55 @@ +package partnertopics + +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 ActivateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerTopic +} + +// Activate ... +func (c PartnerTopicsClient) Activate(ctx context.Context, id PartnerTopicId) (result ActivateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/activate", 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 PartnerTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_createorupdate.go new file mode 100644 index 00000000000..b3cc284c092 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_createorupdate.go @@ -0,0 +1,59 @@ +package partnertopics + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerTopic +} + +// CreateOrUpdate ... +func (c PartnerTopicsClient) CreateOrUpdate(ctx context.Context, id PartnerTopicId, input PartnerTopic) (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 + } + + var model PartnerTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_deactivate.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_deactivate.go new file mode 100644 index 00000000000..704ce7b2beb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_deactivate.go @@ -0,0 +1,55 @@ +package partnertopics + +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 DeactivateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerTopic +} + +// Deactivate ... +func (c PartnerTopicsClient) Deactivate(ctx context.Context, id PartnerTopicId) (result DeactivateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/deactivate", 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 PartnerTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_delete.go new file mode 100644 index 00000000000..f131c9b3e77 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_delete.go @@ -0,0 +1,71 @@ +package partnertopics + +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 PartnerTopicsClient) Delete(ctx context.Context, id PartnerTopicId) (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 PartnerTopicsClient) DeleteThenPoll(ctx context.Context, id PartnerTopicId) 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/eventgrid/2023-12-15-preview/partnertopics/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_get.go new file mode 100644 index 00000000000..166a4bfa628 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_get.go @@ -0,0 +1,54 @@ +package partnertopics + +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 *PartnerTopic +} + +// Get ... +func (c PartnerTopicsClient) Get(ctx context.Context, id PartnerTopicId) (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 PartnerTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_listbyresourcegroup.go new file mode 100644 index 00000000000..d5de4bd7602 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package partnertopics + +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 *[]PartnerTopic +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerTopic +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c PartnerTopicsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerTopics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerTopic `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 PartnerTopicsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, PartnerTopicOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerTopicsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate PartnerTopicOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]PartnerTopic, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_listbysubscription.go new file mode 100644 index 00000000000..1d635f96dc3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_listbysubscription.go @@ -0,0 +1,124 @@ +package partnertopics + +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 *[]PartnerTopic +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []PartnerTopic +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c PartnerTopicsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/partnerTopics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PartnerTopic `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 PartnerTopicsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, PartnerTopicOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PartnerTopicsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate PartnerTopicOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]PartnerTopic, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_update.go new file mode 100644 index 00000000000..223499933b6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/method_update.go @@ -0,0 +1,59 @@ +package partnertopics + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PartnerTopic +} + +// Update ... +func (c PartnerTopicsClient) Update(ctx context.Context, id PartnerTopicId, input PartnerTopicUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + 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 + } + + var model PartnerTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_eventtypeinfo.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_eventtypeinfo.go new file mode 100644 index 00000000000..08cd29fc3ac --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_eventtypeinfo.go @@ -0,0 +1,9 @@ +package partnertopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypeInfo struct { + InlineEventTypes *map[string]InlineEventProperties `json:"inlineEventTypes,omitempty"` + Kind *EventDefinitionKind `json:"kind,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_inlineeventproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_inlineeventproperties.go new file mode 100644 index 00000000000..e03a71ee086 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_inlineeventproperties.go @@ -0,0 +1,11 @@ +package partnertopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InlineEventProperties struct { + DataSchemaUrl *string `json:"dataSchemaUrl,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + DocumentationUrl *string `json:"documentationUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopic.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopic.go new file mode 100644 index 00000000000..d2c969b49ba --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopic.go @@ -0,0 +1,20 @@ +package partnertopics + +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 PartnerTopic struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *PartnerTopicProperties `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/eventgrid/2023-12-15-preview/partnertopics/model_partnertopicproperties.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopicproperties.go new file mode 100644 index 00000000000..ae6f0a4ee71 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopicproperties.go @@ -0,0 +1,33 @@ +package partnertopics + +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 PartnerTopicProperties struct { + ActivationState *PartnerTopicActivationState `json:"activationState,omitempty"` + EventTypeInfo *EventTypeInfo `json:"eventTypeInfo,omitempty"` + ExpirationTimeIfNotActivatedUtc *string `json:"expirationTimeIfNotActivatedUtc,omitempty"` + MessageForActivation *string `json:"messageForActivation,omitempty"` + PartnerRegistrationImmutableId *string `json:"partnerRegistrationImmutableId,omitempty"` + PartnerTopicFriendlyDescription *string `json:"partnerTopicFriendlyDescription,omitempty"` + ProvisioningState *PartnerTopicProvisioningState `json:"provisioningState,omitempty"` + Source *string `json:"source,omitempty"` +} + +func (o *PartnerTopicProperties) GetExpirationTimeIfNotActivatedUtcAsTime() (*time.Time, error) { + if o.ExpirationTimeIfNotActivatedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeIfNotActivatedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *PartnerTopicProperties) SetExpirationTimeIfNotActivatedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeIfNotActivatedUtc = &formatted +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopicupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopicupdateparameters.go new file mode 100644 index 00000000000..c5c654f8228 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/model_partnertopicupdateparameters.go @@ -0,0 +1,13 @@ +package partnertopics + +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 PartnerTopicUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/partnertopics/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/predicates.go new file mode 100644 index 00000000000..5659c12644b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/predicates.go @@ -0,0 +1,32 @@ +package partnertopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerTopicOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PartnerTopicOperationPredicate) Matches(input PartnerTopic) 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/eventgrid/2023-12-15-preview/partnertopics/version.go b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/version.go new file mode 100644 index 00000000000..b9e5d0b0303 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/partnertopics/version.go @@ -0,0 +1,12 @@ +package partnertopics + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/partnertopics/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/README.md b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/README.md new file mode 100644 index 00000000000..3ad5cdad6c2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/README.md @@ -0,0 +1,66 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies` Documentation + +The `perimeterassociationproxies` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/perimeterassociationproxies" +``` + + +### Client Initialization + +```go +client := perimeterassociationproxies.NewPerimeterAssociationProxiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PerimeterAssociationProxiesClient.NetworkSecurityPerimeterConfigurationsGet` + +```go +ctx := context.TODO() +id := perimeterassociationproxies.NewScopedNetworkSecurityPerimeterConfigurationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "networkSecurityPerimeterConfigurationValue") + +read, err := client.NetworkSecurityPerimeterConfigurationsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PerimeterAssociationProxiesClient.NetworkSecurityPerimeterConfigurationsList` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.NetworkSecurityPerimeterConfigurationsList(ctx, id)` can be used to do batched pagination +items, err := client.NetworkSecurityPerimeterConfigurationsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PerimeterAssociationProxiesClient.NetworkSecurityPerimeterConfigurationsReconcile` + +```go +ctx := context.TODO() +id := perimeterassociationproxies.NewScopedNetworkSecurityPerimeterConfigurationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "networkSecurityPerimeterConfigurationValue") + +if err := client.NetworkSecurityPerimeterConfigurationsReconcileThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/client.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/client.go new file mode 100644 index 00000000000..e39ac1f5eb2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/client.go @@ -0,0 +1,26 @@ +package perimeterassociationproxies + +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 PerimeterAssociationProxiesClient struct { + Client *resourcemanager.Client +} + +func NewPerimeterAssociationProxiesClientWithBaseURI(sdkApi sdkEnv.Api) (*PerimeterAssociationProxiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "perimeterassociationproxies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PerimeterAssociationProxiesClient: %+v", err) + } + + return &PerimeterAssociationProxiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/constants.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/constants.go new file mode 100644 index 00000000000..a9f2f201fb4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/constants.go @@ -0,0 +1,242 @@ +package perimeterassociationproxies + +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 NetworkSecurityPerimeterAssociationAccessMode string + +const ( + NetworkSecurityPerimeterAssociationAccessModeAudit NetworkSecurityPerimeterAssociationAccessMode = "Audit" + NetworkSecurityPerimeterAssociationAccessModeEnforced NetworkSecurityPerimeterAssociationAccessMode = "Enforced" + NetworkSecurityPerimeterAssociationAccessModeLearning NetworkSecurityPerimeterAssociationAccessMode = "Learning" +) + +func PossibleValuesForNetworkSecurityPerimeterAssociationAccessMode() []string { + return []string{ + string(NetworkSecurityPerimeterAssociationAccessModeAudit), + string(NetworkSecurityPerimeterAssociationAccessModeEnforced), + string(NetworkSecurityPerimeterAssociationAccessModeLearning), + } +} + +func (s *NetworkSecurityPerimeterAssociationAccessMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkSecurityPerimeterAssociationAccessMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkSecurityPerimeterAssociationAccessMode(input string) (*NetworkSecurityPerimeterAssociationAccessMode, error) { + vals := map[string]NetworkSecurityPerimeterAssociationAccessMode{ + "audit": NetworkSecurityPerimeterAssociationAccessModeAudit, + "enforced": NetworkSecurityPerimeterAssociationAccessModeEnforced, + "learning": NetworkSecurityPerimeterAssociationAccessModeLearning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkSecurityPerimeterAssociationAccessMode(input) + return &out, nil +} + +type NetworkSecurityPerimeterConfigProvisioningState string + +const ( + NetworkSecurityPerimeterConfigProvisioningStateAccepted NetworkSecurityPerimeterConfigProvisioningState = "Accepted" + NetworkSecurityPerimeterConfigProvisioningStateCanceled NetworkSecurityPerimeterConfigProvisioningState = "Canceled" + NetworkSecurityPerimeterConfigProvisioningStateCreating NetworkSecurityPerimeterConfigProvisioningState = "Creating" + NetworkSecurityPerimeterConfigProvisioningStateDeleted NetworkSecurityPerimeterConfigProvisioningState = "Deleted" + NetworkSecurityPerimeterConfigProvisioningStateDeleting NetworkSecurityPerimeterConfigProvisioningState = "Deleting" + NetworkSecurityPerimeterConfigProvisioningStateFailed NetworkSecurityPerimeterConfigProvisioningState = "Failed" + NetworkSecurityPerimeterConfigProvisioningStateSucceeded NetworkSecurityPerimeterConfigProvisioningState = "Succeeded" + NetworkSecurityPerimeterConfigProvisioningStateUpdating NetworkSecurityPerimeterConfigProvisioningState = "Updating" +) + +func PossibleValuesForNetworkSecurityPerimeterConfigProvisioningState() []string { + return []string{ + string(NetworkSecurityPerimeterConfigProvisioningStateAccepted), + string(NetworkSecurityPerimeterConfigProvisioningStateCanceled), + string(NetworkSecurityPerimeterConfigProvisioningStateCreating), + string(NetworkSecurityPerimeterConfigProvisioningStateDeleted), + string(NetworkSecurityPerimeterConfigProvisioningStateDeleting), + string(NetworkSecurityPerimeterConfigProvisioningStateFailed), + string(NetworkSecurityPerimeterConfigProvisioningStateSucceeded), + string(NetworkSecurityPerimeterConfigProvisioningStateUpdating), + } +} + +func (s *NetworkSecurityPerimeterConfigProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkSecurityPerimeterConfigProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkSecurityPerimeterConfigProvisioningState(input string) (*NetworkSecurityPerimeterConfigProvisioningState, error) { + vals := map[string]NetworkSecurityPerimeterConfigProvisioningState{ + "accepted": NetworkSecurityPerimeterConfigProvisioningStateAccepted, + "canceled": NetworkSecurityPerimeterConfigProvisioningStateCanceled, + "creating": NetworkSecurityPerimeterConfigProvisioningStateCreating, + "deleted": NetworkSecurityPerimeterConfigProvisioningStateDeleted, + "deleting": NetworkSecurityPerimeterConfigProvisioningStateDeleting, + "failed": NetworkSecurityPerimeterConfigProvisioningStateFailed, + "succeeded": NetworkSecurityPerimeterConfigProvisioningStateSucceeded, + "updating": NetworkSecurityPerimeterConfigProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkSecurityPerimeterConfigProvisioningState(input) + return &out, nil +} + +type NetworkSecurityPerimeterConfigurationIssueSeverity string + +const ( + NetworkSecurityPerimeterConfigurationIssueSeverityError NetworkSecurityPerimeterConfigurationIssueSeverity = "Error" + NetworkSecurityPerimeterConfigurationIssueSeverityWarning NetworkSecurityPerimeterConfigurationIssueSeverity = "Warning" +) + +func PossibleValuesForNetworkSecurityPerimeterConfigurationIssueSeverity() []string { + return []string{ + string(NetworkSecurityPerimeterConfigurationIssueSeverityError), + string(NetworkSecurityPerimeterConfigurationIssueSeverityWarning), + } +} + +func (s *NetworkSecurityPerimeterConfigurationIssueSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkSecurityPerimeterConfigurationIssueSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkSecurityPerimeterConfigurationIssueSeverity(input string) (*NetworkSecurityPerimeterConfigurationIssueSeverity, error) { + vals := map[string]NetworkSecurityPerimeterConfigurationIssueSeverity{ + "error": NetworkSecurityPerimeterConfigurationIssueSeverityError, + "warning": NetworkSecurityPerimeterConfigurationIssueSeverityWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkSecurityPerimeterConfigurationIssueSeverity(input) + return &out, nil +} + +type NetworkSecurityPerimeterConfigurationIssueType string + +const ( + NetworkSecurityPerimeterConfigurationIssueTypeConfigurationPropagationFailure NetworkSecurityPerimeterConfigurationIssueType = "ConfigurationPropagationFailure" + NetworkSecurityPerimeterConfigurationIssueTypeMissingIdentityConfiguration NetworkSecurityPerimeterConfigurationIssueType = "MissingIdentityConfiguration" + NetworkSecurityPerimeterConfigurationIssueTypeMissingPerimeterConfiguration NetworkSecurityPerimeterConfigurationIssueType = "MissingPerimeterConfiguration" + NetworkSecurityPerimeterConfigurationIssueTypeOther NetworkSecurityPerimeterConfigurationIssueType = "Other" +) + +func PossibleValuesForNetworkSecurityPerimeterConfigurationIssueType() []string { + return []string{ + string(NetworkSecurityPerimeterConfigurationIssueTypeConfigurationPropagationFailure), + string(NetworkSecurityPerimeterConfigurationIssueTypeMissingIdentityConfiguration), + string(NetworkSecurityPerimeterConfigurationIssueTypeMissingPerimeterConfiguration), + string(NetworkSecurityPerimeterConfigurationIssueTypeOther), + } +} + +func (s *NetworkSecurityPerimeterConfigurationIssueType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkSecurityPerimeterConfigurationIssueType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkSecurityPerimeterConfigurationIssueType(input string) (*NetworkSecurityPerimeterConfigurationIssueType, error) { + vals := map[string]NetworkSecurityPerimeterConfigurationIssueType{ + "configurationpropagationfailure": NetworkSecurityPerimeterConfigurationIssueTypeConfigurationPropagationFailure, + "missingidentityconfiguration": NetworkSecurityPerimeterConfigurationIssueTypeMissingIdentityConfiguration, + "missingperimeterconfiguration": NetworkSecurityPerimeterConfigurationIssueTypeMissingPerimeterConfiguration, + "other": NetworkSecurityPerimeterConfigurationIssueTypeOther, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkSecurityPerimeterConfigurationIssueType(input) + return &out, nil +} + +type NetworkSecurityPerimeterProfileAccessRuleDirection string + +const ( + NetworkSecurityPerimeterProfileAccessRuleDirectionInbound NetworkSecurityPerimeterProfileAccessRuleDirection = "Inbound" + NetworkSecurityPerimeterProfileAccessRuleDirectionOutbound NetworkSecurityPerimeterProfileAccessRuleDirection = "Outbound" +) + +func PossibleValuesForNetworkSecurityPerimeterProfileAccessRuleDirection() []string { + return []string{ + string(NetworkSecurityPerimeterProfileAccessRuleDirectionInbound), + string(NetworkSecurityPerimeterProfileAccessRuleDirectionOutbound), + } +} + +func (s *NetworkSecurityPerimeterProfileAccessRuleDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkSecurityPerimeterProfileAccessRuleDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkSecurityPerimeterProfileAccessRuleDirection(input string) (*NetworkSecurityPerimeterProfileAccessRuleDirection, error) { + vals := map[string]NetworkSecurityPerimeterProfileAccessRuleDirection{ + "inbound": NetworkSecurityPerimeterProfileAccessRuleDirectionInbound, + "outbound": NetworkSecurityPerimeterProfileAccessRuleDirectionOutbound, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkSecurityPerimeterProfileAccessRuleDirection(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/id_scopednetworksecurityperimeterconfiguration.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/id_scopednetworksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..73594e378f4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/id_scopednetworksecurityperimeterconfiguration.go @@ -0,0 +1,113 @@ +package perimeterassociationproxies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedNetworkSecurityPerimeterConfigurationId{} + +// ScopedNetworkSecurityPerimeterConfigurationId is a struct representing the Resource ID for a Scoped Network Security Perimeter Configuration +type ScopedNetworkSecurityPerimeterConfigurationId struct { + Scope string + NetworkSecurityPerimeterConfigurationName string +} + +// NewScopedNetworkSecurityPerimeterConfigurationID returns a new ScopedNetworkSecurityPerimeterConfigurationId struct +func NewScopedNetworkSecurityPerimeterConfigurationID(scope string, networkSecurityPerimeterConfigurationName string) ScopedNetworkSecurityPerimeterConfigurationId { + return ScopedNetworkSecurityPerimeterConfigurationId{ + Scope: scope, + NetworkSecurityPerimeterConfigurationName: networkSecurityPerimeterConfigurationName, + } +} + +// ParseScopedNetworkSecurityPerimeterConfigurationID parses 'input' into a ScopedNetworkSecurityPerimeterConfigurationId +func ParseScopedNetworkSecurityPerimeterConfigurationID(input string) (*ScopedNetworkSecurityPerimeterConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedNetworkSecurityPerimeterConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedNetworkSecurityPerimeterConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedNetworkSecurityPerimeterConfigurationIDInsensitively parses 'input' case-insensitively into a ScopedNetworkSecurityPerimeterConfigurationId +// note: this method should only be used for API response data and not user input +func ParseScopedNetworkSecurityPerimeterConfigurationIDInsensitively(input string) (*ScopedNetworkSecurityPerimeterConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedNetworkSecurityPerimeterConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedNetworkSecurityPerimeterConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedNetworkSecurityPerimeterConfigurationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.NetworkSecurityPerimeterConfigurationName, ok = input.Parsed["networkSecurityPerimeterConfigurationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "networkSecurityPerimeterConfigurationName", input) + } + + return nil +} + +// ValidateScopedNetworkSecurityPerimeterConfigurationID checks that 'input' can be parsed as a Scoped Network Security Perimeter Configuration ID +func ValidateScopedNetworkSecurityPerimeterConfigurationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedNetworkSecurityPerimeterConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Network Security Perimeter Configuration ID +func (id ScopedNetworkSecurityPerimeterConfigurationId) ID() string { + fmtString := "/%s/networkSecurityPerimeterConfigurations/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.NetworkSecurityPerimeterConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Network Security Perimeter Configuration ID +func (id ScopedNetworkSecurityPerimeterConfigurationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticNetworkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations"), + resourceids.UserSpecifiedSegment("networkSecurityPerimeterConfigurationName", "networkSecurityPerimeterConfigurationValue"), + } +} + +// String returns a human-readable description of this Scoped Network Security Perimeter Configuration ID +func (id ScopedNetworkSecurityPerimeterConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Network Security Perimeter Configuration Name: %q", id.NetworkSecurityPerimeterConfigurationName), + } + return fmt.Sprintf("Scoped Network Security Perimeter Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/id_scopednetworksecurityperimeterconfiguration_test.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/id_scopednetworksecurityperimeterconfiguration_test.go new file mode 100644 index 00000000000..92d892d99ff --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/id_scopednetworksecurityperimeterconfiguration_test.go @@ -0,0 +1,192 @@ +package perimeterassociationproxies + +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 = &ScopedNetworkSecurityPerimeterConfigurationId{} + +func TestNewScopedNetworkSecurityPerimeterConfigurationID(t *testing.T) { + id := NewScopedNetworkSecurityPerimeterConfigurationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "networkSecurityPerimeterConfigurationValue") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.NetworkSecurityPerimeterConfigurationName != "networkSecurityPerimeterConfigurationValue" { + t.Fatalf("Expected %q but got %q for Segment 'NetworkSecurityPerimeterConfigurationName'", id.NetworkSecurityPerimeterConfigurationName, "networkSecurityPerimeterConfigurationValue") + } +} + +func TestFormatScopedNetworkSecurityPerimeterConfigurationID(t *testing.T) { + actual := NewScopedNetworkSecurityPerimeterConfigurationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "networkSecurityPerimeterConfigurationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedNetworkSecurityPerimeterConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedNetworkSecurityPerimeterConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/networkSecurityPerimeterConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue", + Expected: &ScopedNetworkSecurityPerimeterConfigurationId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedNetworkSecurityPerimeterConfigurationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.NetworkSecurityPerimeterConfigurationName != v.Expected.NetworkSecurityPerimeterConfigurationName { + t.Fatalf("Expected %q but got %q for NetworkSecurityPerimeterConfigurationName", v.Expected.NetworkSecurityPerimeterConfigurationName, actual.NetworkSecurityPerimeterConfigurationName) + } + + } +} + +func TestParseScopedNetworkSecurityPerimeterConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedNetworkSecurityPerimeterConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/networkSecurityPerimeterConfigurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue", + Expected: &ScopedNetworkSecurityPerimeterConfigurationId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnVaLuE", + Expected: &ScopedNetworkSecurityPerimeterConfigurationId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + NetworkSecurityPerimeterConfigurationName: "nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedNetworkSecurityPerimeterConfigurationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.NetworkSecurityPerimeterConfigurationName != v.Expected.NetworkSecurityPerimeterConfigurationName { + t.Fatalf("Expected %q but got %q for NetworkSecurityPerimeterConfigurationName", v.Expected.NetworkSecurityPerimeterConfigurationName, actual.NetworkSecurityPerimeterConfigurationName) + } + + } +} + +func TestSegmentsForScopedNetworkSecurityPerimeterConfigurationId(t *testing.T) { + segments := ScopedNetworkSecurityPerimeterConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedNetworkSecurityPerimeterConfigurationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationsget.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationsget.go new file mode 100644 index 00000000000..6a4a4fc8f60 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationsget.go @@ -0,0 +1,54 @@ +package perimeterassociationproxies + +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 NetworkSecurityPerimeterConfigurationsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NetworkSecurityPerimeterConfiguration +} + +// NetworkSecurityPerimeterConfigurationsGet ... +func (c PerimeterAssociationProxiesClient) NetworkSecurityPerimeterConfigurationsGet(ctx context.Context, id ScopedNetworkSecurityPerimeterConfigurationId) (result NetworkSecurityPerimeterConfigurationsGetOperationResponse, 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 NetworkSecurityPerimeterConfiguration + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationslist.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationslist.go new file mode 100644 index 00000000000..bc8caa94d22 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationslist.go @@ -0,0 +1,92 @@ +package perimeterassociationproxies + +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 NetworkSecurityPerimeterConfigurationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NetworkSecurityPerimeterConfiguration +} + +type NetworkSecurityPerimeterConfigurationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []NetworkSecurityPerimeterConfiguration +} + +// NetworkSecurityPerimeterConfigurationsList ... +func (c PerimeterAssociationProxiesClient) NetworkSecurityPerimeterConfigurationsList(ctx context.Context, id commonids.ScopeId) (result NetworkSecurityPerimeterConfigurationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/networkSecurityPerimeterConfigurations", 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 *[]NetworkSecurityPerimeterConfiguration `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// NetworkSecurityPerimeterConfigurationsListComplete retrieves all the results into a single object +func (c PerimeterAssociationProxiesClient) NetworkSecurityPerimeterConfigurationsListComplete(ctx context.Context, id commonids.ScopeId) (NetworkSecurityPerimeterConfigurationsListCompleteResult, error) { + return c.NetworkSecurityPerimeterConfigurationsListCompleteMatchingPredicate(ctx, id, NetworkSecurityPerimeterConfigurationOperationPredicate{}) +} + +// NetworkSecurityPerimeterConfigurationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PerimeterAssociationProxiesClient) NetworkSecurityPerimeterConfigurationsListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, predicate NetworkSecurityPerimeterConfigurationOperationPredicate) (result NetworkSecurityPerimeterConfigurationsListCompleteResult, err error) { + items := make([]NetworkSecurityPerimeterConfiguration, 0) + + resp, err := c.NetworkSecurityPerimeterConfigurationsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = NetworkSecurityPerimeterConfigurationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationsreconcile.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationsreconcile.go new file mode 100644 index 00000000000..8ace0db78a0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/method_networksecurityperimeterconfigurationsreconcile.go @@ -0,0 +1,71 @@ +package perimeterassociationproxies + +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 NetworkSecurityPerimeterConfigurationsReconcileOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NetworkSecurityPerimeterConfiguration +} + +// NetworkSecurityPerimeterConfigurationsReconcile ... +func (c PerimeterAssociationProxiesClient) NetworkSecurityPerimeterConfigurationsReconcile(ctx context.Context, id ScopedNetworkSecurityPerimeterConfigurationId) (result NetworkSecurityPerimeterConfigurationsReconcileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/reconcile", 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 +} + +// NetworkSecurityPerimeterConfigurationsReconcileThenPoll performs NetworkSecurityPerimeterConfigurationsReconcile then polls until it's completed +func (c PerimeterAssociationProxiesClient) NetworkSecurityPerimeterConfigurationsReconcileThenPoll(ctx context.Context, id ScopedNetworkSecurityPerimeterConfigurationId) error { + result, err := c.NetworkSecurityPerimeterConfigurationsReconcile(ctx, id) + if err != nil { + return fmt.Errorf("performing NetworkSecurityPerimeterConfigurationsReconcile: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after NetworkSecurityPerimeterConfigurationsReconcile: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfiguration.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..8be18c01d34 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfiguration.go @@ -0,0 +1,11 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfiguration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkSecurityPerimeterConfigurationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationissues.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationissues.go new file mode 100644 index 00000000000..fd580d78de5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationissues.go @@ -0,0 +1,9 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationIssues struct { + Name *string `json:"name,omitempty"` + Properties *NetworkSecurityPerimeterConfigurationIssuesProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationissuesproperties.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationissuesproperties.go new file mode 100644 index 00000000000..6a3f0b2cacf --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationissuesproperties.go @@ -0,0 +1,12 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationIssuesProperties struct { + Description *string `json:"description,omitempty"` + IssueType *NetworkSecurityPerimeterConfigurationIssueType `json:"issueType,omitempty"` + Severity *NetworkSecurityPerimeterConfigurationIssueSeverity `json:"severity,omitempty"` + SuggestedAccessRules *[]string `json:"suggestedAccessRules,omitempty"` + SuggestedResourceIds *[]string `json:"suggestedResourceIds,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationprofile.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationprofile.go new file mode 100644 index 00000000000..b73738f33a8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationprofile.go @@ -0,0 +1,12 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationProfile struct { + AccessRules *[]NetworkSecurityPerimeterProfileAccessRule `json:"accessRules,omitempty"` + AccessRulesVersion *string `json:"accessRulesVersion,omitempty"` + DiagnosticSettingsVersion *string `json:"diagnosticSettingsVersion,omitempty"` + EnabledLogCategories *[]string `json:"enabledLogCategories,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationproperties.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationproperties.go new file mode 100644 index 00000000000..2d1aeab79a3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterconfigurationproperties.go @@ -0,0 +1,12 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationProperties struct { + NetworkSecurityPerimeter *NetworkSecurityPerimeterInfo `json:"networkSecurityPerimeter,omitempty"` + Profile *NetworkSecurityPerimeterConfigurationProfile `json:"profile,omitempty"` + ProvisioningIssues *[]NetworkSecurityPerimeterConfigurationIssues `json:"provisioningIssues,omitempty"` + ProvisioningState *NetworkSecurityPerimeterConfigProvisioningState `json:"provisioningState,omitempty"` + ResourceAssociation *ResourceAssociation `json:"resourceAssociation,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterinfo.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterinfo.go new file mode 100644 index 00000000000..cf841ebd625 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterinfo.go @@ -0,0 +1,10 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterInfo struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + PerimeterGuid *string `json:"perimeterGuid,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterprofileaccessrule.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterprofileaccessrule.go new file mode 100644 index 00000000000..e72aa771327 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterprofileaccessrule.go @@ -0,0 +1,11 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterProfileAccessRule struct { + FullyQualifiedArmId *string `json:"fullyQualifiedArmId,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkSecurityPerimeterProfileAccessRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterprofileaccessruleproperties.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterprofileaccessruleproperties.go new file mode 100644 index 00000000000..45df1ac4e14 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_networksecurityperimeterprofileaccessruleproperties.go @@ -0,0 +1,14 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterProfileAccessRuleProperties struct { + AddressPrefixes *[]string `json:"addressPrefixes,omitempty"` + Direction *NetworkSecurityPerimeterProfileAccessRuleDirection `json:"direction,omitempty"` + EmailAddresses *[]string `json:"emailAddresses,omitempty"` + FullyQualifiedDomainNames *[]string `json:"fullyQualifiedDomainNames,omitempty"` + NetworkSecurityPerimeters *[]NetworkSecurityPerimeterInfo `json:"networkSecurityPerimeters,omitempty"` + PhoneNumbers *[]string `json:"phoneNumbers,omitempty"` + Subscriptions *[]string `json:"subscriptions,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_resourceassociation.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_resourceassociation.go new file mode 100644 index 00000000000..9f0f0a5bf67 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/model_resourceassociation.go @@ -0,0 +1,9 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceAssociation struct { + AccessMode *NetworkSecurityPerimeterAssociationAccessMode `json:"accessMode,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/predicates.go new file mode 100644 index 00000000000..b95aa851fa8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/predicates.go @@ -0,0 +1,27 @@ +package perimeterassociationproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p NetworkSecurityPerimeterConfigurationOperationPredicate) Matches(input NetworkSecurityPerimeterConfiguration) 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/eventgrid/2023-12-15-preview/perimeterassociationproxies/version.go b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/version.go new file mode 100644 index 00000000000..c864f886c02 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/perimeterassociationproxies/version.go @@ -0,0 +1,12 @@ +package perimeterassociationproxies + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/perimeterassociationproxies/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/README.md b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/README.md new file mode 100644 index 00000000000..414f76bd704 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/permissionbindings` Documentation + +The `permissionbindings` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/permissionbindings" +``` + + +### Client Initialization + +```go +client := permissionbindings.NewPermissionBindingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PermissionBindingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := permissionbindings.NewPermissionBindingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "permissionBindingValue") + +payload := permissionbindings.PermissionBinding{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PermissionBindingsClient.Delete` + +```go +ctx := context.TODO() +id := permissionbindings.NewPermissionBindingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "permissionBindingValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PermissionBindingsClient.Get` + +```go +ctx := context.TODO() +id := permissionbindings.NewPermissionBindingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "permissionBindingValue") + +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: `PermissionBindingsClient.ListByNamespace` + +```go +ctx := context.TODO() +id := permissionbindings.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +// alternatively `client.ListByNamespace(ctx, id, permissionbindings.DefaultListByNamespaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByNamespaceComplete(ctx, id, permissionbindings.DefaultListByNamespaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/client.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/client.go new file mode 100644 index 00000000000..6c642fa4881 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/client.go @@ -0,0 +1,26 @@ +package permissionbindings + +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 PermissionBindingsClient struct { + Client *resourcemanager.Client +} + +func NewPermissionBindingsClientWithBaseURI(sdkApi sdkEnv.Api) (*PermissionBindingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "permissionbindings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PermissionBindingsClient: %+v", err) + } + + return &PermissionBindingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/constants.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/constants.go new file mode 100644 index 00000000000..0d8ab0053c8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/constants.go @@ -0,0 +1,107 @@ +package permissionbindings + +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 PermissionBindingProvisioningState string + +const ( + PermissionBindingProvisioningStateCanceled PermissionBindingProvisioningState = "Canceled" + PermissionBindingProvisioningStateCreating PermissionBindingProvisioningState = "Creating" + PermissionBindingProvisioningStateDeleted PermissionBindingProvisioningState = "Deleted" + PermissionBindingProvisioningStateDeleting PermissionBindingProvisioningState = "Deleting" + PermissionBindingProvisioningStateFailed PermissionBindingProvisioningState = "Failed" + PermissionBindingProvisioningStateSucceeded PermissionBindingProvisioningState = "Succeeded" + PermissionBindingProvisioningStateUpdating PermissionBindingProvisioningState = "Updating" +) + +func PossibleValuesForPermissionBindingProvisioningState() []string { + return []string{ + string(PermissionBindingProvisioningStateCanceled), + string(PermissionBindingProvisioningStateCreating), + string(PermissionBindingProvisioningStateDeleted), + string(PermissionBindingProvisioningStateDeleting), + string(PermissionBindingProvisioningStateFailed), + string(PermissionBindingProvisioningStateSucceeded), + string(PermissionBindingProvisioningStateUpdating), + } +} + +func (s *PermissionBindingProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePermissionBindingProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePermissionBindingProvisioningState(input string) (*PermissionBindingProvisioningState, error) { + vals := map[string]PermissionBindingProvisioningState{ + "canceled": PermissionBindingProvisioningStateCanceled, + "creating": PermissionBindingProvisioningStateCreating, + "deleted": PermissionBindingProvisioningStateDeleted, + "deleting": PermissionBindingProvisioningStateDeleting, + "failed": PermissionBindingProvisioningStateFailed, + "succeeded": PermissionBindingProvisioningStateSucceeded, + "updating": PermissionBindingProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PermissionBindingProvisioningState(input) + return &out, nil +} + +type PermissionType string + +const ( + PermissionTypePublisher PermissionType = "Publisher" + PermissionTypeSubscriber PermissionType = "Subscriber" +) + +func PossibleValuesForPermissionType() []string { + return []string{ + string(PermissionTypePublisher), + string(PermissionTypeSubscriber), + } +} + +func (s *PermissionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePermissionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePermissionType(input string) (*PermissionType, error) { + vals := map[string]PermissionType{ + "publisher": PermissionTypePublisher, + "subscriber": PermissionTypeSubscriber, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PermissionType(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_namespace.go new file mode 100644 index 00000000000..643f067e1ad --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_namespace.go @@ -0,0 +1,125 @@ +package permissionbindings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceId{} + +// NamespaceId is a struct representing the Resource ID for a Namespace +type NamespaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string +} + +// NewNamespaceID returns a new NamespaceId struct +func NewNamespaceID(subscriptionId string, resourceGroupName string, namespaceName string) NamespaceId { + return NamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + } +} + +// ParseNamespaceID parses 'input' into a NamespaceId +func ParseNamespaceID(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceIDInsensitively parses 'input' case-insensitively into a NamespaceId +// note: this method should only be used for API response data and not user input +func ParseNamespaceIDInsensitively(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + return nil +} + +// ValidateNamespaceID checks that 'input' can be parsed as a Namespace ID +func ValidateNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace ID +func (id NamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace ID +func (id NamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + } +} + +// String returns a human-readable description of this Namespace ID +func (id NamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + } + return fmt.Sprintf("Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_namespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_namespace_test.go new file mode 100644 index 00000000000..488c31b701a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_namespace_test.go @@ -0,0 +1,282 @@ +package permissionbindings + +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 = &NamespaceId{} + +func TestNewNamespaceID(t *testing.T) { + id := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } +} + +func TestFormatNamespaceID(t *testing.T) { + actual := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestParseNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestSegmentsForNamespaceId(t *testing.T) { + segments := NamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_permissionbinding.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_permissionbinding.go new file mode 100644 index 00000000000..b06593aac96 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_permissionbinding.go @@ -0,0 +1,134 @@ +package permissionbindings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PermissionBindingId{} + +// PermissionBindingId is a struct representing the Resource ID for a Permission Binding +type PermissionBindingId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + PermissionBindingName string +} + +// NewPermissionBindingID returns a new PermissionBindingId struct +func NewPermissionBindingID(subscriptionId string, resourceGroupName string, namespaceName string, permissionBindingName string) PermissionBindingId { + return PermissionBindingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + PermissionBindingName: permissionBindingName, + } +} + +// ParsePermissionBindingID parses 'input' into a PermissionBindingId +func ParsePermissionBindingID(input string) (*PermissionBindingId, error) { + parser := resourceids.NewParserFromResourceIdType(&PermissionBindingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PermissionBindingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePermissionBindingIDInsensitively parses 'input' case-insensitively into a PermissionBindingId +// note: this method should only be used for API response data and not user input +func ParsePermissionBindingIDInsensitively(input string) (*PermissionBindingId, error) { + parser := resourceids.NewParserFromResourceIdType(&PermissionBindingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PermissionBindingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PermissionBindingId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.PermissionBindingName, ok = input.Parsed["permissionBindingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "permissionBindingName", input) + } + + return nil +} + +// ValidatePermissionBindingID checks that 'input' can be parsed as a Permission Binding ID +func ValidatePermissionBindingID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePermissionBindingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Permission Binding ID +func (id PermissionBindingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/permissionBindings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.PermissionBindingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Permission Binding ID +func (id PermissionBindingId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticPermissionBindings", "permissionBindings", "permissionBindings"), + resourceids.UserSpecifiedSegment("permissionBindingName", "permissionBindingValue"), + } +} + +// String returns a human-readable description of this Permission Binding ID +func (id PermissionBindingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Permission Binding Name: %q", id.PermissionBindingName), + } + return fmt.Sprintf("Permission Binding (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_permissionbinding_test.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_permissionbinding_test.go new file mode 100644 index 00000000000..e8cfcde0e4f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/id_permissionbinding_test.go @@ -0,0 +1,327 @@ +package permissionbindings + +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 = &PermissionBindingId{} + +func TestNewPermissionBindingID(t *testing.T) { + id := NewPermissionBindingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "permissionBindingValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.PermissionBindingName != "permissionBindingValue" { + t.Fatalf("Expected %q but got %q for Segment 'PermissionBindingName'", id.PermissionBindingName, "permissionBindingValue") + } +} + +func TestFormatPermissionBindingID(t *testing.T) { + actual := NewPermissionBindingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "permissionBindingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/permissionBindings/permissionBindingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePermissionBindingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PermissionBindingId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/permissionBindings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/permissionBindings/permissionBindingValue", + Expected: &PermissionBindingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + PermissionBindingName: "permissionBindingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/permissionBindings/permissionBindingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePermissionBindingID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.PermissionBindingName != v.Expected.PermissionBindingName { + t.Fatalf("Expected %q but got %q for PermissionBindingName", v.Expected.PermissionBindingName, actual.PermissionBindingName) + } + + } +} + +func TestParsePermissionBindingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PermissionBindingId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/permissionBindings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/pErMiSsIoNbInDiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/permissionBindings/permissionBindingValue", + Expected: &PermissionBindingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + PermissionBindingName: "permissionBindingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/permissionBindings/permissionBindingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/pErMiSsIoNbInDiNgS/pErMiSsIoNbInDiNgVaLuE", + Expected: &PermissionBindingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + PermissionBindingName: "pErMiSsIoNbInDiNgVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/pErMiSsIoNbInDiNgS/pErMiSsIoNbInDiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePermissionBindingIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.PermissionBindingName != v.Expected.PermissionBindingName { + t.Fatalf("Expected %q but got %q for PermissionBindingName", v.Expected.PermissionBindingName, actual.PermissionBindingName) + } + + } +} + +func TestSegmentsForPermissionBindingId(t *testing.T) { + segments := PermissionBindingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PermissionBindingId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_createorupdate.go new file mode 100644 index 00000000000..f6055f3829e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_createorupdate.go @@ -0,0 +1,75 @@ +package permissionbindings + +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 *PermissionBinding +} + +// CreateOrUpdate ... +func (c PermissionBindingsClient) CreateOrUpdate(ctx context.Context, id PermissionBindingId, input PermissionBinding) (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 PermissionBindingsClient) CreateOrUpdateThenPoll(ctx context.Context, id PermissionBindingId, input PermissionBinding) 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/eventgrid/2023-12-15-preview/permissionbindings/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_delete.go new file mode 100644 index 00000000000..2e772cb87f3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_delete.go @@ -0,0 +1,71 @@ +package permissionbindings + +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 PermissionBindingsClient) Delete(ctx context.Context, id PermissionBindingId) (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 PermissionBindingsClient) DeleteThenPoll(ctx context.Context, id PermissionBindingId) 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/eventgrid/2023-12-15-preview/permissionbindings/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_get.go new file mode 100644 index 00000000000..66d5cca6474 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_get.go @@ -0,0 +1,54 @@ +package permissionbindings + +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 *PermissionBinding +} + +// Get ... +func (c PermissionBindingsClient) Get(ctx context.Context, id PermissionBindingId) (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 PermissionBinding + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_listbynamespace.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_listbynamespace.go new file mode 100644 index 00000000000..0c3da76a1e8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/method_listbynamespace.go @@ -0,0 +1,123 @@ +package permissionbindings + +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 ListByNamespaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PermissionBinding +} + +type ListByNamespaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PermissionBinding +} + +type ListByNamespaceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByNamespaceOperationOptions() ListByNamespaceOperationOptions { + return ListByNamespaceOperationOptions{} +} + +func (o ListByNamespaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByNamespaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByNamespaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByNamespace ... +func (c PermissionBindingsClient) ListByNamespace(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (result ListByNamespaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/permissionBindings", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PermissionBinding `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNamespaceComplete retrieves all the results into a single object +func (c PermissionBindingsClient) ListByNamespaceComplete(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (ListByNamespaceCompleteResult, error) { + return c.ListByNamespaceCompleteMatchingPredicate(ctx, id, options, PermissionBindingOperationPredicate{}) +} + +// ListByNamespaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PermissionBindingsClient) ListByNamespaceCompleteMatchingPredicate(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions, predicate PermissionBindingOperationPredicate) (result ListByNamespaceCompleteResult, err error) { + items := make([]PermissionBinding, 0) + + resp, err := c.ListByNamespace(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNamespaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/model_permissionbinding.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/model_permissionbinding.go new file mode 100644 index 00000000000..c8fe5d6ea1b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/model_permissionbinding.go @@ -0,0 +1,16 @@ +package permissionbindings + +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 PermissionBinding struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PermissionBindingProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/model_permissionbindingproperties.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/model_permissionbindingproperties.go new file mode 100644 index 00000000000..776325a8cb8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/model_permissionbindingproperties.go @@ -0,0 +1,12 @@ +package permissionbindings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PermissionBindingProperties struct { + ClientGroupName *string `json:"clientGroupName,omitempty"` + Description *string `json:"description,omitempty"` + Permission *PermissionType `json:"permission,omitempty"` + ProvisioningState *PermissionBindingProvisioningState `json:"provisioningState,omitempty"` + TopicSpaceName *string `json:"topicSpaceName,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/predicates.go new file mode 100644 index 00000000000..91c15215995 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/predicates.go @@ -0,0 +1,27 @@ +package permissionbindings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PermissionBindingOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PermissionBindingOperationPredicate) Matches(input PermissionBinding) 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/eventgrid/2023-12-15-preview/permissionbindings/version.go b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/version.go new file mode 100644 index 00000000000..4dea80f3f57 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/permissionbindings/version.go @@ -0,0 +1,12 @@ +package permissionbindings + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/permissionbindings/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/README.md b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/README.md new file mode 100644 index 00000000000..8c1dea11856 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewScopedPrivateEndpointConnectionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "privateEndpointConnectionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewScopedPrivateEndpointConnectionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "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.ListByResource` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListByResource(ctx, id, privateendpointconnections.DefaultListByResourceOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceComplete(ctx, id, privateendpointconnections.DefaultListByResourceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Update` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewScopedPrivateEndpointConnectionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "privateEndpointConnectionValue") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/client.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/client.go new file mode 100644 index 00000000000..3bf7a6afe1f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/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/eventgrid/2023-12-15-preview/privateendpointconnections/constants.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/constants.go new file mode 100644 index 00000000000..d2006bdf1a1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/constants.go @@ -0,0 +1,110 @@ +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 PersistedConnectionStatus string + +const ( + PersistedConnectionStatusApproved PersistedConnectionStatus = "Approved" + PersistedConnectionStatusDisconnected PersistedConnectionStatus = "Disconnected" + PersistedConnectionStatusPending PersistedConnectionStatus = "Pending" + PersistedConnectionStatusRejected PersistedConnectionStatus = "Rejected" +) + +func PossibleValuesForPersistedConnectionStatus() []string { + return []string{ + string(PersistedConnectionStatusApproved), + string(PersistedConnectionStatusDisconnected), + string(PersistedConnectionStatusPending), + string(PersistedConnectionStatusRejected), + } +} + +func (s *PersistedConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePersistedConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePersistedConnectionStatus(input string) (*PersistedConnectionStatus, error) { + vals := map[string]PersistedConnectionStatus{ + "approved": PersistedConnectionStatusApproved, + "disconnected": PersistedConnectionStatusDisconnected, + "pending": PersistedConnectionStatusPending, + "rejected": PersistedConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersistedConnectionStatus(input) + return &out, nil +} + +type ResourceProvisioningState string + +const ( + ResourceProvisioningStateCanceled ResourceProvisioningState = "Canceled" + ResourceProvisioningStateCreating ResourceProvisioningState = "Creating" + ResourceProvisioningStateDeleting ResourceProvisioningState = "Deleting" + ResourceProvisioningStateFailed ResourceProvisioningState = "Failed" + ResourceProvisioningStateSucceeded ResourceProvisioningState = "Succeeded" + ResourceProvisioningStateUpdating ResourceProvisioningState = "Updating" +) + +func PossibleValuesForResourceProvisioningState() []string { + return []string{ + string(ResourceProvisioningStateCanceled), + string(ResourceProvisioningStateCreating), + string(ResourceProvisioningStateDeleting), + string(ResourceProvisioningStateFailed), + string(ResourceProvisioningStateSucceeded), + string(ResourceProvisioningStateUpdating), + } +} + +func (s *ResourceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceProvisioningState(input string) (*ResourceProvisioningState, error) { + vals := map[string]ResourceProvisioningState{ + "canceled": ResourceProvisioningStateCanceled, + "creating": ResourceProvisioningStateCreating, + "deleting": ResourceProvisioningStateDeleting, + "failed": ResourceProvisioningStateFailed, + "succeeded": ResourceProvisioningStateSucceeded, + "updating": ResourceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/id_scopedprivateendpointconnection.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/id_scopedprivateendpointconnection.go new file mode 100644 index 00000000000..6c9d3c1d001 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/id_scopedprivateendpointconnection.go @@ -0,0 +1,113 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedPrivateEndpointConnectionId{} + +// ScopedPrivateEndpointConnectionId is a struct representing the Resource ID for a Scoped Private Endpoint Connection +type ScopedPrivateEndpointConnectionId struct { + Scope string + PrivateEndpointConnectionName string +} + +// NewScopedPrivateEndpointConnectionID returns a new ScopedPrivateEndpointConnectionId struct +func NewScopedPrivateEndpointConnectionID(scope string, privateEndpointConnectionName string) ScopedPrivateEndpointConnectionId { + return ScopedPrivateEndpointConnectionId{ + Scope: scope, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParseScopedPrivateEndpointConnectionID parses 'input' into a ScopedPrivateEndpointConnectionId +func ParseScopedPrivateEndpointConnectionID(input string) (*ScopedPrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedPrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedPrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedPrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a ScopedPrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParseScopedPrivateEndpointConnectionIDInsensitively(input string) (*ScopedPrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedPrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedPrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedPrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidateScopedPrivateEndpointConnectionID checks that 'input' can be parsed as a Scoped Private Endpoint Connection ID +func ValidateScopedPrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedPrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Private Endpoint Connection ID +func (id ScopedPrivateEndpointConnectionId) ID() string { + fmtString := "/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Private Endpoint Connection ID +func (id ScopedPrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Scoped Private Endpoint Connection ID +func (id ScopedPrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Scoped Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/id_scopedprivateendpointconnection_test.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/id_scopedprivateendpointconnection_test.go new file mode 100644 index 00000000000..381f3b19461 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/id_scopedprivateendpointconnection_test.go @@ -0,0 +1,192 @@ +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 = &ScopedPrivateEndpointConnectionId{} + +func TestNewScopedPrivateEndpointConnectionID(t *testing.T) { + id := NewScopedPrivateEndpointConnectionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "privateEndpointConnectionValue") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatScopedPrivateEndpointConnectionID(t *testing.T) { + actual := NewScopedPrivateEndpointConnectionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedPrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedPrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &ScopedPrivateEndpointConnectionId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedPrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParseScopedPrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedPrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &ScopedPrivateEndpointConnectionId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &ScopedPrivateEndpointConnectionId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedPrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForScopedPrivateEndpointConnectionId(t *testing.T) { + segments := ScopedPrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedPrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..6e73eb7534f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/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 ScopedPrivateEndpointConnectionId) (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 ScopedPrivateEndpointConnectionId) 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/eventgrid/2023-12-15-preview/privateendpointconnections/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..09cecb3eae5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/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 *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id ScopedPrivateEndpointConnectionId) (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 PrivateEndpointConnection + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_listbyresource.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_listbyresource.go new file mode 100644 index 00000000000..94b5763159c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_listbyresource.go @@ -0,0 +1,124 @@ +package privateendpointconnections + +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 ListByResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type ListByResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnection +} + +type ListByResourceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceOperationOptions() ListByResourceOperationOptions { + return ListByResourceOperationOptions{} +} + +func (o ListByResourceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResource ... +func (c PrivateEndpointConnectionsClient) ListByResource(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions) (result ListByResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) ListByResourceComplete(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions) (ListByResourceCompleteResult, error) { + return c.ListByResourceCompleteMatchingPredicate(ctx, id, options, PrivateEndpointConnectionOperationPredicate{}) +} + +// ListByResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) ListByResourceCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions, predicate PrivateEndpointConnectionOperationPredicate) (result ListByResourceCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.ListByResource(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_update.go new file mode 100644 index 00000000000..985956b0d2e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/method_update.go @@ -0,0 +1,75 @@ +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 UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Update ... +func (c PrivateEndpointConnectionsClient) Update(ctx context.Context, id ScopedPrivateEndpointConnectionId, input PrivateEndpointConnection) (result UpdateOperationResponse, 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 +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c PrivateEndpointConnectionsClient) UpdateThenPoll(ctx context.Context, id ScopedPrivateEndpointConnectionId, input PrivateEndpointConnection) 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/eventgrid/2023-12-15-preview/privateendpointconnections/model_connectionstate.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_connectionstate.go new file mode 100644 index 00000000000..11c7bacadc5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_connectionstate.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 ConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PersistedConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_privateendpoint.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/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/eventgrid/2023-12-15-preview/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_privateendpointconnection.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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..68b962d6f88 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/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 *ConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ResourceProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..4a03a91ce52 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/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 PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/version.go b/resource-manager/eventgrid/2023-12-15-preview/privateendpointconnections/version.go new file mode 100644 index 00000000000..462164e10b7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/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 = "2023-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/README.md b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/README.md new file mode 100644 index 00000000000..3a30c557b39 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.Get` + +```go +ctx := context.TODO() +id := privatelinkresources.NewScopedPrivateLinkResourceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "privateLinkResourceValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkResourcesClient.ListByResource` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListByResource(ctx, id, privatelinkresources.DefaultListByResourceOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceComplete(ctx, id, privatelinkresources.DefaultListByResourceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/client.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/client.go new file mode 100644 index 00000000000..e6e22caa746 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +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 PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/id_scopedprivatelinkresource.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/id_scopedprivatelinkresource.go new file mode 100644 index 00000000000..e9e7707a9ee --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/id_scopedprivatelinkresource.go @@ -0,0 +1,113 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedPrivateLinkResourceId{} + +// ScopedPrivateLinkResourceId is a struct representing the Resource ID for a Scoped Private Link Resource +type ScopedPrivateLinkResourceId struct { + Scope string + PrivateLinkResourceName string +} + +// NewScopedPrivateLinkResourceID returns a new ScopedPrivateLinkResourceId struct +func NewScopedPrivateLinkResourceID(scope string, privateLinkResourceName string) ScopedPrivateLinkResourceId { + return ScopedPrivateLinkResourceId{ + Scope: scope, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParseScopedPrivateLinkResourceID parses 'input' into a ScopedPrivateLinkResourceId +func ParseScopedPrivateLinkResourceID(input string) (*ScopedPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedPrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedPrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a ScopedPrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParseScopedPrivateLinkResourceIDInsensitively(input string) (*ScopedPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedPrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedPrivateLinkResourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidateScopedPrivateLinkResourceID checks that 'input' can be parsed as a Scoped Private Link Resource ID +func ValidateScopedPrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedPrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Private Link Resource ID +func (id ScopedPrivateLinkResourceId) ID() string { + fmtString := "/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Private Link Resource ID +func (id ScopedPrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceValue"), + } +} + +// String returns a human-readable description of this Scoped Private Link Resource ID +func (id ScopedPrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Scoped Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/id_scopedprivatelinkresource_test.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/id_scopedprivatelinkresource_test.go new file mode 100644 index 00000000000..cc1fad1b8d8 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/id_scopedprivatelinkresource_test.go @@ -0,0 +1,192 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedPrivateLinkResourceId{} + +func TestNewScopedPrivateLinkResourceID(t *testing.T) { + id := NewScopedPrivateLinkResourceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "privateLinkResourceValue") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.PrivateLinkResourceName != "privateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceValue") + } +} + +func TestFormatScopedPrivateLinkResourceID(t *testing.T) { + actual := NewScopedPrivateLinkResourceID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "privateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateLinkResources/privateLinkResourceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedPrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedPrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateLinkResources/privateLinkResourceValue", + Expected: &ScopedPrivateLinkResourceId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedPrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParseScopedPrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedPrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateLinkResources/privateLinkResourceValue", + Expected: &ScopedPrivateLinkResourceId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE", + Expected: &ScopedPrivateLinkResourceId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedPrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForScopedPrivateLinkResourceId(t *testing.T) { + segments := ScopedPrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedPrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/method_get.go new file mode 100644 index 00000000000..3bd66c97190 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/method_get.go @@ -0,0 +1,54 @@ +package privatelinkresources + +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 *PrivateLinkResource +} + +// Get ... +func (c PrivateLinkResourcesClient) Get(ctx context.Context, id ScopedPrivateLinkResourceId) (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 PrivateLinkResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/method_listbyresource.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/method_listbyresource.go new file mode 100644 index 00000000000..aba3a25ce1d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/method_listbyresource.go @@ -0,0 +1,124 @@ +package privatelinkresources + +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 ListByResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListByResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +type ListByResourceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceOperationOptions() ListByResourceOperationOptions { + return ListByResourceOperationOptions{} +} + +func (o ListByResourceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResource ... +func (c PrivateLinkResourcesClient) ListByResource(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions) (result ListByResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceComplete retrieves all the results into a single object +func (c PrivateLinkResourcesClient) ListByResourceComplete(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions) (ListByResourceCompleteResult, error) { + return c.ListByResourceCompleteMatchingPredicate(ctx, id, options, PrivateLinkResourceOperationPredicate{}) +} + +// ListByResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkResourcesClient) ListByResourceCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListByResourceOperationOptions, predicate PrivateLinkResourceOperationPredicate) (result ListByResourceCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.ListByResource(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/model_privatelinkresource.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..b20a6aab034 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + DisplayName *string `json:"displayName,omitempty"` + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/predicates.go new file mode 100644 index 00000000000..19b771c3994 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/predicates.go @@ -0,0 +1,27 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type 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/eventgrid/2023-12-15-preview/privatelinkresources/version.go b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/version.go new file mode 100644 index 00000000000..b6396226d74 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/privatelinkresources/version.go @@ -0,0 +1,12 @@ +package privatelinkresources + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkresources/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/README.md b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/README.md new file mode 100644 index 00000000000..d399cf2ec9c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/systemtopics` Documentation + +The `systemtopics` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/systemtopics" +``` + + +### Client Initialization + +```go +client := systemtopics.NewSystemTopicsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SystemTopicsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := systemtopics.NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue") + +payload := systemtopics.SystemTopic{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SystemTopicsClient.Delete` + +```go +ctx := context.TODO() +id := systemtopics.NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SystemTopicsClient.Get` + +```go +ctx := context.TODO() +id := systemtopics.NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue") + +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: `SystemTopicsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, systemtopics.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, systemtopics.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SystemTopicsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, systemtopics.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, systemtopics.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SystemTopicsClient.Update` + +```go +ctx := context.TODO() +id := systemtopics.NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue") + +payload := systemtopics.SystemTopicUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/client.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/client.go new file mode 100644 index 00000000000..a75eb998451 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/client.go @@ -0,0 +1,26 @@ +package systemtopics + +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 SystemTopicsClient struct { + Client *resourcemanager.Client +} + +func NewSystemTopicsClientWithBaseURI(sdkApi sdkEnv.Api) (*SystemTopicsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "systemtopics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SystemTopicsClient: %+v", err) + } + + return &SystemTopicsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/constants.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/constants.go new file mode 100644 index 00000000000..ac0276c3511 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/constants.go @@ -0,0 +1,63 @@ +package systemtopics + +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 ResourceProvisioningState string + +const ( + ResourceProvisioningStateCanceled ResourceProvisioningState = "Canceled" + ResourceProvisioningStateCreating ResourceProvisioningState = "Creating" + ResourceProvisioningStateDeleting ResourceProvisioningState = "Deleting" + ResourceProvisioningStateFailed ResourceProvisioningState = "Failed" + ResourceProvisioningStateSucceeded ResourceProvisioningState = "Succeeded" + ResourceProvisioningStateUpdating ResourceProvisioningState = "Updating" +) + +func PossibleValuesForResourceProvisioningState() []string { + return []string{ + string(ResourceProvisioningStateCanceled), + string(ResourceProvisioningStateCreating), + string(ResourceProvisioningStateDeleting), + string(ResourceProvisioningStateFailed), + string(ResourceProvisioningStateSucceeded), + string(ResourceProvisioningStateUpdating), + } +} + +func (s *ResourceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceProvisioningState(input string) (*ResourceProvisioningState, error) { + vals := map[string]ResourceProvisioningState{ + "canceled": ResourceProvisioningStateCanceled, + "creating": ResourceProvisioningStateCreating, + "deleting": ResourceProvisioningStateDeleting, + "failed": ResourceProvisioningStateFailed, + "succeeded": ResourceProvisioningStateSucceeded, + "updating": ResourceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/id_systemtopic.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/id_systemtopic.go new file mode 100644 index 00000000000..30eeb9f97c9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/id_systemtopic.go @@ -0,0 +1,125 @@ +package systemtopics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SystemTopicId{} + +// SystemTopicId is a struct representing the Resource ID for a System Topic +type SystemTopicId struct { + SubscriptionId string + ResourceGroupName string + SystemTopicName string +} + +// NewSystemTopicID returns a new SystemTopicId struct +func NewSystemTopicID(subscriptionId string, resourceGroupName string, systemTopicName string) SystemTopicId { + return SystemTopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SystemTopicName: systemTopicName, + } +} + +// ParseSystemTopicID parses 'input' into a SystemTopicId +func ParseSystemTopicID(input string) (*SystemTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&SystemTopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SystemTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSystemTopicIDInsensitively parses 'input' case-insensitively into a SystemTopicId +// note: this method should only be used for API response data and not user input +func ParseSystemTopicIDInsensitively(input string) (*SystemTopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&SystemTopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SystemTopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SystemTopicId) 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.SystemTopicName, ok = input.Parsed["systemTopicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "systemTopicName", input) + } + + return nil +} + +// ValidateSystemTopicID checks that 'input' can be parsed as a System Topic ID +func ValidateSystemTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSystemTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted System Topic ID +func (id SystemTopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/systemTopics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SystemTopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this System Topic ID +func (id SystemTopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticSystemTopics", "systemTopics", "systemTopics"), + resourceids.UserSpecifiedSegment("systemTopicName", "systemTopicValue"), + } +} + +// String returns a human-readable description of this System Topic ID +func (id SystemTopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("System Topic Name: %q", id.SystemTopicName), + } + return fmt.Sprintf("System Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/id_systemtopic_test.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/id_systemtopic_test.go new file mode 100644 index 00000000000..526e50a2caa --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/id_systemtopic_test.go @@ -0,0 +1,282 @@ +package systemtopics + +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 = &SystemTopicId{} + +func TestNewSystemTopicID(t *testing.T) { + id := NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue") + + if id.SubscriptionId != "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.SystemTopicName != "systemTopicValue" { + t.Fatalf("Expected %q but got %q for Segment 'SystemTopicName'", id.SystemTopicName, "systemTopicValue") + } +} + +func TestFormatSystemTopicID(t *testing.T) { + actual := NewSystemTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "systemTopicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSystemTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SystemTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue", + Expected: &SystemTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SystemTopicName: "systemTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSystemTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SystemTopicName != v.Expected.SystemTopicName { + t.Fatalf("Expected %q but got %q for SystemTopicName", v.Expected.SystemTopicName, actual.SystemTopicName) + } + + } +} + +func TestParseSystemTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SystemTopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue", + Expected: &SystemTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SystemTopicName: "systemTopicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/systemTopics/systemTopicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE", + Expected: &SystemTopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SystemTopicName: "sYsTeMtOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/sYsTeMtOpIcS/sYsTeMtOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSystemTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SystemTopicName != v.Expected.SystemTopicName { + t.Fatalf("Expected %q but got %q for SystemTopicName", v.Expected.SystemTopicName, actual.SystemTopicName) + } + + } +} + +func TestSegmentsForSystemTopicId(t *testing.T) { + segments := SystemTopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SystemTopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_createorupdate.go new file mode 100644 index 00000000000..2d11681bf50 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_createorupdate.go @@ -0,0 +1,75 @@ +package systemtopics + +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 *SystemTopic +} + +// CreateOrUpdate ... +func (c SystemTopicsClient) CreateOrUpdate(ctx context.Context, id SystemTopicId, input SystemTopic) (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 SystemTopicsClient) CreateOrUpdateThenPoll(ctx context.Context, id SystemTopicId, input SystemTopic) 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/eventgrid/2023-12-15-preview/systemtopics/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_delete.go new file mode 100644 index 00000000000..366d4294f1a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_delete.go @@ -0,0 +1,71 @@ +package systemtopics + +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 SystemTopicsClient) Delete(ctx context.Context, id SystemTopicId) (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 SystemTopicsClient) DeleteThenPoll(ctx context.Context, id SystemTopicId) 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/eventgrid/2023-12-15-preview/systemtopics/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_get.go new file mode 100644 index 00000000000..a8da6a2fc6a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_get.go @@ -0,0 +1,54 @@ +package systemtopics + +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 *SystemTopic +} + +// Get ... +func (c SystemTopicsClient) Get(ctx context.Context, id SystemTopicId) (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 SystemTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_listbyresourcegroup.go new file mode 100644 index 00000000000..c465920b477 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package systemtopics + +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 *[]SystemTopic +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []SystemTopic +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c SystemTopicsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/systemTopics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SystemTopic `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 SystemTopicsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, SystemTopicOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SystemTopicsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate SystemTopicOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]SystemTopic, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_listbysubscription.go new file mode 100644 index 00000000000..8dc0523c9a1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_listbysubscription.go @@ -0,0 +1,124 @@ +package systemtopics + +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 *[]SystemTopic +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []SystemTopic +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c SystemTopicsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/systemTopics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SystemTopic `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 SystemTopicsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, SystemTopicOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SystemTopicsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate SystemTopicOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]SystemTopic, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_update.go new file mode 100644 index 00000000000..cf564a6e5f0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/method_update.go @@ -0,0 +1,75 @@ +package systemtopics + +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 *SystemTopic +} + +// Update ... +func (c SystemTopicsClient) Update(ctx context.Context, id SystemTopicId, input SystemTopicUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + 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 SystemTopicsClient) UpdateThenPoll(ctx context.Context, id SystemTopicId, input SystemTopicUpdateParameters) 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/eventgrid/2023-12-15-preview/systemtopics/model_systemtopic.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/model_systemtopic.go new file mode 100644 index 00000000000..fbc2b113077 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/model_systemtopic.go @@ -0,0 +1,20 @@ +package systemtopics + +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 SystemTopic struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *SystemTopicProperties `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/eventgrid/2023-12-15-preview/systemtopics/model_systemtopicproperties.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/model_systemtopicproperties.go new file mode 100644 index 00000000000..edcdf8cccab --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/model_systemtopicproperties.go @@ -0,0 +1,11 @@ +package systemtopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SystemTopicProperties struct { + MetricResourceId *string `json:"metricResourceId,omitempty"` + ProvisioningState *ResourceProvisioningState `json:"provisioningState,omitempty"` + Source *string `json:"source,omitempty"` + TopicType *string `json:"topicType,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/model_systemtopicupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/model_systemtopicupdateparameters.go new file mode 100644 index 00000000000..57eed8f94f7 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/model_systemtopicupdateparameters.go @@ -0,0 +1,13 @@ +package systemtopics + +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 SystemTopicUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/systemtopics/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/predicates.go new file mode 100644 index 00000000000..eb50601c4f2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/predicates.go @@ -0,0 +1,32 @@ +package systemtopics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SystemTopicOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SystemTopicOperationPredicate) Matches(input SystemTopic) 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/eventgrid/2023-12-15-preview/systemtopics/version.go b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/version.go new file mode 100644 index 00000000000..d4a157ba6a9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/systemtopics/version.go @@ -0,0 +1,12 @@ +package systemtopics + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/systemtopics/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/README.md b/resource-manager/eventgrid/2023-12-15-preview/topics/README.md new file mode 100644 index 00000000000..73563205e7f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/README.md @@ -0,0 +1,182 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/topics` Documentation + +The `topics` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/topics" +``` + + +### Client Initialization + +```go +client := topics.NewTopicsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TopicsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := topics.NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + +payload := topics.Topic{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TopicsClient.Delete` + +```go +ctx := context.TODO() +id := topics.NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TopicsClient.ExtensionTopicsGet` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.ExtensionTopicsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TopicsClient.Get` + +```go +ctx := context.TODO() +id := topics.NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + +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: `TopicsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, topics.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, topics.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TopicsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, topics.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, topics.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TopicsClient.ListEventTypes` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.ListEventTypes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TopicsClient.ListSharedAccessKeys` + +```go +ctx := context.TODO() +id := topics.NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + +read, err := client.ListSharedAccessKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TopicsClient.RegenerateKey` + +```go +ctx := context.TODO() +id := topics.NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + +payload := topics.TopicRegenerateKeyRequest{ + // ... +} + + +if err := client.RegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TopicsClient.Update` + +```go +ctx := context.TODO() +id := topics.NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + +payload := topics.TopicUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/client.go b/resource-manager/eventgrid/2023-12-15-preview/topics/client.go new file mode 100644 index 00000000000..0e7b8385566 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/client.go @@ -0,0 +1,26 @@ +package topics + +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 TopicsClient struct { + Client *resourcemanager.Client +} + +func NewTopicsClientWithBaseURI(sdkApi sdkEnv.Api) (*TopicsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "topics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TopicsClient: %+v", err) + } + + return &TopicsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/constants.go b/resource-manager/eventgrid/2023-12-15-preview/topics/constants.go new file mode 100644 index 00000000000..b5c6910e0b2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/constants.go @@ -0,0 +1,532 @@ +package topics + +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 DataResidencyBoundary string + +const ( + DataResidencyBoundaryWithinGeopair DataResidencyBoundary = "WithinGeopair" + DataResidencyBoundaryWithinRegion DataResidencyBoundary = "WithinRegion" +) + +func PossibleValuesForDataResidencyBoundary() []string { + return []string{ + string(DataResidencyBoundaryWithinGeopair), + string(DataResidencyBoundaryWithinRegion), + } +} + +func (s *DataResidencyBoundary) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataResidencyBoundary(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataResidencyBoundary(input string) (*DataResidencyBoundary, error) { + vals := map[string]DataResidencyBoundary{ + "withingeopair": DataResidencyBoundaryWithinGeopair, + "withinregion": DataResidencyBoundaryWithinRegion, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataResidencyBoundary(input) + return &out, nil +} + +type EventDefinitionKind string + +const ( + EventDefinitionKindInline EventDefinitionKind = "Inline" +) + +func PossibleValuesForEventDefinitionKind() []string { + return []string{ + string(EventDefinitionKindInline), + } +} + +func (s *EventDefinitionKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventDefinitionKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventDefinitionKind(input string) (*EventDefinitionKind, error) { + vals := map[string]EventDefinitionKind{ + "inline": EventDefinitionKindInline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventDefinitionKind(input) + return &out, nil +} + +type IPActionType string + +const ( + IPActionTypeAllow IPActionType = "Allow" +) + +func PossibleValuesForIPActionType() []string { + return []string{ + string(IPActionTypeAllow), + } +} + +func (s *IPActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIPActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIPActionType(input string) (*IPActionType, error) { + vals := map[string]IPActionType{ + "allow": IPActionTypeAllow, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPActionType(input) + return &out, nil +} + +type InputSchema string + +const ( + InputSchemaCloudEventSchemaVOneZero InputSchema = "CloudEventSchemaV1_0" + InputSchemaCustomEventSchema InputSchema = "CustomEventSchema" + InputSchemaEventGridSchema InputSchema = "EventGridSchema" +) + +func PossibleValuesForInputSchema() []string { + return []string{ + string(InputSchemaCloudEventSchemaVOneZero), + string(InputSchemaCustomEventSchema), + string(InputSchemaEventGridSchema), + } +} + +func (s *InputSchema) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInputSchema(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInputSchema(input string) (*InputSchema, error) { + vals := map[string]InputSchema{ + "cloudeventschemav1_0": InputSchemaCloudEventSchemaVOneZero, + "customeventschema": InputSchemaCustomEventSchema, + "eventgridschema": InputSchemaEventGridSchema, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InputSchema(input) + return &out, nil +} + +type InputSchemaMappingType string + +const ( + InputSchemaMappingTypeJson InputSchemaMappingType = "Json" +) + +func PossibleValuesForInputSchemaMappingType() []string { + return []string{ + string(InputSchemaMappingTypeJson), + } +} + +func (s *InputSchemaMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInputSchemaMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInputSchemaMappingType(input string) (*InputSchemaMappingType, error) { + vals := map[string]InputSchemaMappingType{ + "json": InputSchemaMappingTypeJson, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InputSchemaMappingType(input) + return &out, nil +} + +type PersistedConnectionStatus string + +const ( + PersistedConnectionStatusApproved PersistedConnectionStatus = "Approved" + PersistedConnectionStatusDisconnected PersistedConnectionStatus = "Disconnected" + PersistedConnectionStatusPending PersistedConnectionStatus = "Pending" + PersistedConnectionStatusRejected PersistedConnectionStatus = "Rejected" +) + +func PossibleValuesForPersistedConnectionStatus() []string { + return []string{ + string(PersistedConnectionStatusApproved), + string(PersistedConnectionStatusDisconnected), + string(PersistedConnectionStatusPending), + string(PersistedConnectionStatusRejected), + } +} + +func (s *PersistedConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePersistedConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePersistedConnectionStatus(input string) (*PersistedConnectionStatus, error) { + vals := map[string]PersistedConnectionStatus{ + "approved": PersistedConnectionStatusApproved, + "disconnected": PersistedConnectionStatusDisconnected, + "pending": PersistedConnectionStatusPending, + "rejected": PersistedConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersistedConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" + PublicNetworkAccessSecuredByPerimeter PublicNetworkAccess = "SecuredByPerimeter" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + string(PublicNetworkAccessSecuredByPerimeter), + } +} + +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, + "securedbyperimeter": PublicNetworkAccessSecuredByPerimeter, + } + 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 ResourceKind string + +const ( + ResourceKindAzure ResourceKind = "Azure" + ResourceKindAzureArc ResourceKind = "AzureArc" +) + +func PossibleValuesForResourceKind() []string { + return []string{ + string(ResourceKindAzure), + string(ResourceKindAzureArc), + } +} + +func (s *ResourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceKind(input string) (*ResourceKind, error) { + vals := map[string]ResourceKind{ + "azure": ResourceKindAzure, + "azurearc": ResourceKindAzureArc, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceKind(input) + return &out, nil +} + +type ResourceProvisioningState string + +const ( + ResourceProvisioningStateCanceled ResourceProvisioningState = "Canceled" + ResourceProvisioningStateCreating ResourceProvisioningState = "Creating" + ResourceProvisioningStateDeleting ResourceProvisioningState = "Deleting" + ResourceProvisioningStateFailed ResourceProvisioningState = "Failed" + ResourceProvisioningStateSucceeded ResourceProvisioningState = "Succeeded" + ResourceProvisioningStateUpdating ResourceProvisioningState = "Updating" +) + +func PossibleValuesForResourceProvisioningState() []string { + return []string{ + string(ResourceProvisioningStateCanceled), + string(ResourceProvisioningStateCreating), + string(ResourceProvisioningStateDeleting), + string(ResourceProvisioningStateFailed), + string(ResourceProvisioningStateSucceeded), + string(ResourceProvisioningStateUpdating), + } +} + +func (s *ResourceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceProvisioningState(input string) (*ResourceProvisioningState, error) { + vals := map[string]ResourceProvisioningState{ + "canceled": ResourceProvisioningStateCanceled, + "creating": ResourceProvisioningStateCreating, + "deleting": ResourceProvisioningStateDeleting, + "failed": ResourceProvisioningStateFailed, + "succeeded": ResourceProvisioningStateSucceeded, + "updating": ResourceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceProvisioningState(input) + return &out, nil +} + +type Sku string + +const ( + SkuBasic Sku = "Basic" + SkuPremium Sku = "Premium" +) + +func PossibleValuesForSku() []string { + return []string{ + string(SkuBasic), + string(SkuPremium), + } +} + +func (s *Sku) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSku(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSku(input string) (*Sku, error) { + vals := map[string]Sku{ + "basic": SkuBasic, + "premium": SkuPremium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Sku(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} + +type TopicProvisioningState string + +const ( + TopicProvisioningStateCanceled TopicProvisioningState = "Canceled" + TopicProvisioningStateCreating TopicProvisioningState = "Creating" + TopicProvisioningStateDeleting TopicProvisioningState = "Deleting" + TopicProvisioningStateFailed TopicProvisioningState = "Failed" + TopicProvisioningStateSucceeded TopicProvisioningState = "Succeeded" + TopicProvisioningStateUpdating TopicProvisioningState = "Updating" +) + +func PossibleValuesForTopicProvisioningState() []string { + return []string{ + string(TopicProvisioningStateCanceled), + string(TopicProvisioningStateCreating), + string(TopicProvisioningStateDeleting), + string(TopicProvisioningStateFailed), + string(TopicProvisioningStateSucceeded), + string(TopicProvisioningStateUpdating), + } +} + +func (s *TopicProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTopicProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTopicProvisioningState(input string) (*TopicProvisioningState, error) { + vals := map[string]TopicProvisioningState{ + "canceled": TopicProvisioningStateCanceled, + "creating": TopicProvisioningStateCreating, + "deleting": TopicProvisioningStateDeleting, + "failed": TopicProvisioningStateFailed, + "succeeded": TopicProvisioningStateSucceeded, + "updating": TopicProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TopicProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/id_topic.go b/resource-manager/eventgrid/2023-12-15-preview/topics/id_topic.go new file mode 100644 index 00000000000..dad5195535a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/id_topic.go @@ -0,0 +1,125 @@ +package topics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TopicId{} + +// TopicId is a struct representing the Resource ID for a Topic +type TopicId struct { + SubscriptionId string + ResourceGroupName string + TopicName string +} + +// NewTopicID returns a new TopicId struct +func NewTopicID(subscriptionId string, resourceGroupName string, topicName string) TopicId { + return TopicId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TopicName: topicName, + } +} + +// ParseTopicID parses 'input' into a TopicId +func ParseTopicID(input string) (*TopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTopicIDInsensitively parses 'input' case-insensitively into a TopicId +// note: this method should only be used for API response data and not user input +func ParseTopicIDInsensitively(input string) (*TopicId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TopicId) 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.TopicName, ok = input.Parsed["topicName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicName", input) + } + + return nil +} + +// ValidateTopicID checks that 'input' can be parsed as a Topic ID +func ValidateTopicID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTopicID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Topic ID +func (id TopicId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/topics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TopicName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Topic ID +func (id TopicId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticTopics", "topics", "topics"), + resourceids.UserSpecifiedSegment("topicName", "topicValue"), + } +} + +// String returns a human-readable description of this Topic ID +func (id TopicId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Topic Name: %q", id.TopicName), + } + return fmt.Sprintf("Topic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/id_topic_test.go b/resource-manager/eventgrid/2023-12-15-preview/topics/id_topic_test.go new file mode 100644 index 00000000000..c7bcbe2fec5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/id_topic_test.go @@ -0,0 +1,282 @@ +package topics + +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 = &TopicId{} + +func TestNewTopicID(t *testing.T) { + id := NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue") + + if id.SubscriptionId != "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.TopicName != "topicValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicName'", id.TopicName, "topicValue") + } +} + +func TestFormatTopicID(t *testing.T) { + actual := NewTopicID("12345678-1234-9876-4563-123456789012", "example-resource-group", "topicValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTopicID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue", + Expected: &TopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestParseTopicIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue", + Expected: &TopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TopicName: "topicValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/topics/topicValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcS/tOpIcVaLuE", + Expected: &TopicId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TopicName: "tOpIcVaLuE", + }, + }, + { + // 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.eVeNtGrId/tOpIcS/tOpIcVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TopicName != v.Expected.TopicName { + t.Fatalf("Expected %q but got %q for TopicName", v.Expected.TopicName, actual.TopicName) + } + + } +} + +func TestSegmentsForTopicId(t *testing.T) { + segments := TopicId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TopicId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_createorupdate.go new file mode 100644 index 00000000000..7a16629b531 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_createorupdate.go @@ -0,0 +1,74 @@ +package topics + +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 *Topic +} + +// CreateOrUpdate ... +func (c TopicsClient) CreateOrUpdate(ctx context.Context, id TopicId, input Topic) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c TopicsClient) CreateOrUpdateThenPoll(ctx context.Context, id TopicId, input Topic) 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/eventgrid/2023-12-15-preview/topics/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_delete.go new file mode 100644 index 00000000000..01fa4ce5fea --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_delete.go @@ -0,0 +1,70 @@ +package topics + +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 TopicsClient) Delete(ctx context.Context, id TopicId) (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 TopicsClient) DeleteThenPoll(ctx context.Context, id TopicId) 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/eventgrid/2023-12-15-preview/topics/method_extensiontopicsget.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_extensiontopicsget.go new file mode 100644 index 00000000000..e56b3e7ed5a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_extensiontopicsget.go @@ -0,0 +1,56 @@ +package topics + +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 ExtensionTopicsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtensionTopic +} + +// ExtensionTopicsGet ... +func (c TopicsClient) ExtensionTopicsGet(ctx context.Context, id commonids.ScopeId) (result ExtensionTopicsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/extensionTopics/default", 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 ExtensionTopic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_get.go new file mode 100644 index 00000000000..a276dae1132 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_get.go @@ -0,0 +1,54 @@ +package topics + +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 *Topic +} + +// Get ... +func (c TopicsClient) Get(ctx context.Context, id TopicId) (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 Topic + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_listbyresourcegroup.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listbyresourcegroup.go new file mode 100644 index 00000000000..fe5bbaf590b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listbyresourcegroup.go @@ -0,0 +1,124 @@ +package topics + +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 *[]Topic +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Topic +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c TopicsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/topics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Topic `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 TopicsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, TopicOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TopicsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate TopicOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Topic, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_listbysubscription.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listbysubscription.go new file mode 100644 index 00000000000..940e84ef1d3 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listbysubscription.go @@ -0,0 +1,124 @@ +package topics + +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 *[]Topic +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Topic +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c TopicsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/topics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Topic `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 TopicsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, TopicOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TopicsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate TopicOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Topic, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_listeventtypes.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listeventtypes.go new file mode 100644 index 00000000000..9ad02baea36 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listeventtypes.go @@ -0,0 +1,56 @@ +package topics + +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 ListEventTypesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventTypesListResult +} + +// ListEventTypes ... +func (c TopicsClient) ListEventTypes(ctx context.Context, id commonids.ScopeId) (result ListEventTypesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.EventGrid/eventTypes", 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 EventTypesListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_listsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listsharedaccesskeys.go new file mode 100644 index 00000000000..926e9ba1256 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_listsharedaccesskeys.go @@ -0,0 +1,55 @@ +package topics + +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 ListSharedAccessKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TopicSharedAccessKeys +} + +// ListSharedAccessKeys ... +func (c TopicsClient) ListSharedAccessKeys(ctx context.Context, id TopicId) (result ListSharedAccessKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TopicSharedAccessKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_regeneratekey.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_regeneratekey.go new file mode 100644 index 00000000000..d696f3b4d78 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_regeneratekey.go @@ -0,0 +1,75 @@ +package topics + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TopicSharedAccessKeys +} + +// RegenerateKey ... +func (c TopicsClient) RegenerateKey(ctx context.Context, id TopicId, input TopicRegenerateKeyRequest) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RegenerateKeyThenPoll performs RegenerateKey then polls until it's completed +func (c TopicsClient) RegenerateKeyThenPoll(ctx context.Context, id TopicId, input TopicRegenerateKeyRequest) error { + result, err := c.RegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/method_update.go b/resource-manager/eventgrid/2023-12-15-preview/topics/method_update.go new file mode 100644 index 00000000000..1a3ab1b3614 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/method_update.go @@ -0,0 +1,75 @@ +package topics + +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 *Topic +} + +// Update ... +func (c TopicsClient) Update(ctx context.Context, id TopicId, input TopicUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + 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 TopicsClient) UpdateThenPoll(ctx context.Context, id TopicId, input TopicUpdateParameters) 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/eventgrid/2023-12-15-preview/topics/model_connectionstate.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_connectionstate.go new file mode 100644 index 00000000000..3c621c81ea0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_connectionstate.go @@ -0,0 +1,10 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PersistedConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtype.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtype.go new file mode 100644 index 00000000000..54190c81913 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtype.go @@ -0,0 +1,11 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventType struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EventTypeProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeinfo.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeinfo.go new file mode 100644 index 00000000000..b5002895133 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeinfo.go @@ -0,0 +1,9 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypeInfo struct { + InlineEventTypes *map[string]InlineEventProperties `json:"inlineEventTypes,omitempty"` + Kind *EventDefinitionKind `json:"kind,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeproperties.go new file mode 100644 index 00000000000..d670b27156a --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeproperties.go @@ -0,0 +1,11 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypeProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + IsInDefaultSet *bool `json:"isInDefaultSet,omitempty"` + SchemaUrl *string `json:"schemaUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeslistresult.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeslistresult.go new file mode 100644 index 00000000000..36bb2b12861 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_eventtypeslistresult.go @@ -0,0 +1,8 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypesListResult struct { + Value *[]EventType `json:"value,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_extendedlocation.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_extendedlocation.go new file mode 100644 index 00000000000..4164ab9bb34 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_extendedlocation.go @@ -0,0 +1,9 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_extensiontopic.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_extensiontopic.go new file mode 100644 index 00000000000..a2a2665995f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_extensiontopic.go @@ -0,0 +1,16 @@ +package topics + +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 ExtensionTopic struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtensionTopicProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_extensiontopicproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_extensiontopicproperties.go new file mode 100644 index 00000000000..97f338f2a0e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_extensiontopicproperties.go @@ -0,0 +1,9 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionTopicProperties struct { + Description *string `json:"description,omitempty"` + SystemTopic *string `json:"systemTopic,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_inboundiprule.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_inboundiprule.go new file mode 100644 index 00000000000..c314f7abe80 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_inboundiprule.go @@ -0,0 +1,9 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InboundIPRule struct { + Action *IPActionType `json:"action,omitempty"` + IPMask *string `json:"ipMask,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_inlineeventproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_inlineeventproperties.go new file mode 100644 index 00000000000..ccd709dcb50 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_inlineeventproperties.go @@ -0,0 +1,11 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InlineEventProperties struct { + DataSchemaUrl *string `json:"dataSchemaUrl,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + DocumentationUrl *string `json:"documentationUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_inputschemamapping.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_inputschemamapping.go new file mode 100644 index 00000000000..ea5cba6d2c9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_inputschemamapping.go @@ -0,0 +1,53 @@ +package topics + +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 InputSchemaMapping interface { +} + +// RawInputSchemaMappingImpl 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 RawInputSchemaMappingImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalInputSchemaMappingImplementation(input []byte) (InputSchemaMapping, 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 InputSchemaMapping into map[string]interface: %+v", err) + } + + value, ok := temp["inputSchemaMappingType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Json") { + var out JsonInputSchemaMapping + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into JsonInputSchemaMapping: %+v", err) + } + return out, nil + } + + out := RawInputSchemaMappingImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsonfield.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsonfield.go new file mode 100644 index 00000000000..4ec54b2c930 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsonfield.go @@ -0,0 +1,8 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JsonField struct { + SourceField *string `json:"sourceField,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsonfieldwithdefault.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsonfieldwithdefault.go new file mode 100644 index 00000000000..23e6f15a161 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsonfieldwithdefault.go @@ -0,0 +1,9 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JsonFieldWithDefault struct { + DefaultValue *string `json:"defaultValue,omitempty"` + SourceField *string `json:"sourceField,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsoninputschemamapping.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsoninputschemamapping.go new file mode 100644 index 00000000000..84c4a558344 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsoninputschemamapping.go @@ -0,0 +1,41 @@ +package topics + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ InputSchemaMapping = JsonInputSchemaMapping{} + +type JsonInputSchemaMapping struct { + Properties *JsonInputSchemaMappingProperties `json:"properties,omitempty"` + + // Fields inherited from InputSchemaMapping +} + +var _ json.Marshaler = JsonInputSchemaMapping{} + +func (s JsonInputSchemaMapping) MarshalJSON() ([]byte, error) { + type wrapper JsonInputSchemaMapping + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling JsonInputSchemaMapping: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling JsonInputSchemaMapping: %+v", err) + } + decoded["inputSchemaMappingType"] = "Json" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling JsonInputSchemaMapping: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsoninputschemamappingproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsoninputschemamappingproperties.go new file mode 100644 index 00000000000..fb23803ba7c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_jsoninputschemamappingproperties.go @@ -0,0 +1,13 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JsonInputSchemaMappingProperties struct { + DataVersion *JsonFieldWithDefault `json:"dataVersion,omitempty"` + EventTime *JsonField `json:"eventTime,omitempty"` + EventType *JsonFieldWithDefault `json:"eventType,omitempty"` + Id *JsonField `json:"id,omitempty"` + Subject *JsonFieldWithDefault `json:"subject,omitempty"` + Topic *JsonField `json:"topic,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpoint.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpoint.go new file mode 100644 index 00000000000..008a7149844 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpoint.go @@ -0,0 +1,8 @@ +package topics + +// 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/eventgrid/2023-12-15-preview/topics/model_privateendpointconnection.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpointconnection.go new file mode 100644 index 00000000000..bff383a250e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpointconnectionproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..d2e8c75ad1f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package topics + +// 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 *ConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ResourceProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_resourcesku.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_resourcesku.go new file mode 100644 index 00000000000..242421f4a33 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_resourcesku.go @@ -0,0 +1,8 @@ +package topics + +// 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 { + Name *Sku `json:"name,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_topic.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topic.go new file mode 100644 index 00000000000..c3845aa44f2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topic.go @@ -0,0 +1,23 @@ +package topics + +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 Topic struct { + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *ResourceKind `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *TopicProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicproperties.go new file mode 100644 index 00000000000..7a10bb88bc5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicproperties.go @@ -0,0 +1,60 @@ +package topics + +import ( + "encoding/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 TopicProperties struct { + DataResidencyBoundary *DataResidencyBoundary `json:"dataResidencyBoundary,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + Endpoint *string `json:"endpoint,omitempty"` + EventTypeInfo *EventTypeInfo `json:"eventTypeInfo,omitempty"` + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + InputSchema *InputSchema `json:"inputSchema,omitempty"` + InputSchemaMapping InputSchemaMapping `json:"inputSchemaMapping"` + MetricResourceId *string `json:"metricResourceId,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *TopicProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} + +var _ json.Unmarshaler = &TopicProperties{} + +func (s *TopicProperties) UnmarshalJSON(bytes []byte) error { + type alias TopicProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into TopicProperties: %+v", err) + } + + s.DataResidencyBoundary = decoded.DataResidencyBoundary + s.DisableLocalAuth = decoded.DisableLocalAuth + s.Endpoint = decoded.Endpoint + s.EventTypeInfo = decoded.EventTypeInfo + s.InboundIPRules = decoded.InboundIPRules + s.InputSchema = decoded.InputSchema + s.MetricResourceId = decoded.MetricResourceId + s.MinimumTlsVersionAllowed = decoded.MinimumTlsVersionAllowed + s.PrivateEndpointConnections = decoded.PrivateEndpointConnections + s.ProvisioningState = decoded.ProvisioningState + s.PublicNetworkAccess = decoded.PublicNetworkAccess + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TopicProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["inputSchemaMapping"]; ok { + impl, err := unmarshalInputSchemaMappingImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'InputSchemaMapping' for 'TopicProperties': %+v", err) + } + s.InputSchemaMapping = impl + } + return nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicregeneratekeyrequest.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicregeneratekeyrequest.go new file mode 100644 index 00000000000..a79e0c7dcdc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicregeneratekeyrequest.go @@ -0,0 +1,8 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicRegenerateKeyRequest struct { + KeyName string `json:"keyName"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicsharedaccesskeys.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicsharedaccesskeys.go new file mode 100644 index 00000000000..703619022a6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicsharedaccesskeys.go @@ -0,0 +1,9 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicSharedAccessKeys struct { + Key1 *string `json:"key1,omitempty"` + Key2 *string `json:"key2,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicupdateparameterproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicupdateparameterproperties.go new file mode 100644 index 00000000000..89a0ef796b6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicupdateparameterproperties.go @@ -0,0 +1,13 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicUpdateParameterProperties struct { + DataResidencyBoundary *DataResidencyBoundary `json:"dataResidencyBoundary,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + EventTypeInfo *EventTypeInfo `json:"eventTypeInfo,omitempty"` + InboundIPRules *[]InboundIPRule `json:"inboundIpRules,omitempty"` + MinimumTlsVersionAllowed *TlsVersion `json:"minimumTlsVersionAllowed,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicupdateparameters.go b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicupdateparameters.go new file mode 100644 index 00000000000..692841e876d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/model_topicupdateparameters.go @@ -0,0 +1,15 @@ +package topics + +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 TopicUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *TopicUpdateParameterProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topics/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/topics/predicates.go new file mode 100644 index 00000000000..da916d64e3d --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/predicates.go @@ -0,0 +1,32 @@ +package topics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p TopicOperationPredicate) Matches(input Topic) 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/eventgrid/2023-12-15-preview/topics/version.go b/resource-manager/eventgrid/2023-12-15-preview/topics/version.go new file mode 100644 index 00000000000..9b7cc1878fc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topics/version.go @@ -0,0 +1,12 @@ +package topics + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/topics/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/README.md b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/README.md new file mode 100644 index 00000000000..1edbf769435 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/topicspaces` Documentation + +The `topicspaces` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/topicspaces" +``` + + +### Client Initialization + +```go +client := topicspaces.NewTopicSpacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TopicSpacesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := topicspaces.NewTopicSpaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicSpaceValue") + +payload := topicspaces.TopicSpace{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TopicSpacesClient.Delete` + +```go +ctx := context.TODO() +id := topicspaces.NewTopicSpaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicSpaceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TopicSpacesClient.Get` + +```go +ctx := context.TODO() +id := topicspaces.NewTopicSpaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicSpaceValue") + +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: `TopicSpacesClient.ListByNamespace` + +```go +ctx := context.TODO() +id := topicspaces.NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + +// alternatively `client.ListByNamespace(ctx, id, topicspaces.DefaultListByNamespaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByNamespaceComplete(ctx, id, topicspaces.DefaultListByNamespaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/client.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/client.go new file mode 100644 index 00000000000..cd50a8e2ec9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/client.go @@ -0,0 +1,26 @@ +package topicspaces + +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 TopicSpacesClient struct { + Client *resourcemanager.Client +} + +func NewTopicSpacesClientWithBaseURI(sdkApi sdkEnv.Api) (*TopicSpacesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "topicspaces", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TopicSpacesClient: %+v", err) + } + + return &TopicSpacesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/constants.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/constants.go new file mode 100644 index 00000000000..a8f3d66f325 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/constants.go @@ -0,0 +1,66 @@ +package topicspaces + +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 TopicSpaceProvisioningState string + +const ( + TopicSpaceProvisioningStateCanceled TopicSpaceProvisioningState = "Canceled" + TopicSpaceProvisioningStateCreating TopicSpaceProvisioningState = "Creating" + TopicSpaceProvisioningStateDeleted TopicSpaceProvisioningState = "Deleted" + TopicSpaceProvisioningStateDeleting TopicSpaceProvisioningState = "Deleting" + TopicSpaceProvisioningStateFailed TopicSpaceProvisioningState = "Failed" + TopicSpaceProvisioningStateSucceeded TopicSpaceProvisioningState = "Succeeded" + TopicSpaceProvisioningStateUpdating TopicSpaceProvisioningState = "Updating" +) + +func PossibleValuesForTopicSpaceProvisioningState() []string { + return []string{ + string(TopicSpaceProvisioningStateCanceled), + string(TopicSpaceProvisioningStateCreating), + string(TopicSpaceProvisioningStateDeleted), + string(TopicSpaceProvisioningStateDeleting), + string(TopicSpaceProvisioningStateFailed), + string(TopicSpaceProvisioningStateSucceeded), + string(TopicSpaceProvisioningStateUpdating), + } +} + +func (s *TopicSpaceProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTopicSpaceProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTopicSpaceProvisioningState(input string) (*TopicSpaceProvisioningState, error) { + vals := map[string]TopicSpaceProvisioningState{ + "canceled": TopicSpaceProvisioningStateCanceled, + "creating": TopicSpaceProvisioningStateCreating, + "deleted": TopicSpaceProvisioningStateDeleted, + "deleting": TopicSpaceProvisioningStateDeleting, + "failed": TopicSpaceProvisioningStateFailed, + "succeeded": TopicSpaceProvisioningStateSucceeded, + "updating": TopicSpaceProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TopicSpaceProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_namespace.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_namespace.go new file mode 100644 index 00000000000..5f942d88a11 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_namespace.go @@ -0,0 +1,125 @@ +package topicspaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamespaceId{} + +// NamespaceId is a struct representing the Resource ID for a Namespace +type NamespaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string +} + +// NewNamespaceID returns a new NamespaceId struct +func NewNamespaceID(subscriptionId string, resourceGroupName string, namespaceName string) NamespaceId { + return NamespaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + } +} + +// ParseNamespaceID parses 'input' into a NamespaceId +func ParseNamespaceID(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamespaceIDInsensitively parses 'input' case-insensitively into a NamespaceId +// note: this method should only be used for API response data and not user input +func ParseNamespaceIDInsensitively(input string) (*NamespaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamespaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamespaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamespaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + return nil +} + +// ValidateNamespaceID checks that 'input' can be parsed as a Namespace ID +func ValidateNamespaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamespaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Namespace ID +func (id NamespaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Namespace ID +func (id NamespaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + } +} + +// String returns a human-readable description of this Namespace ID +func (id NamespaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + } + return fmt.Sprintf("Namespace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_namespace_test.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_namespace_test.go new file mode 100644 index 00000000000..4a928837ee4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_namespace_test.go @@ -0,0 +1,282 @@ +package topicspaces + +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 = &NamespaceId{} + +func TestNewNamespaceID(t *testing.T) { + id := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } +} + +func TestFormatNamespaceID(t *testing.T) { + actual := NewNamespaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamespaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestParseNamespaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamespaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Expected: &NamespaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamespaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + } +} + +func TestSegmentsForNamespaceId(t *testing.T) { + segments := NamespaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamespaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_topicspace.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_topicspace.go new file mode 100644 index 00000000000..f8231ebace5 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_topicspace.go @@ -0,0 +1,134 @@ +package topicspaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TopicSpaceId{} + +// TopicSpaceId is a struct representing the Resource ID for a Topic Space +type TopicSpaceId struct { + SubscriptionId string + ResourceGroupName string + NamespaceName string + TopicSpaceName string +} + +// NewTopicSpaceID returns a new TopicSpaceId struct +func NewTopicSpaceID(subscriptionId string, resourceGroupName string, namespaceName string, topicSpaceName string) TopicSpaceId { + return TopicSpaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NamespaceName: namespaceName, + TopicSpaceName: topicSpaceName, + } +} + +// ParseTopicSpaceID parses 'input' into a TopicSpaceId +func ParseTopicSpaceID(input string) (*TopicSpaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicSpaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicSpaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTopicSpaceIDInsensitively parses 'input' case-insensitively into a TopicSpaceId +// note: this method should only be used for API response data and not user input +func ParseTopicSpaceIDInsensitively(input string) (*TopicSpaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicSpaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicSpaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TopicSpaceId) 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.NamespaceName, ok = input.Parsed["namespaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namespaceName", input) + } + + if id.TopicSpaceName, ok = input.Parsed["topicSpaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicSpaceName", input) + } + + return nil +} + +// ValidateTopicSpaceID checks that 'input' can be parsed as a Topic Space ID +func ValidateTopicSpaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTopicSpaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Topic Space ID +func (id TopicSpaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventGrid/namespaces/%s/topicSpaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.TopicSpaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Topic Space ID +func (id TopicSpaceId) 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("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticNamespaces", "namespaces", "namespaces"), + resourceids.UserSpecifiedSegment("namespaceName", "namespaceValue"), + resourceids.StaticSegment("staticTopicSpaces", "topicSpaces", "topicSpaces"), + resourceids.UserSpecifiedSegment("topicSpaceName", "topicSpaceValue"), + } +} + +// String returns a human-readable description of this Topic Space ID +func (id TopicSpaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Namespace Name: %q", id.NamespaceName), + fmt.Sprintf("Topic Space Name: %q", id.TopicSpaceName), + } + return fmt.Sprintf("Topic Space (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_topicspace_test.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_topicspace_test.go new file mode 100644 index 00000000000..836bc8a01fd --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/id_topicspace_test.go @@ -0,0 +1,327 @@ +package topicspaces + +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 = &TopicSpaceId{} + +func TestNewTopicSpaceID(t *testing.T) { + id := NewTopicSpaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicSpaceValue") + + if id.SubscriptionId != "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.NamespaceName != "namespaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamespaceName'", id.NamespaceName, "namespaceValue") + } + + if id.TopicSpaceName != "topicSpaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicSpaceName'", id.TopicSpaceName, "topicSpaceValue") + } +} + +func TestFormatTopicSpaceID(t *testing.T) { + actual := NewTopicSpaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "namespaceValue", "topicSpaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topicSpaces/topicSpaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTopicSpaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicSpaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topicSpaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topicSpaces/topicSpaceValue", + Expected: &TopicSpaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicSpaceName: "topicSpaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topicSpaces/topicSpaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicSpaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicSpaceName != v.Expected.TopicSpaceName { + t.Fatalf("Expected %q but got %q for TopicSpaceName", v.Expected.TopicSpaceName, actual.TopicSpaceName) + } + + } +} + +func TestParseTopicSpaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicSpaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topicSpaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcSpAcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topicSpaces/topicSpaceValue", + Expected: &TopicSpaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NamespaceName: "namespaceValue", + TopicSpaceName: "topicSpaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.EventGrid/namespaces/namespaceValue/topicSpaces/topicSpaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcSpAcEs/tOpIcSpAcEvAlUe", + Expected: &TopicSpaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NamespaceName: "nAmEsPaCeVaLuE", + TopicSpaceName: "tOpIcSpAcEvAlUe", + }, + }, + { + // 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.eVeNtGrId/nAmEsPaCeS/nAmEsPaCeVaLuE/tOpIcSpAcEs/tOpIcSpAcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicSpaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NamespaceName != v.Expected.NamespaceName { + t.Fatalf("Expected %q but got %q for NamespaceName", v.Expected.NamespaceName, actual.NamespaceName) + } + + if actual.TopicSpaceName != v.Expected.TopicSpaceName { + t.Fatalf("Expected %q but got %q for TopicSpaceName", v.Expected.TopicSpaceName, actual.TopicSpaceName) + } + + } +} + +func TestSegmentsForTopicSpaceId(t *testing.T) { + segments := TopicSpaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TopicSpaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_createorupdate.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_createorupdate.go new file mode 100644 index 00000000000..46b131fe0b9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_createorupdate.go @@ -0,0 +1,75 @@ +package topicspaces + +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 *TopicSpace +} + +// CreateOrUpdate ... +func (c TopicSpacesClient) CreateOrUpdate(ctx context.Context, id TopicSpaceId, input TopicSpace) (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 TopicSpacesClient) CreateOrUpdateThenPoll(ctx context.Context, id TopicSpaceId, input TopicSpace) 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/eventgrid/2023-12-15-preview/topicspaces/method_delete.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_delete.go new file mode 100644 index 00000000000..01dc7268a4f --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_delete.go @@ -0,0 +1,71 @@ +package topicspaces + +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 TopicSpacesClient) Delete(ctx context.Context, id TopicSpaceId) (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 TopicSpacesClient) DeleteThenPoll(ctx context.Context, id TopicSpaceId) 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/eventgrid/2023-12-15-preview/topicspaces/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_get.go new file mode 100644 index 00000000000..738ad40b640 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_get.go @@ -0,0 +1,54 @@ +package topicspaces + +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 *TopicSpace +} + +// Get ... +func (c TopicSpacesClient) Get(ctx context.Context, id TopicSpaceId) (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 TopicSpace + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_listbynamespace.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_listbynamespace.go new file mode 100644 index 00000000000..aced76ea4cc --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/method_listbynamespace.go @@ -0,0 +1,123 @@ +package topicspaces + +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 ListByNamespaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TopicSpace +} + +type ListByNamespaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []TopicSpace +} + +type ListByNamespaceOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByNamespaceOperationOptions() ListByNamespaceOperationOptions { + return ListByNamespaceOperationOptions{} +} + +func (o ListByNamespaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByNamespaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByNamespaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByNamespace ... +func (c TopicSpacesClient) ListByNamespace(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (result ListByNamespaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/topicSpaces", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TopicSpace `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNamespaceComplete retrieves all the results into a single object +func (c TopicSpacesClient) ListByNamespaceComplete(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions) (ListByNamespaceCompleteResult, error) { + return c.ListByNamespaceCompleteMatchingPredicate(ctx, id, options, TopicSpaceOperationPredicate{}) +} + +// ListByNamespaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TopicSpacesClient) ListByNamespaceCompleteMatchingPredicate(ctx context.Context, id NamespaceId, options ListByNamespaceOperationOptions, predicate TopicSpaceOperationPredicate) (result ListByNamespaceCompleteResult, err error) { + items := make([]TopicSpace, 0) + + resp, err := c.ListByNamespace(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNamespaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/model_topicspace.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/model_topicspace.go new file mode 100644 index 00000000000..8675af89207 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/model_topicspace.go @@ -0,0 +1,16 @@ +package topicspaces + +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 TopicSpace struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TopicSpaceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/model_topicspaceproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/model_topicspaceproperties.go new file mode 100644 index 00000000000..1218fad7366 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/model_topicspaceproperties.go @@ -0,0 +1,10 @@ +package topicspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicSpaceProperties struct { + Description *string `json:"description,omitempty"` + ProvisioningState *TopicSpaceProvisioningState `json:"provisioningState,omitempty"` + TopicTemplates *[]string `json:"topicTemplates,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topicspaces/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/predicates.go new file mode 100644 index 00000000000..acc5ff358d9 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/predicates.go @@ -0,0 +1,27 @@ +package topicspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicSpaceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TopicSpaceOperationPredicate) Matches(input TopicSpace) 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/eventgrid/2023-12-15-preview/topicspaces/version.go b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/version.go new file mode 100644 index 00000000000..ee3d43fb794 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topicspaces/version.go @@ -0,0 +1,12 @@ +package topicspaces + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/topicspaces/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/README.md b/resource-manager/eventgrid/2023-12-15-preview/topictypes/README.md new file mode 100644 index 00000000000..68a95761721 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/README.md @@ -0,0 +1,68 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/topictypes` Documentation + +The `topictypes` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/topictypes" +``` + + +### Client Initialization + +```go +client := topictypes.NewTopicTypesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TopicTypesClient.Get` + +```go +ctx := context.TODO() +id := topictypes.NewTopicTypeID("topicTypeValue") + +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: `TopicTypesClient.List` + +```go +ctx := context.TODO() + + +read, err := client.List(ctx) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TopicTypesClient.ListEventTypes` + +```go +ctx := context.TODO() +id := topictypes.NewTopicTypeID("topicTypeValue") + +read, err := client.ListEventTypes(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/eventgrid/2023-12-15-preview/topictypes/client.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/client.go new file mode 100644 index 00000000000..9e6399829c2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/client.go @@ -0,0 +1,26 @@ +package topictypes + +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 TopicTypesClient struct { + Client *resourcemanager.Client +} + +func NewTopicTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*TopicTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "topictypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TopicTypesClient: %+v", err) + } + + return &TopicTypesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/constants.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/constants.go new file mode 100644 index 00000000000..5c87c7ca5ae --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/constants.go @@ -0,0 +1,151 @@ +package topictypes + +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 ResourceRegionType string + +const ( + ResourceRegionTypeGlobalResource ResourceRegionType = "GlobalResource" + ResourceRegionTypeRegionalResource ResourceRegionType = "RegionalResource" +) + +func PossibleValuesForResourceRegionType() []string { + return []string{ + string(ResourceRegionTypeGlobalResource), + string(ResourceRegionTypeRegionalResource), + } +} + +func (s *ResourceRegionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceRegionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceRegionType(input string) (*ResourceRegionType, error) { + vals := map[string]ResourceRegionType{ + "globalresource": ResourceRegionTypeGlobalResource, + "regionalresource": ResourceRegionTypeRegionalResource, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceRegionType(input) + return &out, nil +} + +type TopicTypeProvisioningState string + +const ( + TopicTypeProvisioningStateCanceled TopicTypeProvisioningState = "Canceled" + TopicTypeProvisioningStateCreating TopicTypeProvisioningState = "Creating" + TopicTypeProvisioningStateDeleting TopicTypeProvisioningState = "Deleting" + TopicTypeProvisioningStateFailed TopicTypeProvisioningState = "Failed" + TopicTypeProvisioningStateSucceeded TopicTypeProvisioningState = "Succeeded" + TopicTypeProvisioningStateUpdating TopicTypeProvisioningState = "Updating" +) + +func PossibleValuesForTopicTypeProvisioningState() []string { + return []string{ + string(TopicTypeProvisioningStateCanceled), + string(TopicTypeProvisioningStateCreating), + string(TopicTypeProvisioningStateDeleting), + string(TopicTypeProvisioningStateFailed), + string(TopicTypeProvisioningStateSucceeded), + string(TopicTypeProvisioningStateUpdating), + } +} + +func (s *TopicTypeProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTopicTypeProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTopicTypeProvisioningState(input string) (*TopicTypeProvisioningState, error) { + vals := map[string]TopicTypeProvisioningState{ + "canceled": TopicTypeProvisioningStateCanceled, + "creating": TopicTypeProvisioningStateCreating, + "deleting": TopicTypeProvisioningStateDeleting, + "failed": TopicTypeProvisioningStateFailed, + "succeeded": TopicTypeProvisioningStateSucceeded, + "updating": TopicTypeProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TopicTypeProvisioningState(input) + return &out, nil +} + +type TopicTypeSourceScope string + +const ( + TopicTypeSourceScopeAzureSubscription TopicTypeSourceScope = "AzureSubscription" + TopicTypeSourceScopeManagementGroup TopicTypeSourceScope = "ManagementGroup" + TopicTypeSourceScopeResource TopicTypeSourceScope = "Resource" + TopicTypeSourceScopeResourceGroup TopicTypeSourceScope = "ResourceGroup" +) + +func PossibleValuesForTopicTypeSourceScope() []string { + return []string{ + string(TopicTypeSourceScopeAzureSubscription), + string(TopicTypeSourceScopeManagementGroup), + string(TopicTypeSourceScopeResource), + string(TopicTypeSourceScopeResourceGroup), + } +} + +func (s *TopicTypeSourceScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTopicTypeSourceScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTopicTypeSourceScope(input string) (*TopicTypeSourceScope, error) { + vals := map[string]TopicTypeSourceScope{ + "azuresubscription": TopicTypeSourceScopeAzureSubscription, + "managementgroup": TopicTypeSourceScopeManagementGroup, + "resource": TopicTypeSourceScopeResource, + "resourcegroup": TopicTypeSourceScopeResourceGroup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TopicTypeSourceScope(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/id_topictype.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/id_topictype.go new file mode 100644 index 00000000000..d47837a16d2 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/id_topictype.go @@ -0,0 +1,107 @@ +package topictypes + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TopicTypeId{} + +// TopicTypeId is a struct representing the Resource ID for a Topic Type +type TopicTypeId struct { + TopicTypeName string +} + +// NewTopicTypeID returns a new TopicTypeId struct +func NewTopicTypeID(topicTypeName string) TopicTypeId { + return TopicTypeId{ + TopicTypeName: topicTypeName, + } +} + +// ParseTopicTypeID parses 'input' into a TopicTypeId +func ParseTopicTypeID(input string) (*TopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTopicTypeIDInsensitively parses 'input' case-insensitively into a TopicTypeId +// note: this method should only be used for API response data and not user input +func ParseTopicTypeIDInsensitively(input string) (*TopicTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&TopicTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TopicTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TopicTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.TopicTypeName, ok = input.Parsed["topicTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "topicTypeName", input) + } + + return nil +} + +// ValidateTopicTypeID checks that 'input' can be parsed as a Topic Type ID +func ValidateTopicTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTopicTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Topic Type ID +func (id TopicTypeId) ID() string { + fmtString := "/providers/Microsoft.EventGrid/topicTypes/%s" + return fmt.Sprintf(fmtString, id.TopicTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Topic Type ID +func (id TopicTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticTopicTypes", "topicTypes", "topicTypes"), + resourceids.UserSpecifiedSegment("topicTypeName", "topicTypeValue"), + } +} + +// String returns a human-readable description of this Topic Type ID +func (id TopicTypeId) String() string { + components := []string{ + fmt.Sprintf("Topic Type Name: %q", id.TopicTypeName), + } + return fmt.Sprintf("Topic Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/id_topictype_test.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/id_topictype_test.go new file mode 100644 index 00000000000..6994e4b785c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/id_topictype_test.go @@ -0,0 +1,192 @@ +package topictypes + +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 = &TopicTypeId{} + +func TestNewTopicTypeID(t *testing.T) { + id := NewTopicTypeID("topicTypeValue") + + if id.TopicTypeName != "topicTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'TopicTypeName'", id.TopicTypeName, "topicTypeValue") + } +} + +func TestFormatTopicTypeID(t *testing.T) { + actual := NewTopicTypeID("topicTypeValue").ID() + expected := "/providers/Microsoft.EventGrid/topicTypes/topicTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTopicTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid/topicTypes", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.EventGrid/topicTypes/topicTypeValue", + Expected: &TopicTypeId{ + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.EventGrid/topicTypes/topicTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestParseTopicTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TopicTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid/topicTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.EventGrid/topicTypes/topicTypeValue", + Expected: &TopicTypeId{ + TopicTypeName: "topicTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.EventGrid/topicTypes/topicTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS/tOpIcTyPeVaLuE", + Expected: &TopicTypeId{ + TopicTypeName: "tOpIcTyPeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId/tOpIcTyPeS/tOpIcTyPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTopicTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.TopicTypeName != v.Expected.TopicTypeName { + t.Fatalf("Expected %q but got %q for TopicTypeName", v.Expected.TopicTypeName, actual.TopicTypeName) + } + + } +} + +func TestSegmentsForTopicTypeId(t *testing.T) { + segments := TopicTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TopicTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_get.go new file mode 100644 index 00000000000..c1c6fbcdd6b --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_get.go @@ -0,0 +1,54 @@ +package topictypes + +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 *TopicTypeInfo +} + +// Get ... +func (c TopicTypesClient) Get(ctx context.Context, id TopicTypeId) (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 TopicTypeInfo + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_list.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_list.go new file mode 100644 index 00000000000..99aaa9f6830 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_list.go @@ -0,0 +1,54 @@ +package topictypes + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TopicTypesListResult +} + +// List ... +func (c TopicTypesClient) List(ctx context.Context) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: "/providers/Microsoft.EventGrid/topicTypes", + } + + 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 TopicTypesListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_listeventtypes.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_listeventtypes.go new file mode 100644 index 00000000000..b5bfb44e665 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/method_listeventtypes.go @@ -0,0 +1,55 @@ +package topictypes + +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 ListEventTypesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventTypesListResult +} + +// ListEventTypes ... +func (c TopicTypesClient) ListEventTypes(ctx context.Context, id TopicTypeId) (result ListEventTypesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/eventTypes", 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 EventTypesListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtype.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtype.go new file mode 100644 index 00000000000..e16f6643fb4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtype.go @@ -0,0 +1,11 @@ +package topictypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventType struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EventTypeProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtypeproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtypeproperties.go new file mode 100644 index 00000000000..deadd920daf --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtypeproperties.go @@ -0,0 +1,11 @@ +package topictypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypeProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + IsInDefaultSet *bool `json:"isInDefaultSet,omitempty"` + SchemaUrl *string `json:"schemaUrl,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtypeslistresult.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtypeslistresult.go new file mode 100644 index 00000000000..047710763b6 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_eventtypeslistresult.go @@ -0,0 +1,8 @@ +package topictypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventTypesListResult struct { + Value *[]EventType `json:"value,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeadditionalenforcedpermission.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeadditionalenforcedpermission.go new file mode 100644 index 00000000000..5be527993da --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeadditionalenforcedpermission.go @@ -0,0 +1,9 @@ +package topictypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicTypeAdditionalEnforcedPermission struct { + IsDataAction *bool `json:"isDataAction,omitempty"` + PermissionName *string `json:"permissionName,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeinfo.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeinfo.go new file mode 100644 index 00000000000..058556bef1c --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeinfo.go @@ -0,0 +1,11 @@ +package topictypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicTypeInfo struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TopicTypeProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeproperties.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeproperties.go new file mode 100644 index 00000000000..806883f909e --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeproperties.go @@ -0,0 +1,17 @@ +package topictypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicTypeProperties struct { + AdditionalEnforcedPermissions *[]TopicTypeAdditionalEnforcedPermission `json:"additionalEnforcedPermissions,omitempty"` + AreRegionalAndGlobalSourcesSupported *bool `json:"areRegionalAndGlobalSourcesSupported,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Provider *string `json:"provider,omitempty"` + ProvisioningState *TopicTypeProvisioningState `json:"provisioningState,omitempty"` + ResourceRegionType *ResourceRegionType `json:"resourceRegionType,omitempty"` + SourceResourceFormat *string `json:"sourceResourceFormat,omitempty"` + SupportedLocations *[]string `json:"supportedLocations,omitempty"` + SupportedScopesForSource *[]TopicTypeSourceScope `json:"supportedScopesForSource,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeslistresult.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeslistresult.go new file mode 100644 index 00000000000..cc57dab9c94 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/model_topictypeslistresult.go @@ -0,0 +1,8 @@ +package topictypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopicTypesListResult struct { + Value *[]TopicTypeInfo `json:"value,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/topictypes/version.go b/resource-manager/eventgrid/2023-12-15-preview/topictypes/version.go new file mode 100644 index 00000000000..b2652aad9bd --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/topictypes/version.go @@ -0,0 +1,12 @@ +package topictypes + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/topictypes/%s", defaultApiVersion) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/README.md b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/README.md new file mode 100644 index 00000000000..3e1b24fceb4 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners` Documentation + +The `verifiedpartners` SDK allows for interaction with the Azure Resource Manager Service `eventgrid` (API Version `2023-12-15-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/eventgrid/2023-12-15-preview/verifiedpartners" +``` + + +### Client Initialization + +```go +client := verifiedpartners.NewVerifiedPartnersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `VerifiedPartnersClient.Get` + +```go +ctx := context.TODO() +id := verifiedpartners.NewVerifiedPartnerID("verifiedPartnerValue") + +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: `VerifiedPartnersClient.List` + +```go +ctx := context.TODO() + + +// alternatively `client.List(ctx, verifiedpartners.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, verifiedpartners.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/client.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/client.go new file mode 100644 index 00000000000..576b4f91baa --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/client.go @@ -0,0 +1,26 @@ +package verifiedpartners + +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 VerifiedPartnersClient struct { + Client *resourcemanager.Client +} + +func NewVerifiedPartnersClientWithBaseURI(sdkApi sdkEnv.Api) (*VerifiedPartnersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "verifiedpartners", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating VerifiedPartnersClient: %+v", err) + } + + return &VerifiedPartnersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/constants.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/constants.go new file mode 100644 index 00000000000..7053140c491 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/constants.go @@ -0,0 +1,63 @@ +package verifiedpartners + +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 VerifiedPartnerProvisioningState string + +const ( + VerifiedPartnerProvisioningStateCanceled VerifiedPartnerProvisioningState = "Canceled" + VerifiedPartnerProvisioningStateCreating VerifiedPartnerProvisioningState = "Creating" + VerifiedPartnerProvisioningStateDeleting VerifiedPartnerProvisioningState = "Deleting" + VerifiedPartnerProvisioningStateFailed VerifiedPartnerProvisioningState = "Failed" + VerifiedPartnerProvisioningStateSucceeded VerifiedPartnerProvisioningState = "Succeeded" + VerifiedPartnerProvisioningStateUpdating VerifiedPartnerProvisioningState = "Updating" +) + +func PossibleValuesForVerifiedPartnerProvisioningState() []string { + return []string{ + string(VerifiedPartnerProvisioningStateCanceled), + string(VerifiedPartnerProvisioningStateCreating), + string(VerifiedPartnerProvisioningStateDeleting), + string(VerifiedPartnerProvisioningStateFailed), + string(VerifiedPartnerProvisioningStateSucceeded), + string(VerifiedPartnerProvisioningStateUpdating), + } +} + +func (s *VerifiedPartnerProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVerifiedPartnerProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVerifiedPartnerProvisioningState(input string) (*VerifiedPartnerProvisioningState, error) { + vals := map[string]VerifiedPartnerProvisioningState{ + "canceled": VerifiedPartnerProvisioningStateCanceled, + "creating": VerifiedPartnerProvisioningStateCreating, + "deleting": VerifiedPartnerProvisioningStateDeleting, + "failed": VerifiedPartnerProvisioningStateFailed, + "succeeded": VerifiedPartnerProvisioningStateSucceeded, + "updating": VerifiedPartnerProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VerifiedPartnerProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/id_verifiedpartner.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/id_verifiedpartner.go new file mode 100644 index 00000000000..71b1a76ebaf --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/id_verifiedpartner.go @@ -0,0 +1,107 @@ +package verifiedpartners + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &VerifiedPartnerId{} + +// VerifiedPartnerId is a struct representing the Resource ID for a Verified Partner +type VerifiedPartnerId struct { + VerifiedPartnerName string +} + +// NewVerifiedPartnerID returns a new VerifiedPartnerId struct +func NewVerifiedPartnerID(verifiedPartnerName string) VerifiedPartnerId { + return VerifiedPartnerId{ + VerifiedPartnerName: verifiedPartnerName, + } +} + +// ParseVerifiedPartnerID parses 'input' into a VerifiedPartnerId +func ParseVerifiedPartnerID(input string) (*VerifiedPartnerId, error) { + parser := resourceids.NewParserFromResourceIdType(&VerifiedPartnerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VerifiedPartnerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVerifiedPartnerIDInsensitively parses 'input' case-insensitively into a VerifiedPartnerId +// note: this method should only be used for API response data and not user input +func ParseVerifiedPartnerIDInsensitively(input string) (*VerifiedPartnerId, error) { + parser := resourceids.NewParserFromResourceIdType(&VerifiedPartnerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VerifiedPartnerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VerifiedPartnerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.VerifiedPartnerName, ok = input.Parsed["verifiedPartnerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "verifiedPartnerName", input) + } + + return nil +} + +// ValidateVerifiedPartnerID checks that 'input' can be parsed as a Verified Partner ID +func ValidateVerifiedPartnerID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseVerifiedPartnerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Verified Partner ID +func (id VerifiedPartnerId) ID() string { + fmtString := "/providers/Microsoft.EventGrid/verifiedPartners/%s" + return fmt.Sprintf(fmtString, id.VerifiedPartnerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Verified Partner ID +func (id VerifiedPartnerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftEventGrid", "Microsoft.EventGrid", "Microsoft.EventGrid"), + resourceids.StaticSegment("staticVerifiedPartners", "verifiedPartners", "verifiedPartners"), + resourceids.UserSpecifiedSegment("verifiedPartnerName", "verifiedPartnerValue"), + } +} + +// String returns a human-readable description of this Verified Partner ID +func (id VerifiedPartnerId) String() string { + components := []string{ + fmt.Sprintf("Verified Partner Name: %q", id.VerifiedPartnerName), + } + return fmt.Sprintf("Verified Partner (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/id_verifiedpartner_test.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/id_verifiedpartner_test.go new file mode 100644 index 00000000000..68b4cb712de --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/id_verifiedpartner_test.go @@ -0,0 +1,192 @@ +package verifiedpartners + +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 = &VerifiedPartnerId{} + +func TestNewVerifiedPartnerID(t *testing.T) { + id := NewVerifiedPartnerID("verifiedPartnerValue") + + if id.VerifiedPartnerName != "verifiedPartnerValue" { + t.Fatalf("Expected %q but got %q for Segment 'VerifiedPartnerName'", id.VerifiedPartnerName, "verifiedPartnerValue") + } +} + +func TestFormatVerifiedPartnerID(t *testing.T) { + actual := NewVerifiedPartnerID("verifiedPartnerValue").ID() + expected := "/providers/Microsoft.EventGrid/verifiedPartners/verifiedPartnerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVerifiedPartnerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VerifiedPartnerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid/verifiedPartners", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.EventGrid/verifiedPartners/verifiedPartnerValue", + Expected: &VerifiedPartnerId{ + VerifiedPartnerName: "verifiedPartnerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.EventGrid/verifiedPartners/verifiedPartnerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVerifiedPartnerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.VerifiedPartnerName != v.Expected.VerifiedPartnerName { + t.Fatalf("Expected %q but got %q for VerifiedPartnerName", v.Expected.VerifiedPartnerName, actual.VerifiedPartnerName) + } + + } +} + +func TestParseVerifiedPartnerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VerifiedPartnerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.EventGrid/verifiedPartners", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId/vErIfIeDpArTnErS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.EventGrid/verifiedPartners/verifiedPartnerValue", + Expected: &VerifiedPartnerId{ + VerifiedPartnerName: "verifiedPartnerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.EventGrid/verifiedPartners/verifiedPartnerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId/vErIfIeDpArTnErS/vErIfIeDpArTnErVaLuE", + Expected: &VerifiedPartnerId{ + VerifiedPartnerName: "vErIfIeDpArTnErVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.eVeNtGrId/vErIfIeDpArTnErS/vErIfIeDpArTnErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVerifiedPartnerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.VerifiedPartnerName != v.Expected.VerifiedPartnerName { + t.Fatalf("Expected %q but got %q for VerifiedPartnerName", v.Expected.VerifiedPartnerName, actual.VerifiedPartnerName) + } + + } +} + +func TestSegmentsForVerifiedPartnerId(t *testing.T) { + segments := VerifiedPartnerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VerifiedPartnerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/method_get.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/method_get.go new file mode 100644 index 00000000000..67eed1527ad --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/method_get.go @@ -0,0 +1,54 @@ +package verifiedpartners + +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 *VerifiedPartner +} + +// Get ... +func (c VerifiedPartnersClient) Get(ctx context.Context, id VerifiedPartnerId) (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 VerifiedPartner + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/method_list.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/method_list.go new file mode 100644 index 00000000000..17b0d4382d1 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/method_list.go @@ -0,0 +1,123 @@ +package verifiedpartners + +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 *[]VerifiedPartner +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []VerifiedPartner +} + +type ListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c VerifiedPartnersClient) List(ctx context.Context, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: "/providers/Microsoft.EventGrid/verifiedPartners", + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]VerifiedPartner `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 VerifiedPartnersClient) ListComplete(ctx context.Context, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, options, VerifiedPartnerOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VerifiedPartnersClient) ListCompleteMatchingPredicate(ctx context.Context, options ListOperationOptions, predicate VerifiedPartnerOperationPredicate) (result ListCompleteResult, err error) { + items := make([]VerifiedPartner, 0) + + resp, err := c.List(ctx, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_partnerdetails.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_partnerdetails.go new file mode 100644 index 00000000000..a7635332e83 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_partnerdetails.go @@ -0,0 +1,10 @@ +package verifiedpartners + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerDetails struct { + Description *string `json:"description,omitempty"` + LongDescription *string `json:"longDescription,omitempty"` + SetupUri *string `json:"setupUri,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_verifiedpartner.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_verifiedpartner.go new file mode 100644 index 00000000000..2c5a09e7dfe --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_verifiedpartner.go @@ -0,0 +1,16 @@ +package verifiedpartners + +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 VerifiedPartner struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VerifiedPartnerProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_verifiedpartnerproperties.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_verifiedpartnerproperties.go new file mode 100644 index 00000000000..291f8cd54ca --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/model_verifiedpartnerproperties.go @@ -0,0 +1,13 @@ +package verifiedpartners + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VerifiedPartnerProperties struct { + OrganizationName *string `json:"organizationName,omitempty"` + PartnerDestinationDetails *PartnerDetails `json:"partnerDestinationDetails,omitempty"` + PartnerDisplayName *string `json:"partnerDisplayName,omitempty"` + PartnerRegistrationImmutableId *string `json:"partnerRegistrationImmutableId,omitempty"` + PartnerTopicDetails *PartnerDetails `json:"partnerTopicDetails,omitempty"` + ProvisioningState *VerifiedPartnerProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/predicates.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/predicates.go new file mode 100644 index 00000000000..f2d25160cbb --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/predicates.go @@ -0,0 +1,27 @@ +package verifiedpartners + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VerifiedPartnerOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VerifiedPartnerOperationPredicate) Matches(input VerifiedPartner) 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/eventgrid/2023-12-15-preview/verifiedpartners/version.go b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/version.go new file mode 100644 index 00000000000..352af8caba0 --- /dev/null +++ b/resource-manager/eventgrid/2023-12-15-preview/verifiedpartners/version.go @@ -0,0 +1,12 @@ +package verifiedpartners + +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-12-15-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/verifiedpartners/%s", defaultApiVersion) +}